Filter out chopped DASH segment streams
[playVideoOnDreamboxProxy.git] / www / play.php
index a9adc5b8a83953a35a69eb81e96410d7033101d6..d9593a5ab1b97eaa7001dd52c01c4c1c04e0f838 100644 (file)
@@ -9,7 +9,11 @@ if (file_exists($cfgFile)) {
 
 $pageUrl  = getPageUrl();
 $videoUrl = extractVideoUrl($pageUrl, $youtubedlPath);
-header('Video-URL: ' . $videoUrl);
+if (php_sapi_name() == 'cli') {
+    echo $videoUrl .  "\n";
+} else {
+    header('Video-URL: ' . $videoUrl);
+}
 playVideoOnDreambox($videoUrl, $dreamboxHost);
 
 function getPageUrl()
@@ -45,7 +49,7 @@ function extractVideoUrl($pageUrl, $youtubedlPath)
         . ' --quiet'
         . ' --dump-json'
         . ' ' . escapeshellarg($pageUrl)
-        . ' 2>&1';
+        . ' 2> /dev/null';
 
     $lastLine = exec($cmd, $output, $exitCode);
     if ($exitCode !== 0) {
@@ -64,8 +68,12 @@ function extractVideoUrl($pageUrl, $youtubedlPath)
 
     $url = null;
     foreach ($data->formats as $format) {
-        //dreambox 7080hd does not play hls files
         if (strpos($format->format, 'hls') !== false) {
+            //dreambox 7080hd does not play hls files
+            continue;
+        }
+        if ($format->protocol == 'http_dash_segments') {
+            //split up into multiple small files
             continue;
         }
         $url = $format->url;
@@ -75,6 +83,13 @@ function extractVideoUrl($pageUrl, $youtubedlPath)
         //use URL chosen by youtube-dl
         $url = $data->url;
     }
+
+    if ($url == '') {
+        errorOut(
+            'No video URL found',
+            '406 No video URL found'
+        );
+    }
     return $url;
 }
 
@@ -120,7 +135,6 @@ function errorInput($msg)
     header('HTTP/1.0 400 Bad Request');
     header('Content-type: text/plain');
     echo $msg . "\n";
-    syslog(LOG_ERR, 'playVideoOnDreamboxProxy: ' . $httpStatus . ':' .  $msg);
     exit(1);
 }