| The Following User Says Thank You to pyther For This Useful Post: | ||
|
|
2013-01-22
, 05:52
|
|
Posts: 176 |
Thanked: 262 times |
Joined on Nov 2009
@ Texas, USA
|
#2
|
|
|
2013-01-22
, 09:45
|
|
|
Posts: 3,811 |
Thanked: 1,150 times |
Joined on Oct 2007
@ East Lansing, MI
|
#3
|
|
|
2013-01-22
, 10:20
|
|
Posts: 128 |
Thanked: 53 times |
Joined on Nov 2012
|
#4
|
|
|
2013-01-22
, 11:33
|
|
|
Posts: 528 |
Thanked: 345 times |
Joined on Aug 2010
@ MLB.AU
|
#5
|
|
|
2013-01-22
, 16:29
|
|
Posts: 176 |
Thanked: 262 times |
Joined on Nov 2009
@ Texas, USA
|
#6
|
|
|
2013-01-22
, 16:30
|
|
Posts: 176 |
Thanked: 262 times |
Joined on Nov 2009
@ Texas, USA
|
#7
|
|
|
2013-01-22
, 16:31
|
|
Posts: 176 |
Thanked: 262 times |
Joined on Nov 2009
@ Texas, USA
|
#8
|
|
|
2013-01-22
, 20:07
|
|
Posts: 196 |
Thanked: 141 times |
Joined on Aug 2007
|
#9
|
| The Following User Says Thank You to jcharpak For This Useful Post: | ||
The script is written in python so you can just save it as iheartradio.py and execute it with python iheartradio.py
You must compile a RECENT version of mplayer! The version from extra does not have rtmp support and will NOT work. SVN snapshot 32027 compiles in the SDK without a problem.
If there is a demand I can provide the mplayer binary and/or sources.
The Script:
#!/usr/bin/env python import subprocess import time import urllib2 import xml.etree.ElementTree as ET import os import datetime #Location of Stream to be SAVED DefaultStation="wtfx-fm" def getXML(): data=urllib2.urlopen('http://p2.'+station+'.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live').read() xml=ET.fromstring(data) return xml def getSongInfo(): xml=getXML() artist=xml.find('ListenLiveInitialize/JustPlayed/song/artist').attrib['name'] title=xml.find('ListenLiveInitialize/JustPlayed/song/track').attrib['track_title'] return artist,title while True: station=raw_input("Enter Station ID [" + DefaultStation + "]: ") if not station: station=DefaultStation try: xml=getXML() except urllib2.URLError: print "Error - Invalid Station ID or Web Server Problem - Try Again" else: break while True: try: TIME=int(raw_input("Time Stream will Play (in minutes): ")) except ValueError: print "Error - Invalid Time - Try Again" else: break rtmpurl=xml.find("ListenLiveInitialize/StreamInfo/stream").attrib['primary_location'] mp=subprocess.Popen(['/usr/bin/mplayer', rtmpurl, '-novideo', '-ao', 'pulse', '-quiet'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) mpPID=mp.pid endTime = datetime.datetime.now() + datetime.timedelta(minutes=TIME) OldSongInfo=[] while datetime.datetime.now() < endTime: SongInfo=getSongInfo() if not SongInfo == OldSongInfo: OldSongInfo = SongInfo print SongInfo[0] + " - " + SongInfo[1] time.sleep(5) print("Stopping MPlayer...") os.kill(mpPID, 2) print "Done"