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