July 18, 2004
Your Personal New Music Radio Station
Getting new music to listen to is always good, but the way my system was set up meant that listening to the MP3s required interrupting whatever music I was already listening to (and I'm always listening to something), and often I need a couple of listens to a track before it worms its way into my head.
For a while I've been meaning to write some code to get the latest MP3s from the RSS feeds and somehow insert them into my listening schedule for the day. Then I came across Jeffrey Veen's post about using
wget to download the MP3s. That took care of acquiring the tracks, but didn't give me an easy way to listen to them.
So, some experimenting and perl hacking later, I now have NewMusicRadio. There are two parts to this, and when combined they provide my own personal radio station of recent additions to my music collection and an assortment of new discoveries from Soulseek and the MP3 blogs I subscribe to.
First off is the
cron job script which runs each day - downloading the new tracks from an assortment of MP3 blogs, and generating the list of MP3s recently added to my collection. Jeff explained most of the wget options, and I've added two others:
-nvThis just cuts down on the amount of output generated to reduce the size of my cron logs
wgetnot to download a new copy of a file just because the sizes don't match. That allows me to overwrite files I don't like with a zero-byte file and
wgetwon't just get me another copy next time it runs. The
chmod g+wafter each
wgetis just because my cron job doesn't run as the same user as the CGI script that might want to "delete" an MP3; they are in the same group, so the
chmodmakes sure the downloaded MP3s can be overwritten.
Rather than give
wget a list of URLs for each MP3 blog, I'm running a different
wget for each blog so that I can filter the downloaded MP3s into a directory for that blog, just to help me keep track of which tracks I got from where.
Then I use
find to create a list of tracks which have been added in the past 42 days:
find /home/musicfiles/ -name \*.mp3 -mtime -42 -print > /home/musicfiles/recentfiles.txt
/home/musicfiles/This is where all my MP3s live. When I buy a new CD, it gets ripped and the MP3s are put in /home/musicfiles/<artist>/<album>/<track_n.mp3> and everything I download with soulseek, or from an MP3 blog gets put into /home/musicfiles/downloads. This parameter tells
findwhere to look for updated files.
-name \*.mp3This option tells
findjust to look for files called <something>.mp3. The \ is needed before the * to ensure the * isn't expanded by the shell and makes it to
findas a *
findto only include files which were modified in the past 42 days (six weeks)
> /home/musicfiles/recentfiles.txtredirect the output into the file we'll give to the playlist generator
Now that I've got a load of MP3s and a list of which ones are new, I use a little perl script installed on my Apache webserver to pick random songs from the list and deliver them to my media player. Musicmatch seems to get the artist/title information when it's available, but Winamp just displays the URL the track is being streamed from, which isn't as useful.
When I point my web browser at the script, I get a form to fill in (see an example). Once I've chosen how many tracks I want in the playlist I can either listen to the playlist straight away - generating an m3u playlist which automatically fires up Musicmatch - or have a look at which tracks are chosen. The view playlist option looks like this; shows me which tracks are in the playlist; lets me listen to the playlist; and lets me delete songs that have been downloaded (as opposed to ripped from CD) if I decide I don't like them.
If anyone fancies having a play with it, I've made it available over here. I'd be interested in hearing any thoughts about it, or suggestions for improvement.Posted by Adrian at July 18, 2004 08:47 PM | TrackBack