Radionomy Board
It is currently Sun Nov 29, 2020 2:32 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Jan 20, 2014 1:46 pm 
Offline

Joined: Tue Sep 24, 2013 11:27 am
Posts: 46
Radio 1: http://www.radionomy.com/energyfmoldschoolclassics
Hi,
I've 'kind of' figured out an easy way to use PHP to parse the XML to display the current track. I say 'kind of' because it's not quite perfect; maybe someone with more PHP / XML knowledge may be able to clean it up. I've used the html comment tag <!--...--> to blank out the parts I don't want to be displayed but I can't get rid of the '1' (current) being displayed. Also I would like to display first 'Artists' then 'Title'.
Code:
<?php
//Initialize the XML parser
$parser=xml_parser_create();

//Function to use at the start of an element
function start($parser,$element_name,$element_attrs)
  {
  switch($element_name)
    {
    case "RADIONAME":
    echo '<!--';
    break;
    case "ARTISTS":
    echo " - ";
    break;
    case "TITLE":
    echo "-->";
    break;
    case "STARTTIME":
    echo '<!--';
    break;
    case "CURRENT":
    echo '-->';
    break;
    }
  }

//Function to use at the end of an element
function stop($parser,$element_name)
  {
  echo "";
  }

//Function to use when finding character data
function char($parser,$data)
  {
  echo $data;
  }

//Specify element handler
xml_set_element_handler($parser,"start","stop");

//Specify data handler
xml_set_character_data_handler($parser,"char");

//Open XML file
$fp=fopen("http://api.radionomy.com/currentsong.cfm?radiouid=YOURUID&apikey=YOURKEY&type=xml","r");

//Read data
while ($data=fread($fp,4096))
  {
  xml_parse($parser,$data,feof($fp)) or
  die (sprintf("XML Error: %s at line %d",
  xml_error_string(xml_get_error_code($parser)),
  xml_get_current_line_number($parser)));
  }

//Free the XML parser
xml_parser_free($parser);
?>

_________________
http://www.radionomy.com/energyfmoldschoolclassics


Top
 Profile Send private message  
 
PostPosted: Mon Aug 18, 2014 10:33 am 
Offline

Joined: Sat Aug 16, 2014 8:26 am
Posts: 8
Radio 1: http://www.radionomy.com/en/radio/monsterfmradio
This might be a little late but just drop
case "CURRENT":
echo '-->';
break;

As this is the "1" you are seeing in the nowplaying data.

Hope this helps.


Top
 Profile Send private message  
 
PostPosted: Mon Aug 18, 2014 10:35 am 
Offline

Joined: Sat Aug 16, 2014 8:26 am
Posts: 8
Radio 1: http://www.radionomy.com/en/radio/monsterfmradio
Remove case "CURRENT": echo '-->'; break; from the php to get rid of the "1"


Top
 Profile Send private message  
 
PostPosted: Sun Nov 16, 2014 9:37 pm 
Offline
User avatar

Joined: Mon Sep 16, 2013 4:47 pm
Posts: 152
Location: UK
Radio 1: http://listen.radionomy.com/wyldwood-radio
removing

case "CURRENT":
echo '-->';
break;"

won't work, it removes the --> necessary to make the comment tag work, this breaks any html on the page after this point.

_________________
Radio 1: http://listen.radionomy.com/wyldwood-radio
O.S: Windows 8.1


Top
 Profile Send private message  
 
PostPosted: Sun Nov 16, 2014 9:41 pm 
Offline
User avatar

Joined: Mon Sep 16, 2013 4:47 pm
Posts: 152
Location: UK
Radio 1: http://listen.radionomy.com/wyldwood-radio
Also this script does not auto refresh, the only way to see the current track after the track changes is to refresh the page.

_________________
Radio 1: http://listen.radionomy.com/wyldwood-radio
O.S: Windows 8.1


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group