global $mediatomb;
extract($mediatomb);
- $smt = new Services_MediaTomb($user, $pass, $host, $port);
+ try {
+ $smt = new Services_MediaTomb($user, $pass, $host, $port);
- $path = substr(urldecode($fullPath), strlen($prefix));
- $container = $smt->getContainerByPath($path);
- $listItems = array();
- addPreviousItem($listItems, $fullPath);
+ $path = substr(urldecode($fullPath), strlen($prefix));
+ $container = $smt->getContainerByPath($path);
+ $listItems = array();
+ addPreviousItem($listItems, $fullPath);
- foreach ($container->getContainers() as $subContainer) {
- $listItems[] = getDirItem(
- $subContainer->title,
- $fullPath . urlencode($subContainer->title) . '/'
- );
- }
+ foreach ($container->getContainers() as $subContainer) {
+ $listItems[] = getDirItem(
+ $subContainer->title,
+ $fullPath . rawurlencode($subContainer->title) . '/'
+ );
+ }
- foreach ($container->getItemIterator(false) as $item) {
- $listItems[] = getEpisodeItem(
- $item->title,
- $item->url,
- '',
- 'MP3'
- );
+ foreach ($container->getItemIterator(false) as $item) {
+ $di = $item->getDetailedItem();
+ if ($di->mimetype !== 'audio/mpeg') {
+ //noxon iRadio cube does not want to play .ogg files
+ //FIXME: convert to mp3
+ //$di->location (on the server)
+ }
+ $listItems[] = getEpisodeItem(
+ $item->title,
+ $item->url,
+ '',
+ 'MP3'
+ );
+ }
+ } catch (Exception $e) {
+ sendMessage('Mediatomb error: ' . $e->getMessage());
+ return;
}
sendListItems($listItems);
} else if ($path == '/RadioNative.php') {
//"My Noxon"
$path = '/mynoxon/';
+ $path = '/internetradio/';
} else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
//Internet Radio Station favorites favorited on device
sendMessage('Unsupported');
}
}
+function pathEncode($urlPath)
+{
+ return str_replace('%2F', '/', rawurlencode($urlPath));
+}
+
function sendDir($path)
{
global $varDir;
$entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
$count = 0;
foreach ($entries as $entry) {
- $urlPath = substr($entry, strlen($varDir));
+ $urlPath = pathEncode(substr($entry, strlen($varDir)));
if (is_dir($entry)) {
++$count;
$listItems[] = getDirItem(basename($entry), $urlPath . '/');
$lines = file($varDir . $path);
foreach ($lines as $line) {
- $listItems[] = getDisplayItem($line);
+ $line = trim($line);
+ if ($line != '') {
+ $listItems[] = getDisplayItem($line);
+ }
}
sendListItems($listItems);
}
function getDisplayItem($line)
{
+ $line = preg_replace('#\s+#', ' ', $line);
return '<Item>'
. '<ItemType>Display</ItemType>'
- . '<Display>' . utf8_decode(htmlspecialchars(trim($line))) . '</Display>'
+ . '<Display>' . utf8_decode(htmlspecialchars($line)) . '</Display>'
. '</Item>';
}