Author Topic: TuneIn API Integration  (Read 118001 times)

laurent-CETARadio

  • New User

  • Offline
  • *
  • 26
    • CETA Radio
Re: TuneIn API Integration
« Reply #60 on: December 17, 2014, 05:56:34 PM »
Hello, I would like to contribute to this script.
Our radio station is listed on radioline and the specification need an xml file to submit to their staff.

My little contribution...

Code: [Select]
<?php
define
('RDJ_PASSWORD''xxxxxx'); // RadioDJ Web Export password
$partnerId "xxxxxx"// TuneIn API partner ID
$partnerKey "xxxxxx"// TuneIn API partner key
$stationId "xXXXXXX"// TuneIn API station ID
$stationName "XXXX Radio"// Station Name
$timezone "Europe/Paris"// Time Zone Station
$stationurl "http://www.xxx.yy"// Station Url 

ini_set('error_log''php_error.log');
ini_set('log_errors''on');
error_reporting(E_ERROR E_WARNING E_PARSE);

// file_put_contents('data.txt', print_r($_POST, true)); // comment out this line after debugging

if ( isset($_POST["xpwd"]) && stripcslashes($_POST["xpwd"]) == RDJ_PASSWORD && isset($_POST["title"]) ) {    
    
$artiststripcslashes($_POST["artist"]);
    
$title stripcslashes($_POST["title"]);
    
$start stripcslashes($_POST["start"]);
    
$durations stripcslashes($_POST["durations"]);
    
$artist_tuneinurlencode(stripcslashes($_POST["artist"]));
    
$title_tunein urlencode(stripcslashes($_POST["title"]));
    
$track_type = isset($_POST['track-type'])? (int)$_POST['track-type'] : -1;
    
$commercial = ($track_type === 0) ? 'false' 'true'// Check if track-type is exactly 0 (for Song) and set commercial flag accordingly

    
$url "http://air.radiotime.com/Playing.ashx?partnerId=$partnerId&partnerKey=$partnerKey&id=$stationId&title=".$title_tunein."&artist=".$artist_tunein."&commercial=$commercial";
    
$response file_get_contents($url);
    echo 
$response;

    
// file_put_contents('last_response.txt', date('[Y-m-d H:i:s]')."\n".$response); // for debugging

// for Radioline XML : for further informations, consult http://cms.radioline.co/XML-file-structure-specifications-for-Music-track-metadata-and-Electronic-Program-Guide-_EPG_.pdf
$xw = new xmlWriter;
$xw->openMemory();
$xw->setIndent(true);
$xw->setIndentString("\t");

$xw->startDocument('1.0''utf-8');
$xw->startElement('rol_notification');
$xw->writeElement('name',$stationName);
$xw->writeElement('timeZone',$timezone);
$xw->writeElement('url',$stationurl);
$xw->startElement('onair');
$xw->writeElement('start',$start);
$xw->writeElement('duration',$durations);
$xw->writeElement('title',$title);
$xw->writeElement('artist',$artist);
$music_type = ($track_type === 0) ? 'S' 'A'// S for Music, A for Advertisement
$xw->writeElement('music',$music_type);
// End onair element
$xw->endElement();
// End rol_notification element
$xw->endElement();
file_put_contents('radioline.xml'$xw->outputMemory(true));

} else {
    echo 
"Access Denied";
}
?>

I changed the variables name "artist" and "title" for tune in, due to urlencode function.
RadioDJ User since 2011
CEO CETA Radio
Synology ds209: SQL & Music Data w VPN access

AndyDeGroo

  • Guest
Re: TuneIn API Integration
« Reply #61 on: December 18, 2014, 06:40:00 PM »
Hi Laurent,

Great to see someone contributing to this script.
However, I'm not familiar with radioline and have a question: What do you do with the generated xml file? Is it fetched by them or do you submit it to their service?

laurent-CETARadio

  • New User

  • Offline
  • *
  • 26
    • CETA Radio
Re: TuneIn API Integration
« Reply #62 on: December 18, 2014, 07:00:43 PM »
Good Evening Andy
You have to create an account to cms.radioline.co. You can refer your radio station, podcast...
once it's done, you submit the xml to editorial@radioline.co (from my memory)
all the specs are in this pdf: http://cms.radioline.co/XML-file-structure-specifications-for-Music-track-metadata-and-Electronic-Program-Guide-_EPG_.pdf

Cheers!
RadioDJ User since 2011
CEO CETA Radio
Synology ds209: SQL & Music Data w VPN access

001FM

  • New User

  • Offline
  • *
  • 3
Re: TuneIn API Integration
« Reply #63 on: January 04, 2015, 12:37:56 PM »
Hello,

thanks to laurent-CETARadio and AndyDeGroo for the scripts!

I'm using the script above and i'm facing a problem. I have two radio stations. First one is working fine, but my second one has a partnerID and a partnerKey with special characters. I'm getting a 403 error page everytime in the last_response.txt.
My first station has no special characters in it and its working perfect!

My partnerID is looking like this: Xx*1xXXX
PartnerKey looking like this: _$X1x11x1xX_

It seems that the script has problems with the special characters. Can anyone help me to get it working? When i'm using the normal mode (like Marius said) it works.

Thanks!

001FM

  • New User

  • Offline
  • *
  • 3
Re: TuneIn API Integration
« Reply #64 on: January 06, 2015, 01:09:35 AM »
No one there, that could help me?  :o :(

joshuatree44

  • Guest
Re: TuneIn API Integration
« Reply #65 on: January 15, 2015, 05:09:40 AM »
I am trying to follow what is going on here, but I am completely lost. I am looking over the tunin.com page and I have to email their support, but I have no idea what to email them. I wish they had something setup for radiodj on that page too. I mean this is very confusing. I also have copied the above php and placed it into a new page on wordpress site. However how does the radiodj stuff get to my site from the server here? I wish there was a simple setup per say on this.

Chaos Radio!

  • Full Member

  • Offline
  • ***
  • 152
Re: TuneIn API Integration
« Reply #66 on: January 15, 2015, 03:37:50 PM »
I am trying to follow what is going on here, but I am completely lost. I am looking over the tunin.com page and I have to email their support, but I have no idea what to email them. I wish they had something setup for radiodj on that page too. I mean this is very confusing. I also have copied the above php and placed it into a new page on wordpress site. However how does the radiodj stuff get to my site from the server here? I wish there was a simple setup per say on this.

Hopefully this might help?
If you are already set up to broadcast on Tunein, you need to email them and ask for your stations API which will be the  Partner ID STATION ID and KEY you will need to send info to Tunein.

Make sure in your email to give them your station ID. which should be on the top of the page your station has at Tunein.

Once you have received the info from Tunein then follow the post and instructions from Marius below.

Open Now Playing info (plugin) and in Web Export tab enter this:

On URL:
http://air.radiotime.com/Playing.ashx

On Custom Data:
partnerId=<id>&partnerKey=<key>&id=<stationid>&title=$title$&artist=$artist$

Make sure that you replace the <id> <key> and <stationid> with your data.

Bottom of form:
Set method to GET and check the Enable check-box.

Should be all set, your streamed content will show up on tunein.
Chaos Radio! - True Punk Radio for True Punk Rockers!
Over 100,000 songs in the music vault from all over the globe! Proud RadioDJ user since 2014.

https://chaosradio.info

joshuatree44

  • Guest
Re: TuneIn API Integration
« Reply #67 on: January 19, 2015, 07:13:20 PM »
Thank you for your help. I am going to email them now. I am just confused on what the heck all that stuff is and what to do and the like. I mean it just sounds all Greek to me. Now how will I display this stuff on my website or is that not what this is for? Also, I am wondering about the sam-song.info stuff as well. Is there a way to have that going as well????

yatusabes

  • New User

  • Offline
  • *
  • 33
Re: TuneIn API Integration
« Reply #68 on: January 21, 2015, 04:31:02 PM »
I got my Partner ID STATION ID and KEY from TuneIn. I write the information in the Web Export like Marius says.

RadioDJ starts sending the info to TuneIn. But not only sends the name of the songs, it sends too the name of commercials, promos, news bulletin, etc...

Is there any way that RadioDj only sends the song's information?

joshuatree44

  • Guest
Re: TuneIn API Integration
« Reply #69 on: January 21, 2015, 08:36:27 PM »
I think your stuck with it all going to there. It is not a big deal to be honest. i would however like to send it to tunein but also like I had it to twitter and the like. I am wondering how I will use sam-song.info when I have the stuff going to tunein. Would I have to copy and create a second instance of the playing info plugin?

joshuatree44

  • Guest
Re: TuneIn API Integration
« Reply #70 on: January 23, 2015, 01:01:42 AM »
How long does TuneIn take to send you the items? I have been waiting over a month or so. They must be really hard to get or something.

Chaos Radio!

  • Full Member

  • Offline
  • ***
  • 152
Re: TuneIn API Integration
« Reply #71 on: January 23, 2015, 04:12:05 AM »
How long does TuneIn take to send you the items? I have been waiting over a month or so. They must be really hard to get or something.

Ha....the fun game of TuneIn support. they have two yes two people handling support as far as I can tell.

The best thing to do is keep emailing them daily.
Chaos Radio! - True Punk Radio for True Punk Rockers!
Over 100,000 songs in the music vault from all over the globe! Proud RadioDJ user since 2014.

https://chaosradio.info

joshuatree44

  • Guest
Re: TuneIn API Integration
« Reply #72 on: January 29, 2015, 10:31:23 PM »
got my digits today. I noticed that if you email the broadcast-support@tunein.com it gets faster to them than normal support email. I am loving the stuff displaying. Now I have to try and get the sam-song.info working prob with a copy of the plugin? update, nope it does not work with a copy. That stinks. It is either one or the other. Bummer. Also, I noticed that TuneIn.com API does not show cover art for everything. Which is odd. But for the most part it does what I want it to do. It seems like it gets confused.

joshuatree44

  • Guest
Re: TuneIn API Integration
« Reply #73 on: February 05, 2015, 06:33:29 AM »
This setup does not work 100% with TuneIn. I am not sure what I have wrong but it is only working 25% of the time.

Nitrofish

  • Jr. Member

  • Offline
  • **
  • 92
    • Rock 101 KLOL
Re: TuneIn API Integration
« Reply #74 on: February 14, 2015, 03:17:07 AM »
I think your stuck with it all going to there. It is not a big deal to be honest. i would however like to send it to tunein but also like I had it to twitter and the like. I am wondering how I will use sam-song.info when I have the stuff going to tunein. Would I have to copy and create a second instance of the playing info plugin?

I see that others are using PHP to send only songs. Is there a way to do it without using PHP? It seems that when my sweepers play, it messes up TuneIn's ability to display the correct info. SAM uses this PAL script and it works flawlessly:

Code: [Select]
{
Script to submit song info to the TuneIn AIR API (http://tunein.com/broadcasters/api/).
The stationId, partnerId and partnerKey values need to be set for this to work.
}

const STATION_ID = 'XXX990';
const PARTNER_ID = 'XXXXXXnt';
const PARTNER_KEY = 'XXXXXXXXxSKq';

var player : TPlayer;
var song : TSongInfo;
var baseUrl: String;

FUNCTION urlEncode(s: String): String; forward;
PROCEDURE update(stationId, partnerId, partnerKey, artist, title : String); forward;

{Main}
PAL.Loop := true;

PAL.WaitForPlayCount(1);
player := ActivePlayer;
IF ( player <> NIL ) THEN
BEGIN
IF ( player.Duration > 45000 ) THEN
BEGIN
song := player.GetSongInfo;
IF ( song <> NIL ) THEN
BEGIN
update(STATION_ID, PARTNER_ID, PARTNER_KEY, song['artist'],song['title']);
song.Free;
END;
END;
END;

FUNCTION urlEncode(s: String): String;
BEGIN
var index : integer;
var intVal : integer;
result := '';

PAL.LockExecution;

IF (Length(s)) > 0 THEN
BEGIN
FOR index := 1 TO length(s) DO
BEGIN
intVal := Ord(s[index]);
IF ((intVal > 47) AND (intVal < 58)) OR ((intVal > 64) AND (intVal < 91)) OR ((intVal > 96) AND (intVal < 123))  THEN
BEGIN
result := result + (s[index])
END
ELSE
BEGIN
IF ( intVal < 128 ) THEN
BEGIN
result := result + '%' + IntToHex(intVal, 2);
END
ELSE IF ( intVal < 2048 ) THEN
BEGIN
result := result + '%' + IntToHex( $C0 or Trunc( intVal / 64 ), 2 ) + '%' + IntToHex( $BF and intVal, 2 );
END
ELSE
BEGIN
// not yet supported
END;
END;
END;
END;
PAL.UnlockExecution;
END;

PROCEDURE update(stationId, partnerId, partnerKey, artist, title : String);
BEGIN
var req : String;
req := 'http://air.radiotime.com/Playing.ashx?id=' + stationId
+ '&partnerId=' + urlEncode(partnerId)
+ '&partnerKey=' + urlEncode(partnerKey)
+ '&title=' + urlEncode(title)
+ '&artist=' + urlEncode(artist);

WebToStr(req);
END;

I too am using a Twitter script (sam-song.info) on SAM that sends artist, song title to Twitter. Is anyone working on a plugin for RDJ that can post to Artist and Song Title to Twitter, and/or Facebook?
RadioDJ v2.0.0.6
MySQL v8.0.12

Follow us on Twitter: @Rock101KLOL
Facebook: facebook.com/Rock101KLOL