GrabRadio.sh

Most webradios nowadays provide a podcast service but it wasn’t the case until recently a few years ago and even now it frequently happens that your favorite radio program is only available via streaming, making it impossible to listen to it on your mp3 player. Here is a script to record RealAudio streams, turn them into MP3s and store them in the relevant directories. Linux only.

radiolist (cf the bottom of the script) is a text file with one recording per line: name_of_the_program url

Select All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
 
# Grab RealAudio stream and turn it into mp3
# grabradio.bash
# Chris Ladroue
 
# Variables
tmp=/home/XXXX/tmp
dest=/home/XXXX/media/podcasts
 
 
# for cronjobs
cd $(dirname $0)
 
# Clean up
rm -f $tmp/tmp_grabradio.wav
 
while read  folder url
do
if ! grep "$url" .radiolist > /dev/null
then
echo "--"
echo $folder $url
 
# Record in wav
/usr/bin/mplayer -noconsolecontrols -ao pcm:file=$tmp/tmp_grabradio.wav -vc dummy -vo null -playlist "$url"
 
# Create directory if necessary
if test ! -d $dest/$folder
then
mkdir $dest/$folder
fi
 
# Turn into mp3
ts=`date +'%Y_%m_%d_%H_%M'`
fn=`echo "$folder"_"$ts"`
 
title=`echo $folder | cut -c1-30`
/usr/bin/lame -b 96 --tt $ts --ta $title $tmp/tmp_grabradio.wav $dest/$folder/$fn.mp3
 
# Clean up
rm -f $tmp/tmp_grabradio.wav
 
# add to global m3u
echo $folder/$fn.mp3 | cat - $dest/latest.m3u >> $dest/latest.m3u.tmp
mv -f $dest/latest.m3u.tmp $dest/latest.m3u
 
# add url to .radiolist so that won't be recorded again
echo "$url" >> .radiolist
fi
done < /home/XXXX/scripts/radiolist

Comments are closed.