From: Christian Weiske Date: Wed, 25 Nov 2015 06:36:08 +0000 (+0100) Subject: catch Mediatomb exceptions, encode urls correctly X-Git-Tag: v0.1.0~8 X-Git-Url: https://git.cweiske.de/noxon-gateway.git/commitdiff_plain/206c96dc4ba589fc9eab103f09968bdca2c4b10f catch Mediatomb exceptions, encode urls correctly --- diff --git a/src/mediatomb.php b/src/mediatomb.php index 40861ae..74b7f84 100644 --- a/src/mediatomb.php +++ b/src/mediatomb.php @@ -6,27 +6,38 @@ function handleRequestMediatomb($fullPath, $prefix) 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); diff --git a/www/index.php b/www/index.php index 4db5f2e..b742632 100644 --- a/www/index.php +++ b/www/index.php @@ -40,6 +40,7 @@ if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token } 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'); @@ -91,6 +92,11 @@ function handleRequest($path) } } +function pathEncode($urlPath) +{ + return str_replace('%2F', '/', rawurlencode($urlPath)); +} + function sendDir($path) { global $varDir; @@ -101,7 +107,7 @@ function sendDir($path) $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 . '/'); @@ -129,16 +135,20 @@ function sendTextFile($path) $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 '' . 'Display' - . '' . utf8_decode(htmlspecialchars(trim($line))) . '' + . '' . utf8_decode(htmlspecialchars($line)) . '' . ''; }