If you liked the previous Pi-rate Radio Jukebox (and 15 people did!), you won’t want to miss this latest version of it. It’s basically the same thing, but it runs as a daemon, so you can fire up your favourite tunes using a browser rather than logging in to your Pi to start up scripts. As usual it’s horribly coded in Bash and features a fuck-ugly interface with no aesthetic considerations whatsoever. You can insert prettiness yourself if you want to – it’s easy enough because the web pages are done as templates. All the code is commented to
pad it out and make it look more substantial than it is clearly show what is going on.
This one is called Pirpl and is pronounced “Purple” because it seemed like a good idea at the time. Something to do with Pirate Radio PLaylists or something – it’s all a bit tenuous, quite frankly. Anyway, the main improvement is that rather than telling it what to play from the command line, you pick what you want to listen to from a list on a web page. As before, you can tell it to play all the MP3s in a directory (and all sub-directories) or give it a list of MP3s to play in a file. It’ll then play them (in a random order if you want), showing the current tune on a web page and allowing you to skip a track or stop playing and go back to the playlist chooser.
Other improvements are:
- Support for MP3 ID tags in both version 1 and version 2 format. The old player only recognised version 1 tags.
- Umm… that’s about it really. The code is slightly better in places, I suppose. Still the playlist choosing thing is good, isn’t it?
Want to get going already? This is the tarred archive (20.8 kB)
Download the archive, untar it, edit the “pirpl_conf” file (you’ll see why in the file) and add playlist information to the “pirpl_playlist.conf” (you’ll see how in the file). Before you can start it up, you need to make sure that the following packages are installed on your Pi: netcat, sox, id3v2. If one or more isn’t then, install any missing ones with
sudo apt-get install netcat sox id3v2
The program that does the transmitting needs to run as root, so setuid that bad boy up with:
sudo chown root:root pifm sudo chmod 4755 pifm
Before you can oscillate any electromagnetic fields, you’ll need to make an aerial for your Pi. Instructions are in first paragraph of the drivel for pirbj.
Once you are sorted, start the whole lot up with the command:
To stop it press CTRL-C.
The gruesome details
There are quite a few files that make up pirpl. This is how they work.
This is the main program file. Have a look at it if you want to gaze in wonder at the insane beauty of Bash, but there is no need to edit it. All the configuration stuff is now in…
Various settings for things like the names of files, the transmitter frequency and where you installed pirpl. You probably want to change the transmitter frequency to somewhere empty on your radio’s dial. You will also need to change PIFM_BASE to the directory where you untarred the files. The web server port should not be accessible to the outside world. Other than that, it’s probably best to leave everything else as it is unless you really like reading error messages.
This is where you tell pirpl all about your music. Each line has the path to the playlist or directory containing MP3s, the displayed name of the playlist, and whether to shuffle it. I’ve left all my playlists in as examples. Actually, I forgot to delete them and now I can’t be bothered to take them out. Sorry. If you are using a playlist rather than a directory, the format is one path to an MP3 per line.
Your browser will show this as a web page so open that link, right click and choose “View page source” to see what is in it. You have probably worked out for yourself that this is a template file for showing the available playlists, as defined in pirpl_playlist.conf. The bits in “@@”s are replaced with the information about playlists. I’m sure you can work out what’s going on in that file.
This is the template for showing information about the track that is playing. It’s the usual stark functionality you get from me, simply because it works and I can’t be bothered to try and make it look nice.
This is the script that does the web server. It doesn’t do much; it just outputs a file to the browser and filters commands out of the text sent by the browser, storing any it finds in a file which is picked up by pirpl.sh.
The program that does the transmitting. It’s a barely modified version of this one and the source is included if you want to have a look and compile it yourself.
The best way to start Pirpl is as a service, when the Pi boots up. You don’t want to run it as root, so the easiest way to start it as a normal user is to put a command similar to this in your /etc/rc.local file:
sudo -u naich /home/naich/pirpl/startwrapper.sh
You could use sudo to start Pirpl directly but you end up with sudo hanging around like a bad smell in your process list.
Using this program without the proper license is probably illegal where you are, so don’t use it ever.