summaryrefslogtreecommitdiff
path: root/info.php
diff options
context:
space:
mode:
authorroot2014-09-13 22:26:58 +0200
committerroot2014-09-13 22:26:58 +0200
commitc5639ee890215e4e8e0f544821ea8d285ca58eb8 (patch)
tree29f685943c61c4d7ec0e376e485686e985b97065 /info.php
parentf8c60cae423fc78ed21d17a9217716ccc1e6dab1 (diff)
downloadvideo-dl-c5639ee890215e4e8e0f544821ea8d285ca58eb8.tar.gz
init
Diffstat (limited to 'info.php')
-rw-r--r--info.php88
1 files changed, 88 insertions, 0 deletions
diff --git a/info.php b/info.php
new file mode 100644
index 0000000..5689ef8
--- /dev/null
+++ b/info.php
@@ -0,0 +1,88 @@
+<?php
+
+require_once("func.php");
+
+# check for the request method
+if($_SERVER["REQUEST_METHOD"] != "POST" && $_SERVER["REQUEST_METHOD" != "GET"]){
+ failure("Request method not supported.", false);
+}
+if($_SERVER["REQUEST_METHOD"] == "POST"){
+ $vid = $_POST["vid"];
+} else {
+ $vid = $_GET["vid"];
+}
+
+require_once("config.php");
+require_once("class/redis.php");
+
+# new redis object
+$db = new database($REDIS_DBNAME, $REDIS_CONNECT);
+$db->open();
+
+# check if we have a list specified by the video id
+if(!$db->listExists($vid)){
+ $video = $vid;
+ include("check.php");
+ $vid = getId($video);
+ $db->db->rPush($vid, $video);
+ if(!$vid)
+ failure("<h1>No video information found.</h1>", false);
+}
+
+# do we have already the video information stored?
+if($db->len($vid) > 1){
+ # yes, we have. fetch i direct from redis
+ $info = $db->getAll($vid);
+
+} else {
+ # no, we don't. get the url
+ $url = $db->getItem($vid, 0);
+
+ # and ask youtube-dl to get all information
+ $info = vid_info($url);
+ if(!$info){
+ failure("<h1>No video information found.</h1>", false);
+ }
+
+ # now store it on redis
+ $db->storeList($vid, $info);
+
+ # fetch it from redis to get the right order (TODO)
+ $info = $db->getAll($vid);
+}
+
+# close the db connection
+$db->close();
+
+# free memory
+unset($db);
+
+# $info has the following schema
+/*
+ $url = $info[0]
+ $title = $info[1];
+ $vid = $info[2];
+ $dllink = $info[3];
+ $thumb = $info[4];
+ $filename = $info[5];
+ $duration = $info[6];
+ $format = $info[7];
+ // deprecated
+ $httpcode = $info[8];
+ $mime = $info[9];
+ $filesize =$info[10]
+*/
+
+/*
+if($info[8] >= 400)
+ failure("Failure. Foreign server responded with a invalid status code. (".$info[8].")<br>That is not an error on our side and there is nothing we can do.", false);
+*/
+
+$title = htmlentities($info[1]);
+$vid = htmlentities($info[2]);
+$thumb = htmlentities($info[4]);
+$duration = htmlentities($info[6]);
+$url = htmlentities($info[0]);
+
+# print the stuff
+print_info($title, $vid, $thumb, $duration, $url);