Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python script to send urls from streamtheworld.com (iheartradio) to player. #25

Open
NonaSuomy opened this issue Apr 6, 2017 · 8 comments

Comments

@NonaSuomy
Copy link

NonaSuomy commented Apr 6, 2017

Send a radio station to your Ka-Radio player: GIST

Simple script, at the top of the script is the usage example, basically find a radio station on iheartradio:

iheartradio station list USA
iheartradio
iheartradio Canada

Look at the source code of the iheartradio page (click on song history will help a bit) you will find things like this in it:

view-source:http://www.iheartradio.ca/all-stations/7.13793734?mode=history

<div class="delayed-image-load" data-class=""  data-src="/image/policy:1.1870492:1472654994/Trancid.jpg?f=default&$p$f=a34e00f&{width}" data-ratio="" data-alt="">

                                        <noscript><img class="" itemscope="image" alt="" src="/image/policy:1.1870492:1472654994/Trancid.jpg?f=default&w=200&$p$f$w=a199ace" /></noscript>
                        
        </div>
        
    
                    <div class="streamIcon">
                        <button class="stream-link stream-radio-station" data-ajax="true"
                                                        data-station-callsign="IHR_TRAN"
                                data-ad-unit="/5479/iheartradio.en/allstations"
                                data-ad-ss="radioplayer"
                                data-station-id="1.1870491"
                        > 
                            <span class="ico ico-play">
                                <span class="ico load-hover"></span>
                            </span>
                        </button>

This is what we want:

data-station-callsign="IHR_TRAN"

IHR_TRAN is the callsign for the station you want to play. (Trancid)

Another stations callsign CIMXFM etc.

This is the radio station we are grabbing below from iheartradio 89x "CIMXFM"

Usage: python2 streamtheworldka.py CIMXFM 10.13.37.65
                                   ^Radio callsign  ^IP address of Ka-Radio Device

Make sure you have python2 and curl installed on the system you are sending the station from, download the script to a file on that device, then type the command, I named the script streamtheworldka.py, so type on the command line:

python2 streamtheworldka.py (The radio call sign + FM/AM on the end) (IP Address of your Ka-Radio Player)

First, test with the call sign above/below make sure it is all in CAPS as I know that one works (may not work outside of Canada), the hard part would be finding how they named the call sign for the station you want, and some may be location locked so be aware. Also add FM/AM on the end of the call sign or the script will complain "Callsign is missing FM, AM".

The script then tells the website to give us the ShoutCast stream URL for audio stream compatibility purposes with _SC.

python2 streamtheworldka.py CIMXFM 10.13.37.65

The script is grabbing the stream URL that is a randomly encoded string of characters for that station you want, then send the URL to the ESP8266.

The script requests a URL like this:
http://playerservices.streamtheworld.com/api/livestream?version=1.5&mount=CIMXFM&lang=en

Then it sends back an XML which we extract the values from:

<live_stream_config xmlns="http://provisioning.streamtheworld.com/player/livestream-1.5" version="1.5">
  <script/>
    <mountpoints>
      <mountpoint>
        <status>
          <status-code>200</status-code>
          <status-message>OK</status-message>
        </status>
        <transports>
          <transport>http</transport>
        </transports>
        <metadata>
          <shoutcast-v1 enabled="true" mountSuffix="_SC"/>
          <shoutcast-v2 enabled="false" mountSuffix="_SC"/>
          <sse-sideband enabled="true" streamSuffix="_SC" metadataSuffix="_SBM"/>
        </metadata>
        <servers>
          <server sid="18853">
          <ip>18853.live.streamtheworld.com</ip>
          <ports>
            <port type="http">80</port>
            <port type="http">3690</port>
          </ports>
        </server>
        <server sid="17023">
          <ip>17023.live.streamtheworld.com</ip>
          <ports>
            <port type="http">80</port>
            <port type="http">3690</port>
          </ports>
        </server>
        <server sid="13733">
          <ip>13733.live.streamtheworld.com</ip>
          <ports>
             <port type="http">80</port>
             <port type="http">3690</port>
          </ports>
        </server>
        <server sid="14213">
          <ip>14213.live.streamtheworld.com</ip>
          <ports>
            <port type="http">80</port>
            <port type="http">3690</port>
          </ports>
        </server>
      </servers>
      <metrics>
        <tag name="uuid"/>
      </metrics>
      <mount>CIMXFM</mount>
      <format>FLV</format>
      <bitrate>48000</bitrate>
      <media-format container="flv" cuepoints="stwcue">
        <audio index="0" samplerate="22050" codec="mp3" bitrate="48000" channels="2"/>
      </media-format>
      <authentication>0</authentication>
      <timeout>0</timeout>
      <send-page-url>0</send-page-url>
    </mountpoint>
  </mountpoints>
</live_stream_config>

The script extracts,

Random generated IP: 18853.live.streamtheworld.com
Port: 80, 3690, etc
MountPoint(callsign): CIMXFM

I noticed that there was ShoutCast compatibility in the XML which it shows to add "_CS" onto the mount point: CIMXFMAAC_CS

Then the script sends this data gathered from the XML to Ka-Radio device:

curl http://10.13.37.65/?instant="18853.live.streamtheworld.com:3690/CIMXFMAAC_SC"

Then Ka-Radio should start playing the stream.

If you attach a serial cable to Ka-Radio you should be able to debug what URL is getting passed to it, to see if the station is getting sent properly.

Successful run should look like this on the serial line:

$ cu -l ttyUSB0 -s 115200
Connected.
#INFO:""#
##CLI.STOPPED# from Web Instant
##CLI.URLSET#: 18863.live.streamtheworld.com
##CLI.PATHSET#: /CIMXFMAAC_SC
##CLI.PORTSET#: 3690
##CLI.ICY0#:  
##CLI.ICY3#:  http:\/\/www.89xradio.com
##CLI.ICY4#:  Rock
##CLI.ICY5#:  40
##CLI.ICY6#:  
##CLI.PLAYING#
##CLI.META#: Soundgarden - Fell On Black Days (89X Live-X

Someone with FreeRTOS skills could probably bake this into Ka-Radio, if there was enough memory, but probably best if it was a plugin of sorts, as they could change the way their API works at any moment. Have a hardware button that always generates the random URL and play's your favorite radio station.

Hope it helps!

@NonaSuomy NonaSuomy changed the title Python script to send urls from streamtheworld.com to player. Python script to send urls from streamtheworld.com (iheartradio) to player. Apr 6, 2017
@desadsea
Copy link

Hi, sorry but I did not understand how to use the script, could you make a practical example? Thanks Ezio

@NonaSuomy
Copy link
Author

NonaSuomy commented Apr 22, 2017

@desadsea Information Added to First Comment!

@NonaSuomy
Copy link
Author

NonaSuomy commented Apr 23, 2017

@desadsea I have to thank you, I clicked on your name and you had a fork repository for Esp-radio with Arduino, been hacking away at it and got it loaded, radio stations stream flawlessly, where I couldn't get Ka-Radio to stream anything over 24Kbps. It does 320kbps@160Mhz 256kbps@80Mhz, Also, it uses no EXT RAM just a Ring Buffer. Guess I will be switching over to it for now until I find an issue with it that I can't solve like stuttering with Ka-Radio Issue #24. Will have to try this script with it as well 👍 Edit: Simple change to get it working with it just change the word "instant" to "station" and it works w00t! Stream no longer drops out randomly seems to sound less tinny for some reason. Looks like it has an MQTT function will have to check that out as my house automation is MQTT based 😸 GIST for esp-radio change

@desadsea
Copy link

@NonaSuomy Thank you for having responded, and helped me to figure out how Python script works,
As soon as I have the time I want to try, with regard to the esp with arduino, it's not my project I put it on githbub and how would you like to try it, thank you again for your kindness Ezio.

@NonaSuomy
Copy link
Author

Did an OpenHAB mod for ESP-Radio

@NonaSuomy
Copy link
Author

And integrated the xml parser into ESP-Radio for IHeartRadio

@karawin
Copy link
Owner

karawin commented May 4, 2017 via email

@NonaSuomy
Copy link
Author

Just to note the parser I did was included into the main branch of ESP-Radio now for anyone interested presets look like ihr/CIMXFM.

StreamTheWorld consumes local radio station content and then they rebranded the site as iHeartRadio.

Some people enjoy local radio content stations for stuff relative to them or feels of nostalgia.

wiki iHeartRadio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants