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