-
-
Save anthonyeden/a63a14ba66f1acaceeb4e61317974334 to your computer and use it in GitHub Desktop.
NexGen Now Playing PHP Sample Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//GET XML data from RCS NexGen | |
//?nexgendata=ENCODEDXML | |
// The raw XML data sent from NexGen | |
$xml_raw = $_GET['nexgendata']; | |
// A simple way to convert the XML to an associative array | |
$xml_nexgen = json_decode(json_encode((array)simplexml_load_string($xml_raw)), 1); | |
// This array will store all the data | |
$data = array(); | |
if(!empty($xml_nexgen['title']) && $xml_nexgen['title'] !== array()) { | |
$data['title'] = (String)$xml_nexgen['title']; | |
} | |
if(!empty($xml_nexgen['artist']) && $xml_nexgen['artist'] !== array()) { | |
$data['artist'] = (String)$xml_nexgen['artist']; | |
} | |
// The item number and cut number | |
$data['item_num'] = $xml_nexgen['number']; | |
$data['item_cut'] = $xml_nexgen['cut']; | |
// Duration is provided by NexGen as HH:MM:SS | |
$data['duration'] = (String)$xml_nexgen['length']; | |
// Timestamp is provided as MM/DD/YYYY | |
$data['date'] = (String)$xml_nexgen['played_date']; | |
$data['time'] = (String)$xml_nexgen['played_time']; | |
// Is the file is currently playing? | |
if($xml_nexgen['status'] == "Playing") { | |
$data['played'] = "true"; | |
} else { | |
$data['played'] = "false"; | |
} | |
// Write the data to a JSON file | |
file_put_contents("nexgen_now.xml", json_encode($data)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment