summaryrefslogtreecommitdiff
path: root/info.php
blob: 5689ef8d1cc3b68480bb57b985360f2c253fe5b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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);