Skip to content

Instantly share code, notes, and snippets.

Created September 19, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/be760318ac070d662063a0f0fcb6f974 to your computer and use it in GitHub Desktop.
Save anonymous/be760318ac070d662063a0f0fcb6f974 to your computer and use it in GitHub Desktop.
NexGen Now Playing PHP Sample Script
<?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