?php /* RadioBOSS Song Request demo script To play the requested songs in RadioBOSS, schedule an event with "playrequestedsong" command: http://manual.djsoft.net/radioboss/en/scheduler_commands.htm#songrequest Please make sure the RadioBOSS API is enabled and a password is set: http://manual.djsoft.net/radioboss/en/remote_controlapi.htm If RadioBOSS is installed on a server, please make sure the API port (9000 by default) is allowed in firewall. Home or studio PC: If RadioBOSS is installed on a home or studio PC, please make sure it has a static IP address. If a static IP address is not available, a Dynamic DNS address has to be used instead The IP address (or dynamic DNS address) is entered into the $rb_server variable (please do not include http://) If a computer is behing a NAT (this is usually the case when a router is used), then API port (9000 by default) has to be forwarded in router settings - please see the port forwarding documentation for your router. */ //---------------// // CONFIGURATION // //---------------// //RadioBOSS API connection details $rb_server = '127.0.0.1'; //RadioBOSS hostname or IP $rb_port = '9000'; //RadioBOSS port $rb_password = '7bNR5UK'; //API password //music library name, omitting the .xml extension, the library is loaded from "Music library folder" as set in RadioBOSS settings $rb_library = 'music'; //show detailed error messages (1 - show error details, 0 - show only general error messages) //IMPORTANT! Make sure this is set to 0 once everything is configured and working to avoid revealing too many details to users! //Error messages may contain passwords and other sensitive information //Set this to 1 only if something's not working to get more details $show_errors = 0; //-------------------// // SONG REQUEST FORM // //-------------- ----// //API URL base $rb_api = "http://$rb_server:$rb_port?pass=$rb_password"; ?> RadioBOSS Song Request demo Back'; exit("$msg $back_link"); } $type = isset($_POST['type']) ? $_POST['type'] : ''; if ($type === '') { echo '
'; } elseif ($type === 'request') { //requested artist $artist = mb_strtolower(trim($_POST['artist'])); if ($artist === '') { $artist = false; } //requested title $title = mb_strtolower(trim($_POST['title'])); if ($title === '') { $title = false; } if (($artist === false) && ($title === false)) { result('No artist or title entered.'); } //load library $library_raw = HTTPGet("$rb_api&action=library&filename=" . urlencode($rb_library)); if ($library_raw === false) { $err = 'Song request failed: unable to load music library.'; if ($show_errors) { $err .= ' Error: ' . $last_err; } result($err); } //parse XML data $xml = simplexml_load_string($library_raw); if ($xml === false) { result('Song request failed: unable to parse music library XML data.'); } $fn = false; //search requested song in a music library foreach ($xml as $x) { if ($x->getName() !== 'Track') { continue; } $found = (($artist === false) || (mb_strtolower((string)$x['artist']) === $artist)) && (($title === false) || (mb_strtolower((string)$x['title']) === $title)); if ($found) { $fn = (string)$x['filename']; break; } } //song found, add to requested songs list in RadioBOSS if ($fn !== false) { $msg = isset($_POST['message']) ? $_POST['message'] : ''; $res = HTTPGet("$rb_api&action=songrequest&filename=" . urlencode($fn) . '&message=' . urlencode($msg)); if ($res === 'OK') { result('Song requested successfully!'); } else { $err = 'An error occurred while adding song request.'; if ($show_errors) { $err .= ' Error: ' . $last_err; } result($err); } } else { result('Requested song not found in the music library.'); } } ?>