Radio Playlist

Main Idea

I thought of this project a few days ago. I was driving in my car and they played this new song on the radio (The Edge 103.9). I loved it and wanted to find it on my computer when I got home to listen again, but I had missed the names of the song and band. This happens a lot while driving. Normally in that situation I will have to send a text message to myself of some lyrics that I remember so I can Google them later and try to find the song. Well this project aims to prevent this problem.

I want to write a script that will sit on my server and look for incoming e-mails with a specific subject line coming from my cell phone. When it finds one of these e-mails it will go to The Edge’s web site and look at what song is playing at, or around, that time. When it finds the artist and song title it will save that to a “playlist” of sorts. I can then come home later and look at the list to see all of the songs I want to find. The reason this should work is because The Edge keeps a list of all the songs that they play. Every time they play a song, the list gets updated. I’m thinking I can use Curl to check the website and Bash to do most of the other scripting. Maybe I should use Perl instead to make it more portable?

Basic Functionality

It all starts with me hearing a song on the radio. If I want to know the artist name and song title I just send a text message to a specially made gmail account with the subject line being “Radio”. There does not have to me any message in the body.

A perl script (gmailpop.pl) runs on my server at home and checks my gmail account every five minutes for new messages. If the message has the word “Radio” in the subject line, it gets the time the message was sent and sets an “at” job to run thirty minutes from the current time. The 30 minute delay is required because the play list on the radio station’s website does not update for 10-30 minutes sometimes. It then deletes the message to prevent itself from getting the same song over and over again.

Thirty minutes later, the at job starts a bash script (playlist.bash) with the arguments being equal to the Hour, the Minute, and AM/PM that the e-mail was sent. The bash script uses cURL to download the radio station’s play list to a file locally. It then parses through that file to locate the artist name that played around the time the e-mail was sent. Once it has the artist name, it goes through and looks for the song title. Once the information is found, it appends it to a list for me that I host on a local samba share.

When I get home from wherever I am, I can look at the samba share from my PC and pull up the list to see what the song was.

Miscellaneous

As of May 5, 2008 this project is finished until I run into problems. Everything works so far. All of the trials and tribulations of this project can be found in the following blog posts:

Page 1
Page 2
Page 3
Page 4
Page 5

I have uploaded edited version of my script files to the website. You can download them using the following links:

gmailpop.pl
playlist.bash

In order to use them, you will have to edit the gmailpop perl script to include your own gmail username and password. You may also have to change some file paths to match your own system. You will almost definitely have to change the file paths in the bash script. I manually typed them in to match my own system. You will have to go through and change each one to make it fit your own needs.

Also, you will need to make sure you have the Mail::POP3Client and the IO::Socket::SSL modules installed. You can install them by running cpan and using the install command. You also have to have cURL installed in order for the script to download the playlist.

Thanks

Now to give credit where credit is due. The gmailpop.pl script originally came from this source. I had no idea how to access my Gmail account with Perl but this guy had done just that AND used SSL to encrypt the connection. I basically started with his script, deleted what I didn’t need and added what I did need. The bash script was written from scratch by me.