New Request Script for anyone who wants it.

dblevins

Member
I have created an alternative request script for anyone who wants to make use of it. This one makes use of just one box to search for Artist or Song Title. It will also check the file name if a file has not been tagged properly. It then returns a drop down box, whereby if a song has been covered by several artists, the user can select the version they want to hear. I have omitted the message box from the search as my radio is almost 100% automated and I don't want un-moderated messages appearing on the site. I'm sure someone can amend the script to include it if they need it.

<?php
// Config variables
$rb_server = 'Your RadioBOSS server address'; // Your RadioBOSS server address
$rb_port = '9000'; // RadioBOSS port (9000 is the default one
$rb_password = 'Your password'; // API password
$rb_library = 'Music'; // Music library file (without .xml). Your Music Library name

// API base URL
$rb_api = "http://$rb_server:$rb_port?pass=$rb_password";

// HTTP get function
function HTTPGet($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}

// Function to process the song request
function result($msg) {
echo "$msg <a href='javascript:history.back();'>Back</a>";
exit;
}

// Handling the search and request process
$type = isset($_POST['type']) ? $_POST['type'] : '';
if ($type === '') {
echo '<form method="post">
<input type="hidden" name="type" value="search">
<label>Search by Artist or Title:</label>
<input type="text" name="search" placeholder="Artist or Title">
<button type="submit">Search</button>
</form>';
} elseif ($type === 'search') {
$search = mb_strtolower(trim($_POST['search']));
if ($search === '') {
result('No search term entered.');
}

// Load library data from RadioBOSS API
$library_raw = HTTPGet("$rb_api&action=library&filename=" . urlencode($rb_library));
if ($library_raw === false) {
result('Song request failed: unable to load music library.');
}

// Parse the XML data
//$xml = simplexml_load_string($library_raw);

// Use LIBXML_PARSEHUGE to bypass restrictions
// This allows parsing huge XML files but requires PHP 5.3+.
$xml = simplexml_load_string($library_raw, "SimpleXMLElement", LIBXML_PARSEHUGE);
if ($xml === false) {
result('Song request failed: unable to parse music library XML data.');
}

// Search for matching artist or title
$matches = [];
foreach ($xml->Track as $track) {
$artist = mb_strtolower((string)$track['artist']);
$title = mb_strtolower((string)$track['title']);
if (strpos($artist, $search) !== false || strpos($title, $search) !== false) {
$matches[] = [
'artist' => (string)$track['artist'],
'title' => (string)$track['title'],
'filename' => (string)$track['filename']
];
}
}

if (count($matches) > 0) {
echo '<form method="post">
<input type="hidden" name="type" value="request">
<label>Choose a song:</label>
<select name="song">';
foreach ($matches as $match) {
echo '<option value="' . $match['filename'] . '">' . $match['artist'] . ' - ' . $match['title'] . '</option>';
}
echo '</select><br><button type="submit">Request this song</button></form>';
} else {
result('No matches found for your search.');
}
} elseif ($type === 'request') {
// Handle song request
$filename = $_POST['song'];
$msg = isset($_POST['message']) ? $_POST['message'] : '';

// Send song request to RadioBOSS API
$res = HTTPGet("$rb_api&action=songrequest&filename=" . urlencode($filename) . '&message=' . urlencode($msg));
if ($res === 'OK') {
result('Song requested successfully!');
} else {
result('An error occurred while adding song request.');
}
}


?>
 
PS, If anyone can improve this to avoid abuse I would appreciate it.

Suggestions to limit the number of times a user can request.
For example two requests per hour maximum
And for the request to respect the no repeat rules.
 
Very nice, but a test port would be nice.

I dont know if this would work as it doesnt open my stream because of cross-network changes to the internet. I also found readying the FTP XML export upload gave me images too any ideas on that also $rb_server = 'Your RadioBOSS server address'; what is this ?
 
Last edited:
i used to have cross platform . But this no longer functions
<?php

if (!function_exists(__NAMESPACE__ . '\checkRemoteServerStatus'))
{
function checkRemoteServerStatus($streamingUrl,$interval,$offset = 0)
{
$ua = 'Mozilla/5.0 (X11 Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36';
$opts = array('http'=>array('method'=>'GET','header'=>'Icy-MetaData: 1','user_agent'=>$ua ));
if (1/*&&file_exists($streamingUrl)*/)
{
$context = stream_context_create($opts);
if ($stream = fopen($streamingUrl, 'r', false, $context)) {
$buffer = stream_get_contents($stream, $interval, $offset);
//echo $buffer;
if(strpos($buffer,"Server is currently up and public.") != false) {
return true;
} else {
if(strpos($buffer,"Server is currently down") == false) {
return -1;
} else {
return false;
echo "server is down";
}
}
fclose($stream);
return true;
}
} else {
echo "No URL specified.";
return false;
}
}

} else {
//echo "incorect URL";
return false;
}
//echo checkRemoteServerStatus('http://74.91.126.144:27274/',19200,0);
?>
 
mine is failing here
// Load library data from RadioBOSS API
$library_raw = HTTPGet("$rb_api&action=library&filename=" . urlencode($rb_library));
if ($library_raw === false) {
result('Song request failed: unable to load music library.');

I have my internet ip in $rb_server and my data service as in music catalogue title
 
Yep, I think it might not be getting into the network. I am not sure how to get an API address either from RB.
 
Very nice, but a test port would be nice.

I dont know if this would work as it doesnt open my stream because of cross-network changes to the internet. I also found readying the FTP XML export upload gave me images too any ideas on that also $rb_server = 'Your RadioBOSS server address'; what is this ?
Not sure what you mean by a test port
 
mine is failing here
// Load library data from RadioBOSS API
$library_raw = HTTPGet("$rb_api&action=library&filename=" . urlencode($rb_library));
if ($library_raw === false) {
result('Song request failed: unable to load music library.');

I have my internet ip in $rb_server and my data service as in music catalogue title
Have you forwarded port 9000 in your router
 
Very nice, but a test port would be nice.

I dont know if this would work as it doesnt open my stream because of cross-network changes to the internet. I also found readying the FTP XML export upload gave me images too any ideas on that also $rb_server = 'Your RadioBOSS server address'; what is this ?
It's the address where your Radio Boss is playing from. You will need a static ip address and also need to forward port 9000 to the computer.
 
Very nice, but a test port would be nice.

I dont know if this would work as it doesnt open my stream because of cross-network changes to the internet. I also found readying the FTP XML export upload gave me images too any ideas on that also $rb_server = 'Your RadioBOSS server address'; what is this ?
It is the ip address where radio boss is located. It needs to be static and you also need to forward port 9000 from you router
 
It's the address where your Radio Boss is playing from. You will need a static ip address and also need to forward port 9000 to the computer.
Yes, I have static IP. OK, 9000 needs port forwarding. I will try that. I also noted this doesn't work if RB is not running. The reason this was of interest is that other data could be obtained from RB in this way.do you forward from your internet static IP to your computer IP on that port? Is that not risky?
 
Yes, I have static IP. OK, 9000 needs port forwarding. I will try that. I also noted this doesn't work if RB is not running. The reason this was of interest is that other data could be obtained from RB in this way.do you forward from your internet static IP to your computer IP on that port? Is that not risky?
With a strong password for your API security should not be an issue, but I am no expert. Best confirm that with someone who knows more than me about internet security. In truth, I once had my database stolen with this using different software, but in those days I was using very weak passwords. It has never been an issue with a strong password. RB needs to be running otherwise there is nothing to accept the request, so it would not work.
 
Back
Top