5d631a00f1cef370e9e3b95f7d610f886d7ae009
[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     header('HTTP/1.0 400 Bad Request');
25     header('Content-type: text/plain');
26     echo $msg . "\n";
27     exit(1);
28 }
29
30 function errorOut($msg, $httpStatus = '500 Internal Server Error')
31 {
32     header('HTTP/1.0 ' . $httpStatus);
33     header('Content-type: text/plain');
34     echo $msg . "\n";
35     syslog(LOG_ERR, 'playVideoOnDreamboxProxy: ' . $httpStatus . ': ' . $msg);
36     exit(2);
37 }
38 ?>