Ticket #2021: run-houston-ktrh

File run-houston-ktrh, 886 bytes (added by yuri@…, 15 years ago)

Python script playing KTRH radio

Line 
1#!/usr/bin/env python
2
3import subprocess
4import time
5import urllib2
6import xml.etree.ElementTree as ET
7import os
8import datetime
9
10DefaultStation="ktrh-am"
11
12def 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
17def 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
25station=DefaultStation
26
27try:
28 xml=getXML()
29except urllib2.URLError:
30 print "Error - Invalid Station ID or Web Server Problem - Try Again"
31
32rtmpurl=xml.find("ListenLiveInitialize/StreamInfo/stream").attrib['primary_location']
33
34os.system('/usr/local/bin/mplayer \"'+rtmpurl+'\" -novideo -ao pulse -quiet');