show mediatomb server contents in internetradio
authorChristian Weiske <cweiske@cweiske.de>
Tue, 24 Nov 2015 23:54:02 +0000 (00:54 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 24 Nov 2015 23:54:02 +0000 (00:54 +0100)
.gitignore
data/config.php.dist [new file with mode: 0644]
src/mediatomb.php [new file with mode: 0644]
src/podcasts.php
www/index.php

index ba7508806f11e856106ee63758eb32a2967c8320..b0e72d9d31566912ca942ece608870e5cbd79964 100644 (file)
@@ -2,3 +2,4 @@
 /var/mynoxon/*
 /var/podcasts/*
 /README.html
 /var/mynoxon/*
 /var/podcasts/*
 /README.html
+/data/config.php
diff --git a/data/config.php.dist b/data/config.php.dist
new file mode 100644 (file)
index 0000000..42936be
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+//$host1 = 'http://example.org/';
+//$host2 = 'http://example.org/';
+$mediatomb = array(
+    'user' => 'fixme',
+    'pass' => 'fixme',
+    'host' => 'fixme',
+    'port' => '49152'
+);
+?>
diff --git a/src/mediatomb.php b/src/mediatomb.php
new file mode 100644 (file)
index 0000000..16b0ced
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+require_once 'Services/MediaTomb.php';
+
+function handleRequestMediatomb($fullPath, $prefix)
+{
+    global $mediatomb;
+
+    extract($mediatomb);
+    $smt = new Services_MediaTomb($user, $pass, $host, $port);
+
+    $path = substr($fullPath, strlen($prefix));
+    $container = $smt->getContainerByPath($path);
+    $listItems = array();
+    addPreviousItem($listItems, $fullPath);
+
+    foreach ($container->getContainers() as $subContainer) {
+        $listItems[] = getDirItem(
+            $subContainer->title,
+            $fullPath . $subContainer->title . '/'
+        );
+    }
+
+    foreach ($container->getItemIterator(false) as $item) {
+        $listItems[] = getEpisodeItem(
+            $item->title,
+            $item->url,
+            '',
+            'MP3'
+        );
+    }
+
+    sendListItems($listItems);
+}
+?>
index 1756ed5ad426c501568ba5f60cf90859c3017343..68d133ce057f4dd34e581b39b852689bc7d7978d 100644 (file)
@@ -28,13 +28,12 @@ function sendPodcast($path)
         $desc = (string) $item->description;
         $url = $item->enclosure['url'];
 
         $desc = (string) $item->description;
         $url = $item->enclosure['url'];
 
-        $listItems[] = '<Item>'
-            . '<ItemType>ShowEpisode</ItemType>'
-            . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
-            . '<ShowEpisodeURL>' . $host1 . 'play-url?url=' . urlencode($url) . '</ShowEpisodeURL>'
-            . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
-            . '<ShowMime>MP3</ShowMime>' 
-            . '</Item>';
+        $listItems[] = getEpisodeItem(
+            $title,
+            $host1 . 'play-url?url=' . urlencode($url),
+            $desc,
+            'MP3'
+        );
     }
     sendListItems($listItems);
 }
     }
     sendListItems($listItems);
 }
index 3f06722943073ca3ad8f69ece56abb44ecc81708..4db5f2ef36658b7268671ed2188012f66a7fc137 100644 (file)
@@ -14,6 +14,10 @@ if ($_SERVER['HTTP_HOST'] !== '') {
     $host1 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
     $host2 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
 }
     $host1 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
     $host2 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
 }
+$cfgFile = $dataDir . 'config.php';
+if (file_exists($cfgFile)) {
+    include $cfgFile;
+}
 
 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0') {
     //initial login for "internet radio" and podcasts
 
 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0') {
     //initial login for "internet radio" and podcasts
@@ -29,17 +33,19 @@ if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token
     exit();
 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') {
     //"Internet Radio"
     exit();
 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') {
     //"Internet Radio"
-    $path = '/internetradio';
+    $path = '/internetradio/';
 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/navXML.asp') {
     //"Podcasts"
 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/navXML.asp') {
     //"Podcasts"
-    $path = '/podcasts';
+    $path = '/podcasts/';
 } else if ($path == '/RadioNative.php') {
     //"My Noxon"
 } else if ($path == '/RadioNative.php') {
     //"My Noxon"
-    $path = '/mynoxon';
+    $path = '/mynoxon/';
 } else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
     //Internet Radio Station favorites favorited on device
 } else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
     //Internet Radio Station favorites favorited on device
+    sendMessage('Unsupported');
 } else if ($path == '/RadioNativeFavorites.php') {
     //Favorites, defined via web interface
 } else if ($path == '/RadioNativeFavorites.php') {
     //Favorites, defined via web interface
+    sendMessage('Unsupported');
 } else if (substr($path, 0, 9) == '/play-url') {
     //play a given URL, but first follow all redirects
     //noxon iRadio Cube does not like too many redirections
 } else if (substr($path, 0, 9) == '/play-url') {
     //play a given URL, but first follow all redirects
     //noxon iRadio Cube does not like too many redirections
@@ -60,6 +66,13 @@ function handleRequest($path)
         return;
     }
 
         return;
     }
 
+    if (substr($path, 0, 14) == 'internetradio/') {
+        require_once 'mediatomb.php';
+        handleRequestMediatomb($path, 'internetradio/');
+        return;
+    }
+
+
     $fullPath = $varDir . $path;
     if (!file_exists($fullPath)) {
         sendMessage('Not found: ' . $path);
     $fullPath = $varDir . $path;
     if (!file_exists($fullPath)) {
         sendMessage('Not found: ' . $path);
@@ -140,6 +153,17 @@ function getDirItem($title, $urlPath)
         . '</Item>';
 }
 
         . '</Item>';
 }
 
+function getEpisodeItem($title, $fullUrl, $desc, $type)
+{
+    return '<Item>'
+        . '<ItemType>ShowEpisode</ItemType>'
+        . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
+        . '<ShowEpisodeURL>' . $fullUrl . '</ShowEpisodeURL>'
+        . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
+        . '<ShowMime>' . $type . '</ShowMime>'
+        . '</Item>';
+}
+
 function getPodcastItem($title, $urlPath)
 {
     global $host1;
 function getPodcastItem($title, $urlPath)
 {
     global $host1;