initial version
[youtube-dl-server.git] / www / info.php
1 <?php
2 $youtubedlPath = '/home/cweiske/bin/youtube-dl';
3
4 if (!isset($_GET['url']) || $_GET['url'] == '') {
5     header('HTTP/1.0 400 Bad Request');
6     header('Content-Type: text/plain');
7     echo "'url' parameter missing\n";
8     exit(1);
9 }
10 $url = $_GET['url'];
11 $parsed = parse_url($url);
12 if ($parsed === false || !isset($parsed['scheme']) || !isset($parsed['host'])) {
13     header('HTTP/1.0 400 Bad Request');
14     header('Content-Type: text/plain');
15     echo "Invalid URL\n";
16     exit(1);
17 }
18
19 exec(
20     $youtubedlPath . ' --dump-json ' . escapeshellarg($url),
21     $output,
22     $retval
23 );
24
25 if ($retval === 127) {
26     header('HTTP/1.0 500 Internal Server Error');
27     header('Content-Type: text/plain');
28     echo "youtube-dl not found\n";
29     exit(1);
30 } else if ($retval > 0) {
31     header('HTTP/1.0 500 Internal Server Error');
32     header('Content-Type: text/plain');
33     echo "Error fetching video data\n";
34     exit(1);
35 }
36
37 header('HTTP/1.0 200 OK');
38 header('Content-Type: application/json');
39 echo implode("\n", $output) . "\n";
40 ?>