From: Christian Weiske Date: Thu, 12 Nov 2015 00:11:03 +0000 (+0100) Subject: podcasts work X-Git-Tag: v0.1.0~15 X-Git-Url: https://git.cweiske.de/noxon-gateway.git/commitdiff_plain/931d5803649e32b043d7af9034dde326ddb1fefa podcasts work --- 931d5803649e32b043d7af9034dde326ddb1fefa diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0c3275 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/var/podcasts/* diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..42e09fa --- /dev/null +++ b/README.rst @@ -0,0 +1,30 @@ +******************** +Noxon iRadio gateway +******************** +Push your own content onto Noxon iRadio devices. + +This tool makes it possible to push own data into the menu +entries +- Internet Radio +- Podcasts +- My Noxon + + +================ +Adding a podcast +================ +Create a file "Title.url" in ``var/podcasts/`` and write +the URL of the podcast MP3 RSS feed into it. + +===== +Setup +===== + +Hosts +===== +The following hosts must point to your server and be handled +by this tool:: + + radio567.vtuner.com + radio5672.vtuner.com + gatekeeper.my-noxon.net diff --git a/data/initial-login.xml b/data/initial-login.xml new file mode 100644 index 0000000..2206537 --- /dev/null +++ b/data/initial-login.xml @@ -0,0 +1 @@ +a6703ded78821be5 diff --git a/data/list-test.xml b/data/list-test.xml new file mode 100644 index 0000000..af308cd --- /dev/null +++ b/data/list-test.xml @@ -0,0 +1,10 @@ + + + -1 + + Dir + Hallo! + http://radio567.vtuner.com/test + http://radio5672.vtuner.com/test + + diff --git a/data/login-mynoxon.xml b/data/login-mynoxon.xml new file mode 100644 index 0000000..e88d339 --- /dev/null +++ b/data/login-mynoxon.xml @@ -0,0 +1 @@ +a6703ded78821be5 diff --git a/src/podcasts.php b/src/podcasts.php new file mode 100644 index 0000000..9948af4 --- /dev/null +++ b/src/podcasts.php @@ -0,0 +1,88 @@ +' + . 'ShowOnDemand' + . '' . htmlspecialchars($title) . '' + . 'http://radio567.vtuner.com/podcasts/' . urlencode(basename($file)) . '' + . ''; + } + sendListItems($listItems); +} + +function sendPodcast($file) +{ + //strip /podcasts/ + $file = substr(urldecode($file), 10); + if (strpos($file, '..') !== false) { + sendMessage('No'); + return; + } + + $path = __DIR__ . '/../var/podcasts/' . $file; + if (!file_exists($path)) { + return sendMessage('File does not exist: ' . $file); + } + + $url = trim(file_get_contents($path)); + + $cacheFile = '/tmp/podcast-' . md5($file) . '.xml'; + downloadIfNewer($url, $cacheFile); + + $sx = simplexml_load_file($cacheFile); + $listItems = array(); + foreach ($sx->channel->item as $item) { + $title = (string) $item->title; + $desc = (string) $item->description; + $url = $item->enclosure['url']; + + $listItems[] = '' + . 'ShowEpisode' + . '' . utf8_decode(htmlspecialchars($title)) . '' + . 'http://radio567.vtuner.com/play-url?url=' . urlencode($url) . '' + //. '' . htmlspecialchars($url) . '' + . '' . utf8_decode(htmlspecialchars($desc)) . '' + . 'MP3' + . ''; + } + sendListItems($listItems); +} + + +function downloadIfNewer($url, $file) +{ + $lastModified = 0; + if (file_exists($file)) { + $lastModified = filemtime($file); + } + + $ctx = stream_context_create( + array( + 'http' => array( + 'header' => 'If-Modified-Since: ' . date('r', $lastModified) + ) + ) + ); + $content = file_get_contents($url, false, $ctx); + //unfortunately, redirects require manual parsing of this array + for ($n = count($http_response_header) - 1; $n >= 0; --$n) { + if (substr($http_response_header[$n], 0, 5) == 'HTTP/') { + list(, $code) = explode(' ', $http_response_header[$n]); + break; + } + } + if ($code == 200) { + file_put_contents($file, $content); + } +} + +?> \ No newline at end of file diff --git a/var/podcasts/.keep b/var/podcasts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/www/.htaccess b/www/.htaccess new file mode 100644 index 0000000..4fb1fbe --- /dev/null +++ b/www/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On +RewriteBase / +RewriteRule ^.*$ index.php diff --git a/www/index.php b/www/index.php new file mode 100644 index 0000000..cc0be0e --- /dev/null +++ b/www/index.php @@ -0,0 +1,129 @@ + array('method' => 'HEAD')) + ); + //get_headers follows redirects automatically + $headers = get_headers($url, 1); + if ($headers !== false && isset($headers['Location'])) { + return end($headers['Location']); + } + return $url; +} + + +function sendList($path) +{ + $startitems = 1; + $enditems = 10; + if (isset($_GET['startitems'])) { + $startitems = (int) $_GET['startitems']; + } + if (isset($_GET['enditems'])) { + $enditems = (int) $_GET['enditems']; + } + + header('Content-type: text/xml'); + echo << + + -1 + + Message + $path + + + Dir + $path + http://radio567.vtuner.com/$path + http://radio5672.vtuner.com/$path + + + +XML; +} + +function sendMessage($msg) +{ + header('Content-type: text/xml'); + $xMsg = htmlspecialchars($msg); + echo << + + + Message + $xMsg + + + +XML; +} + +function sendListItems($listItems) +{ + $xml = '' . "\n"; + $xml .= '' . "\n"; + foreach ($listItems as $item) { + $xml .= $item . "\n"; + } + $xml .= "\n"; + + header('Content-type: text/xml'); + echo $xml; +} + +?>