From 2f2cf57a7f06584751fc14f28c879996fa870fad Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 25 Nov 2015 23:58:47 +0100 Subject: [PATCH] move redirect resolving to separate script --- src/podcasts.php | 2 +- www/deredirect.php | 24 ++++++++++++++++++++++++ www/index.php | 21 --------------------- 3 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 www/deredirect.php diff --git a/src/podcasts.php b/src/podcasts.php index 68d133c..3acccbb 100644 --- a/src/podcasts.php +++ b/src/podcasts.php @@ -30,7 +30,7 @@ function sendPodcast($path) $listItems[] = getEpisodeItem( $title, - $host1 . 'play-url?url=' . urlencode($url), + $host1 . 'deredirect.php?url=' . urlencode($url), $desc, 'MP3' ); diff --git a/www/deredirect.php b/www/deredirect.php new file mode 100644 index 0000000..5b90e1d --- /dev/null +++ b/www/deredirect.php @@ -0,0 +1,24 @@ + 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; +} +?> \ No newline at end of file diff --git a/www/index.php b/www/index.php index 8b803db..d64436c 100644 --- a/www/index.php +++ b/www/index.php @@ -41,14 +41,6 @@ if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token } 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 - // 3 redirects did not work. - $url = $_GET['url']; - header('HTTP/1.0 301 Moved Permanently'); - header('Location: ' . getFinalUrl($url)); - exit(); } handleRequest(ltrim($path, '/')); @@ -244,19 +236,6 @@ function addPreviousItem(&$listItems, $urlPath) $listItems[] = getPreviousItem($parentDir); } -function getFinalUrl($url) -{ - $ctx = stream_context_set_default( - array('http' => 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 sendMessage($msg) { sendListItems(array(getMessageItem($msg))); -- 2.30.2