Fix E_NOTICES on php 8.2 master github/master
authorChristian Weiske <cweiske@cweiske.de>
Mon, 20 Nov 2023 16:04:42 +0000 (17:04 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 20 Nov 2023 16:04:42 +0000 (17:04 +0100)
README.rst
www/functions.php
www/play.php

index 0ff7a5ef4eb3090adb86728430bb653dfd34774b..73318cce7a4abd716b2f99a9ea6f2153fc8a0c19 100644 (file)
@@ -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
index 6ad1044e27273a404c0ed571536eb184be80a219..95694e71cbd547c7a0ee9efd2882cbcb2796f9e6 100644 (file)
@@ -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] <url>"
+            );
+        }
+        $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') {
@@ -22,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'])) {
@@ -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)
@@ -89,17 +106,48 @@ 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
+            || $format->vcodec == 'vp9'
+        ) {
+            //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;
         }
+        if ($format->ext == 'flv') {
+            //Internal data flow error
+            continue;
+        }
+        $safeFormats[] = $format;
+    }
+
+    $url = null;
+
+    //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');
+        }
+        return ($b->quality ?? 0) - ($a->quality ?? 0);
+    });
+    foreach ($safeFormats as $format) {
+        //echo $format->format . ' | ' . $format->vcodec . ' | ' . $format->acodec . "\n";
         $url = $format->url;
+        break;
     }
 
     if ($url === null) {
index 502e3f24ce50c1b703fea9ce6cb73609b6def223..0fdb243de8ef2704f1c0e003c8741a7992da8654 100644 (file)
@@ -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();
@@ -15,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') {
@@ -23,7 +26,9 @@ if (php_sapi_name() == 'cli') {
 } else {
     header('Video-URL: ' . $videoUrl);
 }
-playVideoOnDreambox($videoUrl, $dreamboxUrl);
+if (!$dryRun) {
+    playVideoOnDreambox($videoUrl, $dreamboxUrl);
+}
 
 
 function errorInput($msg)