How to record online radio

There are some online radio stations I like to listen to throughout the day. The problem is that when you are off-line or when you have traffic limitations the Internet online radio is either unavailable or you may be motivated against using it.

So I have learned how to record my favourite radio station 24/7 at a computer which is permanently online (a server), in order to listen to the recorded music on my laptop when I am off-line. Command line version of VLC multimedia player and a simple Bash script do the job.

(Note: In the examples below replace the <online_radio_server_url_goes_in_here> with the Internet address of your your favourite online radio and <user> with your actual user name)

Let us assume, that we want all the recordings go into the directory:
/home/<user>/Recordings
and the script itself also will be kept in the subdirectory there:
/home/<user>/Recordings/Bin

So we run the text editor and write in the following:

#!/bin/sh
NOW=$(date +"%b-%d-%y")

cvlc --run-time=86400 http://<online_radio_server_url_goes_in_here> --sout "#duplicate{dst=std{access=file,mux=raw,dst=/home/<user>/Recordings/record-$NOW.mp3}" vlc://quit ;

We name the file record.sh and save it to the /home/<user>/Recordings/Bin.

Don’t forget to give the execution rights to the script file you just created. Either using a file manager or at the command line:

 chmod +x /home/<user>/Recordings/Bin/record.sh

In order to run the recording on daily basis, let’s create a cron job:

  •   Run the command to edit the cron job list
 crontab -e
  •   Enter the following string at a new row:
 00 00 * * * /home/<user>/Recordings/Bin/record.sh

To be sure the crontab schedule has been updated, list the current cron jobs and see if it is there:

 crontab -l

Now. What all of the above does?
Every day at midnigt cron will run the script. The script will start VLC. It will save music from the online radio station to a file stamped with the date the script was run on. VLC will run for 86400 seconds which is full 24 hours. After that, if all goes well, cron will run the script again. The script will start VLC again. And so on…

P.S.
If some day we want to cancel the automatic recording, we just edit the crontab file one more time and delete the respective row:

 crontab -e
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s