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("
No video information found.
", 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("No video information found.
", 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].")
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);