initial version
authorChristian Weiske <christian.weiske@netresearch.de>
Fri, 14 Aug 2015 09:08:53 +0000 (11:08 +0200)
committerChristian Weiske <christian.weiske@netresearch.de>
Fri, 14 Aug 2015 09:08:53 +0000 (11:08 +0200)
README.rst [new file with mode: 0644]
www/info.php [new file with mode: 0644]

diff --git a/README.rst b/README.rst
new file mode 100644 (file)
index 0000000..811bbe8
--- /dev/null
@@ -0,0 +1,33 @@
+*****************
+youtube-dl server
+*****************
+
+Uses `youtube-dl`__ to fetch information about videos that
+can be used to download the video.
+
+
+Usage
+=====
+Use ``get.php`` with the ``url`` parameter::
+
+  http://example.org/get.php?url=http://youtu...
+
+It will return JSON data about the video.
+Same format as ``youtube-dl --dump-json`` returns.
+
+
+Dependencies
+============
+* PHP
+
+
+License
+=======
+AGPLv3 or later.
+
+
+Alternatives
+============
+* youtube-dl-api-server__
+
+__ https://github.com/jaimeMF/youtube-dl-api-server
diff --git a/www/info.php b/www/info.php
new file mode 100644 (file)
index 0000000..deefbf5
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+$youtubedlPath = '/home/cweiske/bin/youtube-dl';
+
+if (!isset($_GET['url']) || $_GET['url'] == '') {
+    header('HTTP/1.0 400 Bad Request');
+    header('Content-Type: text/plain');
+    echo "'url' parameter missing\n";
+    exit(1);
+}
+$url = $_GET['url'];
+$parsed = parse_url($url);
+if ($parsed === false || !isset($parsed['scheme']) || !isset($parsed['host'])) {
+    header('HTTP/1.0 400 Bad Request');
+    header('Content-Type: text/plain');
+    echo "Invalid URL\n";
+    exit(1);
+}
+
+exec(
+    $youtubedlPath . ' --dump-json ' . escapeshellarg($url),
+    $output,
+    $retval
+);
+
+if ($retval === 127) {
+    header('HTTP/1.0 500 Internal Server Error');
+    header('Content-Type: text/plain');
+    echo "youtube-dl not found\n";
+    exit(1);
+} else if ($retval > 0) {
+    header('HTTP/1.0 500 Internal Server Error');
+    header('Content-Type: text/plain');
+    echo "Error fetching video data\n";
+    exit(1);
+}
+
+header('HTTP/1.0 200 OK');
+header('Content-Type: application/json');
+echo implode("\n", $output) . "\n";
+?>