Handle dreambox web interface authentication errors
[playVideoOnDreamboxProxy.git] / www / play.php
1 <?php
2 $youtubedlPath = '/usr/bin/youtube-dl';
3 $dreamboxHost  = '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 $pageUrl  = getPageUrl();
12 $json     = getYoutubeDlJson($pageUrl, $youtubedlPath);
13 $videoUrl = extractVideoUrlFromJson($json);
14 if (php_sapi_name() == 'cli') {
15     echo $videoUrl .  "\n";
16 } else {
17     header('Video-URL: ' . $videoUrl);
18 }
19 playVideoOnDreambox($videoUrl, $dreamboxHost);
20
21
22 function errorInput($msg)
23 {
24     if (!headers_sent()) {
25         header('HTTP/1.0 400 Bad Request');
26         header('Content-type: text/plain');
27     }
28     echo $msg . "\n";
29     exit(1);
30 }
31
32 function errorOut($msg, $httpStatus = '500 Internal Server Error')
33 {
34     if (!headers_sent()) {
35         header('HTTP/1.0 ' . $httpStatus);
36         header('Content-type: text/plain');
37     }
38     echo $msg . "\n";
39     syslog(LOG_ERR, 'playVideoOnDreamboxProxy: ' . $httpStatus . ': ' . $msg);
40     exit(2);
41 }
42 ?>