From: Christian Weiske Date: Wed, 23 Dec 2015 17:34:16 +0000 (+0100) Subject: filter out HLS streams X-Git-Tag: v1.0.0~11 X-Git-Url: https://git.cweiske.de/playVideoOnDreamboxProxy.git/commitdiff_plain/fdc12178d2d72fe33f5f360d5023e5bc2e256d53 filter out HLS streams --- diff --git a/www/play.php b/www/play.php index 0133f5b..314fee7 100644 --- a/www/play.php +++ b/www/play.php @@ -14,12 +14,20 @@ playVideoOnDreambox($videoUrl, $dreamboxHost); function getPageUrl() { - if (!isset($_SERVER['CONTENT_TYPE'])) { - errorInput('Content type header missing'); - } else if ($_SERVER['CONTENT_TYPE'] != 'text/plain') { - errorInput('Content type is not text/plain but ' . $_SERVER['CONTENT_TYPE']); + global $argv, $argc; + if (php_sapi_name() == 'cli') { + if ($argc < 2) { + errorInput('No URL given as command line parameter'); + } + $pageUrl = $argv[1]; + } else { + if (!isset($_SERVER['CONTENT_TYPE'])) { + errorInput('Content type header missing'); + } else if ($_SERVER['CONTENT_TYPE'] != 'text/plain') { + errorInput('Content type is not text/plain but ' . $_SERVER['CONTENT_TYPE']); + } + $pageUrl = file_get_contents('php://input'); } - $pageUrl = file_get_contents('php://input'); $parts = parse_url($pageUrl); if ($parts === false) { errorInput('Invalid URL in POST data'); @@ -35,7 +43,7 @@ function extractVideoUrl($pageUrl, $youtubedlPath) { $cmd = $youtubedlPath . ' --quiet' - . ' --get-url' + . ' --dump-json' . ' ' . escapeshellarg($pageUrl) . ' 2>&1'; @@ -47,7 +55,24 @@ function extractVideoUrl($pageUrl, $youtubedlPath) errorOut('youtube-dl error: ' . $lastLine); } } - return $lastLine; + + $json = implode("\n", $output); + $data = json_decode($json); + + $url = null; + foreach ($data->formats as $format) { + //dreambox 7080hd does not play hls files + if (strpos($format->format, 'hls') !== false) { + continue; + } + $url = $format->url; + } + + if ($url === null) { + //use URL chosen by youtube-dl + $url = $data->url; + } + return $url; } function playVideoOnDreambox($videoUrl, $dreamboxHost)