Use advanced transcoding that streams while transcoding
[noxon-gateway.git] / src / mediatomb.php
index 40861ae4bda2b348090ebb116030212c48ab6c60..e582a46764cd875956b6a12ec66105b5367446b6 100644 (file)
@@ -3,30 +3,42 @@ require_once 'Services/MediaTomb.php';
 
 function handleRequestMediatomb($fullPath, $prefix)
 {
-    global $mediatomb;
+    global $mediatomb, $host1;
 
     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($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,
+                pathEncode($fullPath . $subContainer->title) . '/'
+            );
+        }
 
-    foreach ($container->getItemIterator(false) as $item) {
-        $listItems[] = getEpisodeItem(
-            $item->title,
-            $item->url,
-            '',
-            'MP3'
-        );
+        foreach ($container->getItemIterator(false) as $item) {
+            $di = $item->getDetailedItem();
+            $itemUrl = $item->url;
+            if ($di->mimetype !== 'audio/mpeg') {
+                //noxon iRadio cube does not want to play .ogg files
+                $itemUrl = $host1 . 'transcode-nocache.php'
+                    . '?url=' . urlencode($itemUrl);
+            }
+            $listItems[] = getEpisodeItem(
+                $item->title,
+                $itemUrl,
+                '',
+                'MP3'
+            );
+        }
+    } catch (Exception $e) {
+        sendMessage('Mediatomb error: ' . $e->getMessage());
+        return;
     }
 
     sendListItems($listItems);