| 1 | #!/usr/bin/env python
|
|---|
| 2 |
|
|---|
| 3 | import subprocess
|
|---|
| 4 | import time
|
|---|
| 5 | import urllib2
|
|---|
| 6 | import xml.etree.ElementTree as ET
|
|---|
| 7 | import os
|
|---|
| 8 | import datetime
|
|---|
| 9 |
|
|---|
| 10 | DefaultStation="ktrh-am"
|
|---|
| 11 |
|
|---|
| 12 | def getXML():
|
|---|
| 13 | data=urllib2.urlopen('http://p2.'+station+'.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live').read()
|
|---|
| 14 | xml=ET.fromstring(data)
|
|---|
| 15 | return xml
|
|---|
| 16 |
|
|---|
| 17 | def getSongInfo():
|
|---|
| 18 | xml=getXML()
|
|---|
| 19 | artist=xml.find('ListenLiveInitialize/JustPlayed/song/artist').attrib['name']
|
|---|
| 20 | title=xml.find('ListenLiveInitialize/JustPlayed/song/track').attrib['track_title']
|
|---|
| 21 | return artist,title
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | station=DefaultStation
|
|---|
| 26 |
|
|---|
| 27 | try:
|
|---|
| 28 | xml=getXML()
|
|---|
| 29 | except urllib2.URLError:
|
|---|
| 30 | print "Error - Invalid Station ID or Web Server Problem - Try Again"
|
|---|
| 31 |
|
|---|
| 32 | rtmpurl=xml.find("ListenLiveInitialize/StreamInfo/stream").attrib['primary_location']
|
|---|
| 33 |
|
|---|
| 34 | os.system('/usr/local/bin/mplayer \"'+rtmpurl+'\" -novideo -ao pulse -quiet');
|
|---|