From e49228d52d2c0ef42444b20ffcd543241bdf485c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 7 Mar 2019 20:52:35 +0100 Subject: [PATCH 1/7] Add CORS header for firefox extension --- www/play.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/play.php b/www/play.php index 502e3f2..d96764d 100644 --- a/www/play.php +++ b/www/play.php @@ -8,6 +8,9 @@ if (file_exists($cfgFile)) { include $cfgFile; } +//for the firefox extension +header('Access-Control-Allow-Origin: *'); + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') { require __DIR__ . '/form.php'; exit(); -- 2.30.2 From 27d22297323eb1422463d8df44a8a5f5b7ddd447 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 3 Sep 2021 22:14:10 +0200 Subject: [PATCH 2/7] Filter out VP9 streams, sort by quality --- www/functions.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/www/functions.php b/www/functions.php index 6ad1044..617724a 100644 --- a/www/functions.php +++ b/www/functions.php @@ -89,17 +89,36 @@ function extractVideoUrlFromJson($json) errorOut('Cannot decode JSON: ' . json_last_error_msg()); } - $url = null; + $safeFormats = []; foreach ($data->formats as $format) { if (strpos($format->format, 'hls') !== false) { //dreambox 7080hd does not play hls files continue; } + if (strpos($format->format, 'vp9') !== false) { + //dreambox 7080hd does not play VP9 video streams + continue; + } if ($format->protocol == 'http_dash_segments') { //split up into multiple small files continue; } + if ($format->ext == 'flv') { + //Internal data flow error + continue; + } + $safeFormats[] = $format; + } + + $url = null; + + //filter: best quality + usort($safeFormats, function ($a, $b) { + return ($b->quality ?? 0) - ($a->quality ?? 0); + }); + foreach ($safeFormats as $format) { $url = $format->url; + break; } if ($url === null) { -- 2.30.2 From da8f9390c923632a6d523fd843ae6b47d78acc1c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 14 Dec 2022 22:01:22 +0100 Subject: [PATCH 3/7] Add "--dry-run" ("-n") cli option --- README.rst | 4 ++++ www/functions.php | 23 ++++++++++++++++++++--- www/play.php | 6 ++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 0ff7a5e..73318cc 100644 --- a/README.rst +++ b/README.rst @@ -47,6 +47,10 @@ You can test it on command line, too:: $ php www/play.php http://example.org/page.htm +Testing the URL selection without playing on the dreambox is possible:: + + $ php www/play.php http://example.org/page.htm --dry-run + ======= License diff --git a/www/functions.php b/www/functions.php index 617724a..46a46b5 100644 --- a/www/functions.php +++ b/www/functions.php @@ -2,11 +2,28 @@ function getPageUrl() { global $argv, $argc; + + $dryRun = false; if (php_sapi_name() == 'cli') { if ($argc < 2) { - errorInput('No URL given as command line parameter'); + errorInput( + "No URL given as command line parameter\n" + . "Usage:\n" + . " play.php [--dry-run|-n] " + ); + } + $options = []; + array_shift($argv);//remove script itself + foreach ($argv as $val) { + if ($val[0] == '-') { + $options[$val] = true; + } else { + $pageUrl = $val; + } + } + if (isset($options['--dry-run']) || isset($options['-n'])) { + $dryRun = true; } - $pageUrl = $argv[1]; } else if (!isset($_SERVER['CONTENT_TYPE'])) { errorInput('Content type header missing'); } else if ($_SERVER['CONTENT_TYPE'] == 'text/plain') { @@ -30,7 +47,7 @@ function getPageUrl() } else if ($parts['scheme'] !== 'http' && $parts['scheme'] !== 'https') { errorInput('Invalid URL in POST data: Non-HTTP scheme'); } - return $pageUrl; + return [$pageUrl, $dryRun]; } function getYoutubeDlJson($pageUrl, $youtubedlPath) diff --git a/www/play.php b/www/play.php index d96764d..0fdb243 100644 --- a/www/play.php +++ b/www/play.php @@ -18,7 +18,7 @@ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') { set_error_handler('errorHandlerStore'); -$pageUrl = getPageUrl(); +[$pageUrl, $dryRun] = getPageUrl(); $json = getYoutubeDlJson($pageUrl, $youtubedlPath); $videoUrl = extractVideoUrlFromJson($json); if (php_sapi_name() == 'cli') { @@ -26,7 +26,9 @@ if (php_sapi_name() == 'cli') { } else { header('Video-URL: ' . $videoUrl); } -playVideoOnDreambox($videoUrl, $dreamboxUrl); +if (!$dryRun) { + playVideoOnDreambox($videoUrl, $dreamboxUrl); +} function errorInput($msg) -- 2.30.2 From 827300f59d7899d36929661a940525f3c74addcd Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 14 Dec 2022 22:02:08 +0100 Subject: [PATCH 4/7] Filter vp9 a second time .. DM7080 does not play those --- www/functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/functions.php b/www/functions.php index 46a46b5..9d40737 100644 --- a/www/functions.php +++ b/www/functions.php @@ -112,7 +112,9 @@ function extractVideoUrlFromJson($json) //dreambox 7080hd does not play hls files continue; } - if (strpos($format->format, 'vp9') !== false) { + if (strpos($format->format, 'vp9') !== false + || $format->vcodec == 'vp9' + ) { //dreambox 7080hd does not play VP9 video streams continue; } -- 2.30.2 From d0a86fefe25738c7e5b2d362032d35765bf29b50 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 14 Dec 2022 22:02:32 +0100 Subject: [PATCH 5/7] Give streams with audio a higher priority --- www/functions.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/functions.php b/www/functions.php index 9d40737..3e4e2be 100644 --- a/www/functions.php +++ b/www/functions.php @@ -133,6 +133,9 @@ function extractVideoUrlFromJson($json) //filter: best quality usort($safeFormats, function ($a, $b) { + if ((($a->acodec != 'none') + ($b->acodec != 'none')) == 1) { + return ($b->acodec != 'none') - ($a->acodec != 'none'); + } return ($b->quality ?? 0) - ($a->quality ?? 0); }); foreach ($safeFormats as $format) { -- 2.30.2 From e672bc57514b6a11cd17d7fa20b2f71f3132690c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 14 Dec 2022 22:22:32 +0100 Subject: [PATCH 6/7] Filter all H.246 high profile codecs .. instead of hard-coding the list --- www/functions.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/www/functions.php b/www/functions.php index 3e4e2be..ca64ed5 100644 --- a/www/functions.php +++ b/www/functions.php @@ -118,6 +118,10 @@ function extractVideoUrlFromJson($json) //dreambox 7080hd does not play VP9 video streams continue; } + if (strtolower(substr($format->vcodec, 0, 6)) == 'avc1.6') { + //dreambox DM7080 does not play H.264 High Profile + continue; + } if ($format->protocol == 'http_dash_segments') { //split up into multiple small files continue; @@ -139,6 +143,7 @@ function extractVideoUrlFromJson($json) return ($b->quality ?? 0) - ($a->quality ?? 0); }); foreach ($safeFormats as $format) { + //echo $format->format . ' | ' . $format->vcodec . ' | ' . $format->acodec . "\n"; $url = $format->url; break; } -- 2.30.2 From d8006352f992e60c9f19e7889c39aec1d40e9c1e Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 20 Nov 2023 17:04:42 +0100 Subject: [PATCH 7/7] Fix E_NOTICES on php 8.2 --- www/functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/functions.php b/www/functions.php index ca64ed5..95694e7 100644 --- a/www/functions.php +++ b/www/functions.php @@ -39,7 +39,7 @@ function getPageUrl() errorInput('Content type is not text/plain but ' . $_SERVER['CONTENT_TYPE']); } - $parts = parse_url($pageUrl); + $parts = parse_url($pageUrl ?? null); if ($parts === false) { errorInput('Invalid URL in POST data'); } else if (!isset($parts['scheme'])) { @@ -137,6 +137,8 @@ function extractVideoUrlFromJson($json) //filter: best quality usort($safeFormats, function ($a, $b) { + $a->acodec = $a->acodec ?? null; + $b->acodec = $b->acodec ?? null; if ((($a->acodec != 'none') + ($b->acodec != 'none')) == 1) { return ($b->acodec != 'none') - ($a->acodec != 'none'); } -- 2.30.2