twitter |   ||  email | PGP --> harshal @ harshdevx.com

r00tan4lyt1csgalleryabout m3

stream recorder, internet radio, media

in my previous article i covered how you can setup your home fm transmitter using $50 HiFast USB transmitter. lets take this one step further. i wanted to listen to radio streams however that are in a different time zone. so question was how to schedule recording and broadcast it within my house so that i can listen to the stream without a hassle. also my father lives in a different city than therefore the files i record can be made available to him so that he can listen to the streams as well.

so for example i want to record all india radio (AIR) thats broadcast in indian timezone. i specifically picked up AIR because of the m3u8 playlist. the data is received in chunks. i spent alot of days to find how the data is received and processed by vlc and finally cracked this.

#!/bin/bash

#ALL INDIA RADIO BROADCASTS MORNING PROGRAMS FOR 10 HRS

#morning schedule of 10 hours

#variables declarations

DATE=`TZ='Asia/Kolkata' date +%Y-%m-%d`

DAYBEFORE=`TZ='Asia/Kolkata' date +%Y-%m-%d -d "-1 day"`

DSTFLAG=`if perl -e 'exit ((localtime)[8])' ; then echo -n "winter"; else echo -n "summer"; fi`;

HOUR=`date +%H`;

#UPDATED [SHOWN IN BOLD]THIS WILL TAKE CARE OF DST TIME DIFFERENCE

if ([ $DSTFLAG == "summer" ] && [ "$HOUR" == "06" ]) || ([ "$DSTFLAG" == "summer" ] && [ "$HOUR" == "19" ]) || ([ "$DSTFLAG" == "winter" ] && [ "$HOUR" == "05" ]) || ([ "$DSTFLAG" == "winter" ] && [ "$HOUR" == "18" ]); then

IST=`TZ='Asia/Kolkata' date +%H-%M`

URL="http://vividhbharati-lh.akamaihd.net/i/vividhbharati_1@507811/index_1_a-p.m3u8?sd=10&rebase=on"

LOC1=/media/usb1/music/air/vividhbharati

DCLOC1=/media/username/datadisk1/music/air/vividhbharati

#THE RECORD SCRIPT ACCEPTS PARAMETER FOR MORNING[AM]/EVENING[PM]

SCHEDULE=$1

#recordings of one hour each

TIME=1800

#MOUNTED=`df | awk '{ print $1" "$6 }' | grep -iE "music" | wc -l`

#LIST=$LOC1/list.txt

#FIND FILES AND DELETE OLD FILES

FILES=`find $LOC1/ -iname *.mp3 | wc -l`

if [ "$FILES" > "0" ];then

if [ "$SCHEDULE" == "am" ]; then

rm $LOC1/$DAYBEFORE-AM-am-*

ssh -i /home/pi/keyfile username@192.168.1.35 "rm -f $DCLOC1/$DAYBEFORE-AM-am-*"

elif [ "$SCHEDULE" == "pm" ]; then

rm $LOC1/$DAYBEFORE-AM-pm-*

ssh -i /home/pi/keyfile username@192.168.1.35 "rm -f $DCLOC1/$DAYBEFORE-AM-pm-*"

fi

fi

fi

FILENAME="$DATE-AM"

if [ "$SCHEDULE" == "am" ]; then

for COUNT in {1..21}

do

IST=`TZ='Asia/Kolkata' date +%H-%M`

avconv -i "$URL" -t $TIME $LOC1/$FILENAME-$SCHEDULE-$IST.mp3

#THIS IS FOR INDIVIDUALS RUNNING SUBSONIC I CALL THE RESTAPI TO UPDATE THE SUBSONIC DATABASE

curl -X GET "http://192.168.1.35:4040/rest/startScan.view?u=admin&t=e4530216ce424c73e04a70c479e1f472&s=teststring&v=1.16.0&c=myapp"

done

#ALL INDIA RADIO BROADCASTS EVENING PROGRAMS FOR 6.5 HRS

#evening schedule of 6.5 hrs

elif [ "$SCHEDULE" == "pm" ]; then

COUNT=""

for COUNT in {1..13}

do

IST=`TZ='Asia/Kolkata' date +%H-%M`

avconv -i "$URL" -t $TIME $LOC1/$FILENAME-$SCHEDULE-$IST.mp3

#THIS IS FOR INDIVIDUALS RUNNING SUBSONIC I CALL THE RESTAPI TO UPDATE THE SUBSONIC DATABASE

curl -X GET "http://192.168.1.35:4040/rest/startScan.view?u=admin&t=e4530216ce424c73e04a70c479e1f472&s=teststring&v=1.16.0&c=myapp"

done

fi

#FOR INDIVIDUALS RUNNING MPD MUSIC PLAYER DAEMON UPDATE THE DATABASE WITH NEW FILES RECORDED

mpc -h 192.168.1.6 update

#CODE ENDS HERE

so now we have recorded all programs how do the files look?

Click to englarge me

we have the programming now lets broadcast them. i created another shell script to broadcast the programming using my media player daemon (MPD).

#!/bin/bash

#variable declarations

DATE=`date +%Y-%m-%d`

YESTERDAY=`date +%Y-%m-%d -d "-1 day"`

SCHEDULE=$1

FILENAME="$DATE-AM"

if [ "$SCHEDULE" == "am" ]; then

mpc clear

#MPC has ability to search folders from bash

mpc ls air/marathi/ | grep "$DATE-AM-$SCHEDULE-" | mpc add

mpc play

fi

if [ "$SCHEDULE" == "pm" ]; then

mpc stop

mpc clear

#MPC has ability to search folders from bash

mpc ls air/marathi/ | grep "$DATE-AM-$SCHEDULE-" | mpc add

mpc play

fi

sorry just one last thing.......automate the whole friggin job...

Click to englarge me

concept and design: harshdevX