My Raspberry Pi Internet Radio Show Ripper!




DISCLAIMER: This page really isn’t a tutorial as there are various tutorials online for ripping streaming audio content but I do intend on showing how I setup my raspberry pi to record some of my favorite streaming radio shows that I cannot listen to locally. If you have any specific questions on steps that I have not covered, I would be happy to address them if I can. Comment below or simply click on Contact Me up top and I’ll do what I can to assist. For the time being, this page is a work in progress.

I’ve always loved the vintage feel of a nice Linux machine but never really had a reason to have one at home. Then in 2012, the Raspberry Pi foundation came out with this cool little headless Linux computer called the Raspberry Pi. The rest is history!

Armed with my community college Linux skills, I picked one up to play around with. It was just the coolest thing ever once I got it set up but once I had the 32Gb Micro USB Card imaged and the Pi up and running, I was left with “What do I do with this thing now?” So I thought about all of the cool projects others have posted online and decided to build an Internet Radio Ripper, specifically an Internet Radio Show Ripper. There are various ways to rip radio shows from the Internet, some are free and some not so much. There is even a service you can pay an annual fee for that will accomplish the same thing. I was just looking for a project with very low cost and the ability to fully customize the rips produced.

There are a 3 radio shows that I like to listen to every week, The House of Hair with Dee Snyder, Absolutely 80’s with Nina Blackwood, and BacktraxUSA with Kid Kelly. One of my local stations used to play HOH every week so it was real easy to find the source link for their stream but I had to hunt for the other 2.

Setting Up the Pi

The only real setup I had to do for the Raspberry Pi was to install the Streamripper app and that was done by entering:

sudo apt-get install streamripper

Mounting a NAS Directory

Once Streamripper is installed, you need to decide where you are going to be keeping your ripped streams, IE: on the local SD card or on a mounted NAS. If you’re planning on saving a lot of rips locally then you might want to invest in a 32Gb Micro USB Card for the Raspberry Pi. That will leave you some space to save them at least temporarily. Initially, I saved them locally and then moved them off of the SD Card to a mounted network drive once a week to keep the it from filling up over time and crashing the Raspberry Pi.

I initially used the local SD for storing my rips but quickly found that the more streams I added to Streamripper, the quicker my SD Card filled up so I decided to create a network share on my NAS and mount it on my Pi. I did this by first creating the shared folder Shows on my NAS and then did a bunch of research on permissions and mounting because I couldn’t get it to work no matter what I tried. I finally got it narrowed to permissions causing me the heart ache. I finally got the permissions set up correctly and mounted the NAS directory to my Raspberry Pi by entering the following line into my /etc/fstab file on my Raspberry Pi: 192.168.0.122:/volume1/Shows /mnt/Shows nfs nouser,atime,auto,rw,dev,exec,suid 0 0

Here you can see I have mounted my NAS folder Shows to my local Shows folder on the Raspberry Pi. So now when I rip something, the Pi saves it to the NAS folder instead of locally. I have been running it this way for a very long time and haven’t had any bandwidth issues from multiple streams ripping at once.

Once I had Streamripper installed and running and writing to my mounted NAS directory, I needed to find some streams that ran the shows I was wanting to listen to. Like everything else with computers, there are a bunch of different ways to do this. I opted to use a sniffer program called URLSnooper2. It basically sniffs all of your inbound traffic and gives you the URLs of what you’re actively streaming. Keep in mind though that some streams use a form of security and can’t be ripped automatically, or at least I haven’t been able to figure out how to do it yet. If you know how, let me know!

Finding Your Streams

If you’re fortunate enough to be in the listening area of a station that plays your favorite show then you’re one step ahead of the game. For me, I had to do many Internet searches and try to track them down via TuneIn’s horribly outdated show schedule. For our purposes though, we’ll use CJTN as a known station that plays the House of Hair Radio Show every weekend. Thanks CJTN! So lets head on over to CJTN’s Website. You’ll see that they have a Listen Live link at the top right corner of their home page. Don’t click on it just yet. First you’ll need to get URLSnoop up and running. If you already have it running, click on Sniff Network and you should see the window start filling up with url’s that you are currently connected to. Depending on you network setup, there could be a huge list of addresses or possibly just a few. If you’re in the same situation as me, you’ll have tons! Too many to scroll through each one so you’ll be happy to know that you can use the filter function of URL Snooper to search through the madness and find your target url.

So what I am going to do is Click on Sniff Network as seen above and then type in CJTN in the box that says Must Contain. You’ll see below that I have one entry in there because I already opened the CJTN website.

Now with URLSnooper actively running, I am going back to the CJTN site that we opened up earlier and I’m going to click on the Listen Live link to launch their stream player. You’ll see URLSnooper fill up with links that all have CJTN in them but you’re looking for something like this:

You can take the url http://live.leanstream.co/CJTNFM-MP3 and pop it into VLC media player and listen to the stream for verification that the link is good. I happened to notice with this stream that if you remove the -MP3 from the end of the station name the stream is received in .AAC format instead of MP3. I like the sound of .AAC files because they aren’t as compressed sounding as MP3 files. Now that you have your Raspberry Pi setup, your directory mounted or setup, and your target url handy, you’re most of the way there!

Making the Action Happen!

Now you only need to setup a super easy shell script file and setup a cronjob to kick it off at whatever time your show begins. The shell script is nothing more than the command that you would run from the terminal if you wanted to kick off a recording manually. I used nano to take care of this by simply typing sudo nano cjtn_hoh.sh. This opened a blank file called cjtn_hoh.sh for me to paste my streamripper command into.

For my example, I’ll be saving my rips to a mounted NAS drive who’s located at /mnt/Shows/ and the command I use is as follows:

sudo streamripper http://live.leanstream.co/CJTNFM -l 14400 -k 0 -a HOH_CJTN_%D -A -m 10 -s -d /mnt/Shows/HOH_CJTN2/"$(date -I)"

This command breaks down as follows:
sudo streamripper Run Streamripper as Root.
http://live.leanstream.co/CJTNFM This is the direct url of the radio station stream that I am ripping the show from.
-l 14400 This tells Streamripper that I want to rip the stream for 14,400 seconds, or 4 hours. (It’s a 3 Hour show with some padding thrown in there)
-k 0 This is the number of files to leave in the incomplete directory. I use 0 to keep incomplete files from taking up space.
-a HOH_CJTN_%D This tells Streamripper to record 1 single file and gives it a naming pattern.
-A This ensures only one file will be created.
-m 10 This tells Streamripper to kill the inactive connection after 10 seconds if it drops. Streamripper will then try to reconnect.
-s This keeps Streamripper from making an individual directory for each rip and allows me to keep them all in one CJTN directory instead.
-d /mnt/Shows/HOH_CJTN2/"$(date -I) This simply tells Streamripper where to save the rips. You can see here that I am using a mounted directory called Shows and the CJTN folder to save all of the files I rip from them. You could simply save them to /home is you’re wanting them to be saved on your SD card.

I simply type out or paste this command into the cjtn_hoh.sh file and hit CTRL+X to close the file in nano. It’ll ask if you wan to save it first and you select Y to save it. Now you have to make this shell script executable so you issue the command sudo chmod u+x cjtn_hoh.sh and the script can then be executed by typing sh cjtn_hoh.sh or ./cjtn_hoh.sh. You could run this command manually and have it run in the background but you’d have to kick it off every time you want to record the show and where is the fun in that??

Setup Crontab

Setting up crontab is pretty straight forward. Here’s my entry:

45 19 * * 5 /home/pi/cjtn_hoh.sh >> /home/pi/ripperlogs/cjtn_hoh.sh.log

This simply tells cron to kick off my cjtn_hoh.sh script every Friday(5) night at 1945 local time and it redirects any output to my log folder that I created on my Raspberry Pi. I have another script that deletes the logs weekly so that they don’t fill up the Raspberry Pi eventually as well.

Putting it All Together

The nice thing about ripping streams this way is that I have full control of my recordings and I can rip as many as my bandwidth will allow at any given time. It’s pretty much a set it and forget it installation except for the times that the radio stations switch formats and stop playing my particular show or they switch streaming providers and I have to go and hunt down the new URL.

When my shows finish ripping, I can break out my favorite audio editor and strip out the commercials. Then I save the files to my media library for later listening.

That’s about it for now. Hopefully this will help someone out. If you have any questions, hit me up and I’ll try to help you out.

-Steve