maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Multimedia (https://talk.maemo.org/forumdisplay.php?f=32)
-   -   [script] Listen to iheartradio (mplayer) (https://talk.maemo.org/showthread.php?t=61498)

pyther 2010-09-01 00:17

[script] Listen to iheartradio (mplayer)
 
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"


mooninite 2013-01-22 05:52

Re: [script] Listen to iheartradio (mplayer)
 
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.

Addison 2013-01-22 09:45

Re: [script] Listen to iheartradio (mplayer)
 
Is there somewhere that I can install curl on my Maemo 4 device?

unoace 2013-01-22 10:20

Re: [script] Listen to iheartradio (mplayer)
 
Will this work with nokia n9?

bingomion 2013-01-22 11:33

Re: [script] Listen to iheartradio (mplayer)
 
it doesn't work on the browser with the new flash?

mooninite 2013-01-22 16:29

Re: [script] Listen to iheartradio (mplayer)
 
Quote:

Originally Posted by Addison (Post 1316544)
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.

mooninite 2013-01-22 16:30

Re: [script] Listen to iheartradio (mplayer)
 
Quote:

Originally Posted by unoace (Post 1316556)
Will this work with nokia n9?

If the N9 can play HTTP streams, yes. I don't have an N9.

mooninite 2013-01-22 16:31

Re: [script] Listen to iheartradio (mplayer)
 
Quote:

Originally Posted by bingomion (Post 1316576)
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.

jcharpak 2013-01-22 20:07

Re: [script] Listen to iheartradio (mplayer)
 
Quote:

Originally Posted by Addison (Post 1316544)
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


All times are GMT. The time now is 21:07.

vBulletin® Version 3.8.8