Fix E_NOTICES on php 8.2
[playVideoOnDreamboxProxy.git] / www / play.php
1 <?php
2 $youtubedlPath = '/usr/bin/youtube-dl';
3 $dreamboxUrl   = 'http://dreambox';
4
5 require_once __DIR__ . '/functions.php';
6 $cfgFile = __DIR__ . '/../data/config.php';
7 if (file_exists($cfgFile)) {
8     include $cfgFile;
9 }
10
11 //for the firefox extension
12 header('Access-Control-Allow-Origin: *');
13
14 if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
15     require __DIR__ . '/form.php';
16     exit();
17 }
18
19 set_error_handler('errorHandlerStore');
20
21 [$pageUrl, $dryRun] = getPageUrl();
22 $json     = getYoutubeDlJson($pageUrl, $youtubedlPath);
23 $videoUrl = extractVideoUrlFromJson($json);
24 if (php_sapi_name() == 'cli') {
25     echo $videoUrl .  "\n";
26 } else {
27     header('Video-URL: ' . $videoUrl);
28 }
29 if (!$dryRun) {
30     playVideoOnDreambox($videoUrl, $dreamboxUrl);
31 }
32
33
34 function errorInput($msg)
35 {
36     if (!headers_sent()) {
37         header('HTTP/1.0 400 Bad Request');
38         header('Content-type: text/plain');
39     }
40     echo $msg . "\n";
41     exit(1);
42 }
43
44 function errorOut($msg, $httpStatus = '500 Internal Server Error')
45 {
46     if (!headers_sent()) {
47         header('HTTP/1.0 ' . $httpStatus);
48         header('Content-type: text/plain');
49     }
50     echo $msg . "\n";
51     syslog(LOG_ERR, 'playVideoOnDreamboxProxy: ' . $httpStatus . ': ' . $msg);
52     exit(2);
53 }
54 ?>