Topic: Shuffled music as alarm -- one solution
So, one of the main reasons I got a chumby is that I start to sleep through ANY sound that plays every morning. I wanted an internet radio with good songs but an unpredictable pattern. Pandora worked fine for this, but eventually will not be a solution.
Squeezebox server is a potential solution, but if my home network goes down for some reason ... like insomnified typo-ing leading to wiping out a good part of my operating system, oops ... it won't.
Having all of the music on the chumby, then, and playing it as the alarm, this seems like the safest method. You can wake up to a "stream" which is a playlist of all your music. However, it does not shuffle. It'll just keep playing the same songs each time.
So here's how I dealt with that. I'll try to make a second post with a script that should do ALL of this for you, but here's the breakdown. Hey, I'm assuming that you have your music on a flash drive stuck into your chumby, in a directory called "Music". And that you have your music either directly in directories under Music (like "Music/Artist/mp3s") or in album directories (like "Music/Artist/Album/mp3s"). If you've got something significantly different, and don't already know how to alter the following to make it work, feel free to ask me how to change it.
~ ~ ~
SSH into chumby, You need your chumby's IP, which you can get from the "device information" screen. You'll also need to touch the little pi in the top right corner and, on the hidden screen that opens, press the "SSHD" button. From command line or in putty,
ssh root@[your_chumbys_ip]
Once in, make a list of all the music on the flash drive (some is directly in artist directories, some is in artist/album):
ls /mnt/usb/Music/*/*.mp3 /mnt/usb/Music/*/*/*.mp3 > /mnt/usb/Music/AllSongs.m3u
So that's a playlist of all the mp3's, complete with directory. I went to the control panel, "Music," and "My Streams," and created a stream that read:
file:////mnt/usb/Music/AllSongs.m3u
and played it, to test that it works.
Okay, so now you have a stream that you can set as your alarm wakeup.
But it'll play the same songs over and over. You'll need scripts to help you deal with this. Create a directory to put them in:
mkdir /mnt/usb/bin
And tell the chumby to look there for scripts. Edit your /psp/.profile file to add a line. First, make a backup:
cp /psp/.profile /psp/.profile.bak
Then edit the file ".profile". I'll tell you what to put in it in a minute. First, here's how you can open it to edit it:
* you can edit it directly on the chumby if you have nano or are comfortable with vi, or
nano /psp/.profile
* you can copy it to the chumby's flash drive, edit it on your desktop and then put back into the chumby, or
cp /psp/.profile /mnt/usb/bin/
[remove the drive, take it to your computer, plug it in, edit, put it back in the chumby]
mv /mnt/usb/bin/.profile /psp/
* you can scp it from the chumby it on your desktop and scp it back once it's complete.
scp root@[your_chumbys_ip]:/psp/.profile .
[edit .profile]
scp .profile root@[your_chumbys_ip]:/psp/
Here's what you add to .profile at the end; this adds your new directory to the working path that already existed:
export PATH=$PATH:/mnt/usb/bin
Now, at the command line, type this to go ahead and make your chumby start looking for executable files in "/mnt/usb/bin/" right away:
cd /psp/
. .profile
cd
So I have a script that runs on a cron job that shuffles the file. (Fair confession: got help from spouse the Perl God.) You'll make a file called "random_reorder" with the following code. Create the file in whatever way is easiest for you:
* you can use any of the methods above: edit on the chumby ("nano /mnt/usb/bin/random_reorder"), put it on the chumby's flash drive directly )from your desktop, edit the file and stick it in "bin" in the flash drive), or scp it over (scp random_reorder root@[your_chumbys_ip]:/mnt/usb/bin/").
* Or if you'd find it easiest, you can get a copy from my server. I'll tell you how to do that at the end.
#!/usr/bin/perl -w
# @(#) randomize Effectively _unsort_ a text file into random order.
# 96.02.26 / drl.
# Based on Programming Perl, p 245, "Selecting random element ..."
# Set the random seed, PP, p 188
srand(time|$$);
if (! scalar(@ARGV) ) {
die "\nUsage: random_reorder <filename> [filename] ... [filename]\n";
}
foreach my $file (@ARGV) {
reorder_file($file);
}
sub reorder_file {
my $filename = shift;
if ( ! -f $filename ) {
warn "File $filename does not exist.\n";
return;
}
open(INFILE,$filename);
my @lines = <INFILE>;
close (INFILE);
#backup input file
print `/bin/cp $filename $filename.bak`;
open(OUTFILE,">$filename");
while ( @lines ) {
my $choice = splice(@lines,rand @lines, 1);
print OUTFILE $choice;
}
close OUTFILE;
}
If you don't feel up to creating this file yourself,
cd /mnt/usb/bin/
wget http://www.lady-of-lothlorien.com/chumby/bin/random_reorder
cd
So, once you have created random_reorder, you'll want to make it executable, then tell your chumby to use it regularly. First, at the command line, type:
chmod u+x /mnt/usb/bin/random_reorder
Then you'll work on your cron jobs, which means you have to temporarily mount the filesystem writeable. Normally, you can write to files in /psp/, but not to files in /etc/.
mount -o remount,rw /
Now you'll want to edit the cron file, which is what tells the chumby to do things on a regular basis. If you have nano or are comfortable with vi, you can do it directly on your machine.
nano /etc/cron/crontabs/root
In the cron file, add this line:
15 * * * * random_reorder /mnt/usb/Music/AllSongs.m3u ; echo `date` > /mnt/usb/Music/shuffled.last
That will shuffle the lines in the playlist 15 minutes after every hour, and it will note the time it last shuffled the files in a file called "shuffled_last" in your Music directory.
Now tidy up and finish this off:
sync
mount -o remount,ro /