This script connects to the foo_controlserver telnet server and gets the data.
It's only proof-of-concept, but it puts the data in arrays so it should be more easy to parse.
Thanks to the format of the output ("|" separating fields) it is easy parseable.
The only trouble I have is the persistent connection natures of the server. Once you connect you don't know when to terminate. Currently I solved this by stopping reading data after I get the first 111 block (trackinfo).
You will be most likely using this script on a website and then you don't want to stay connected anyway.
You can optionally send commands using fwrite() to get more data.
<?php
/*
FooBar2000 Now playing script.
Requires foo_controlserver
*/
$host="some server";
$port=666;
$fs = fsockopen($host, $port, $errno, $errstr, 10);
$debug = '';
while (!feof($fs)) {
// Read up until we hit a \n
fscanf($fs, '%[ -~]\n', $line);
$data = preg_split('/\|/', $line);
$debug .= print_r($data, true);
if ( preg_match('/^111|112|113$/', $data[0]) ) break;
}
fclose($fs);
echo $debug;
?>
The code above contains flaws obviously. But I have created a complete script which will list current song together with control buttons and it requires authentication in order to be used.
Just take a look