Fix E_NOTICES on php 8.2
[playVideoOnDreamboxProxy.git] / www / play.php
index 5d631a00f1cef370e9e3b95f7d610f886d7ae009..0fdb243de8ef2704f1c0e003c8741a7992da8654 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 $youtubedlPath = '/usr/bin/youtube-dl';
-$dreamboxHost  = 'dreambox';
+$dreamboxUrl   = 'http://dreambox';
 
 require_once __DIR__ . '/functions.php';
 $cfgFile = __DIR__ . '/../data/config.php';
@@ -8,7 +8,17 @@ if (file_exists($cfgFile)) {
     include $cfgFile;
 }
 
-$pageUrl  = getPageUrl();
+//for the firefox extension
+header('Access-Control-Allow-Origin: *');
+
+if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
+    require __DIR__ . '/form.php';
+    exit();
+}
+
+set_error_handler('errorHandlerStore');
+
+[$pageUrl, $dryRun] = getPageUrl();
 $json     = getYoutubeDlJson($pageUrl, $youtubedlPath);
 $videoUrl = extractVideoUrlFromJson($json);
 if (php_sapi_name() == 'cli') {
@@ -16,23 +26,29 @@ if (php_sapi_name() == 'cli') {
 } else {
     header('Video-URL: ' . $videoUrl);
 }
-playVideoOnDreambox($videoUrl, $dreamboxHost);
+if (!$dryRun) {
+    playVideoOnDreambox($videoUrl, $dreamboxUrl);
+}
 
 
 function errorInput($msg)
 {
-    header('HTTP/1.0 400 Bad Request');
-    header('Content-type: text/plain');
+    if (!headers_sent()) {
+        header('HTTP/1.0 400 Bad Request');
+        header('Content-type: text/plain');
+    }
     echo $msg . "\n";
     exit(1);
 }
 
 function errorOut($msg, $httpStatus = '500 Internal Server Error')
 {
-    header('HTTP/1.0 ' . $httpStatus);
-    header('Content-type: text/plain');
+    if (!headers_sent()) {
+        header('HTTP/1.0 ' . $httpStatus);
+        header('Content-type: text/plain');
+    }
     echo $msg . "\n";
     syslog(LOG_ERR, 'playVideoOnDreamboxProxy: ' . $httpStatus . ': ' . $msg);
     exit(2);
 }
-?>
\ No newline at end of file
+?>