Active Topics

 



Notices


Reply
Thread Tools
Posts: 23 | Thanked: 7 times | Joined on Jun 2010
#1
I have written a script to listen to iheartradio streams using mplayer.

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:
  • Asks you for the station id (ex: wtfx-fm)
  • Asks how long the stream should play for
  • Check for song information every 10 seconds
  • Not Perfect

Code:
#!/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"
 

The Following User Says Thank You to pyther For This Useful Post:
Posts: 176 | Thanked: 262 times | Joined on Nov 2009 @ Texas, USA
#2
Found an easier method. The XML URL does not work for all stations and the station ID is hard to find.

They use a JSON API for getting the streaming info for the flash player on their site and you can use this to get all the data you need. Inside the JSON packet is a HTTP stream URL that works with the stock media player. The RTMP link is also there, if you want that, but I have found the HTTP stream works just fine.

Replace 0000 with the station number that can be found in the URL of your station you want to listen to.

curl -X POST -d 1 http://www.iheart.com/a/live/station/0000/stream/

Example:
Station on the site - http://www.iheart.com/live/1021-The-Edge-2815/

Take 2815 as the station number.

curl -X POST -d 1 http://www.iheart.com/a/live/station/2815/stream/

Take the "shoutcast_url" out of the JSON packet and plug that into the Maemo media player or whatever you want.
 

The Following 2 Users Say Thank You to mooninite For This Useful Post:
Addison's Avatar
Posts: 3,811 | Thanked: 1,151 times | Joined on Oct 2007 @ East Lansing, MI
#3
Is there somewhere that I can install curl on my Maemo 4 device?
 
Posts: 128 | Thanked: 53 times | Joined on Nov 2012
#4
Will this work with nokia n9?
 
bingomion's Avatar
Posts: 528 | Thanked: 345 times | Joined on Aug 2010 @ MLB.AU
#5
it doesn't work on the browser with the new flash?
 
Posts: 176 | Thanked: 262 times | Joined on Nov 2009 @ Texas, USA
#6
Originally Posted by Addison View Post
Is there somewhere that I can install curl on my Maemo 4 device?
I'm not sure, but you could just get the URL on another computer and then type it in your Maemo 4 device. The URL is not user or device specific.
 
Posts: 176 | Thanked: 262 times | Joined on Nov 2009 @ Texas, USA
#7
Originally Posted by unoace View Post
Will this work with nokia n9?
If the N9 can play HTTP streams, yes. I don't have an N9.
 
Posts: 176 | Thanked: 262 times | Joined on Nov 2009 @ Texas, USA
#8
Originally Posted by bingomion View Post
it doesn't work on the browser with the new flash?
If you can trick your flash to report >10 it might work, but think about it... would you rather run flash that uses a lot of power or just stream the audio feed in a low-resource music player.
 
Posts: 196 | Thanked: 141 times | Joined on Aug 2007
#9
Originally Posted by Addison View Post
Is there somewhere that I can install curl on my Maemo 4 device?
Old thread but still relevant http://talk.maemo.org/showthread.php?t=16292
 

The Following User Says Thank You to jcharpak For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 16:54.