2005-10-13

Live365 radio from the command line

One of my passions is the music of Harry Nilsson. Luckily for me, one of the perks of the Internet Age is that finding others that share your passions is pretty easy. For Nilsson fans around the world, the website and mailing list run by Roger Smith has been the medium for that sharing. (Click on Harry's name above to see Roger's site.)

One of the longtime members of the NilssonWeb is Tom Westendorf, or "Old Tom" as he calls himself. Recently, Old Tom started a radio station on Live365.com, heavily featuring our Harry in the playlist. Naturally, I wanted to hear it. I couldn't, however, stand the idea of having to run a graphical client or a web browser in order to listen. I run Linux, after all, so I'm no stranger to the command line. Not to mention that we're talking about audio streaming here. There's no pictures, folks, so why should a GRAPHICAL User Interface be required?

This leads me to this episode's Scripting Pet Trick, which requires only two appications installed on your box: curl, an incredibly useful URL retriever, and mplayer, the best media player ever.

The trick here is to tell curl to remember the cookies it gets when browsing Live365, using the Unix 'cut' utility to pull information out of the cookie jar, and feeding that information into the URL for mplayer.

Other things to note: you have to register (free) with Live365.com, and get your userid and password, and fill them in at the top of the script. Obviously, this is not a secure way of handling things. I should probably have the script ask me the password every time. Also, you'll see that I had to yank the userid out of the session cookie value before passing it to mplayer. I'm also hard-coded to Tom's station here. You may want to browse Live365 for some other choices.

The script:

#! /bin/sh

USERID=useridgoeshere
PASSWD=passwordgoeshere

curl --cookie-jar curlcookies   --output curldump --location-trusted "http://www.live365.com/cgi-bin/login.cgi?url=http://www.live365.com/index.live&membername=${USERID}&password=${PASSWD}"

SANE=`grep SaneID curlcookies | cut -f7`
SESS=`grep sessionid curlcookies | cut -f7 | sed s/${USERID}%3A//`

# Westendorf radio
STATION=326329

mplayer "http://www.live365.com/play/${STATION}?SaneID=${SANE}&membername=${USERID}&session=${SESS}"

Happy streaming! (Oh, and Tom? Nice playlist...)

Tags: , , , , , , ,

8 comments:

Black Wolfette said...

Maybe it's been too much since you posted this wonderful solution here... However, thanks, a lot! It's exactly what I've been looking for during the last year. Thanks again.

Black Wolfette

Anonymous said...

Many thanks. It works perfectly for me too.
I have been trying for such a long time so many things including those indicated in Live365's help that never worked.
I replaced mplayer by gmplayer and put the script in a launcher applet, having so a way to initiate and stop the listening without the use of a console.
In my case the station is not identificated by a number but by its name : hotclubdepott
Once again many, many thanks Bjimba

"Jazz manouche" fan

humpy101 said...

Thanks, this was great!! Worked for me. My favourite station is john262 btw.

Galbinus_Caeli said...

Thanks for this! Very useful.

I did change it so that I could use it on my headless media server (an old linux box in a closet connected to my home sound system.)

It takes the station ID from GET information from an HTML form.

My version looks like this:


#! /bin/sh
# Read the station ID from HTML form.
STATION=`echo "$QUERY_STRING" | cut -f 2 -d =`
echo "Content-type: text/html"
echo ""
echo ""
echo "<html><head></head><body>"
USERID=userid
PASSWD=password

`curl --cookie-jar curlcookies --output curldump --location-trusted "http://www.live365.co
m/cgi-bin/login.cgi?url=http://www.live365.com/index.live&membername=${USERID}&password=${PA
SSWD}"`
SANE=`grep SaneID curlcookies | cut -f7`
SESS=`grep sessionid curlcookies | cut -f7 | sed s/${USERID}%3A//`

echo "<p>Playing Live365 station number: $STATION"
mplayer "http://www.live365.com/play/${STATION}?SaneID=${SANE}&membername=${USERID}&session=
${SESS}"
echo "</body></html>"


And the form to call it looks like this:


<form METHOD=GET ACTION=/cgi-bin/live365.sh>
<input type=submit value="Play Live365 station from list">
<select name="stationid">
<option value="233955">AltRok Radio</option>
</select>
</form>
<input type=submit value="Play Live365 by station number:">
<input type=text name=stationid value="233995">
</form>

MathiasPayer said...

Hey, still works like a charm! Thanks for figuring out all the weird parameters - it's easier to Google for them than to check them yourself ;)

Jim said...

This is great! Five years later, and people are still finding some use for this post.

Kimmo said...

Jim, thanks a lot! This was just what I had been looking for, it work's perfectly. Maybe I'll figure out some way of using this with Radio Tray application. Anyway, thanks!

Kimmo

btw. Radio Salsa Picante drove me into searching for this.

Anonymous said...

How do you find a live365 station's station ID?
Is it in the HTML somewhere or in a cookie?

Once upon a time, I was able to search a station's web page HTML to get the ID, but either I forgot how to do it, or Live365 changed their HTML and it is not easily accessible.

Thanks.