Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a bash script I'm running that plays a station from iHeartRadio in the CLI. I also use it to record a show in the early morning on my RaspPI so I can listen later in the day.

The script works fine, but the Auth code from iHeartRadio changes every 5 to 10 minutes and the time frame changes randomly.

Somehow I have to get the script to detect this and change the url when it changes to keep the show running.

My current code for live is:

rtmpdump --live -r $(wget -O - -q "http://p2.wspd-am.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live" | sed -n "s|.*primary_location=\"\(rtmp://[^\"]*\)\".*|\1|p") | mplayer -vo null -idle -

and for saving

rtmpdump --live -r $(wget -O - -q "http://p2.wspd-am.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live" | sed -n "s|.*primary_location=\"\(rtmp://[^\"]*\)\".*|\1|p") > audio.aac

The problem like I said is the changing primary_location which contains an auth code in it and it changes at random time intervals.

How would I keep this updated best?

I thought about running the rtmpdump in the background & then running a while loop with a 30 second sleep to check the url. When the url changes kill the old process and re-spawn. But there has to be a better way to do this and more streamlined.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.