summaryrefslogtreecommitdiff
path: root/dl.php
diff options
context:
space:
mode:
Diffstat (limited to 'dl.php')
-rw-r--r--dl.php43
1 files changed, 34 insertions, 9 deletions
diff --git a/dl.php b/dl.php
index 88d597e..4e6efe6 100644
--- a/dl.php
+++ b/dl.php
@@ -10,7 +10,7 @@ require_once("class/redis.php");
@ini_set("memory_limit",'150M');
set_time_limit(0);
-$db = new database($REDIS_DBNAME, $REDIS_CONNECT);
+$db = new database($REDIS_DBNAME, $REDIS_CONNECT);
$db->open();
if(!$db->listExists($_GET["vid"])){
failure("No video information found.", true);
@@ -119,16 +119,19 @@ switch($_GET["task"]){
case("stream"):
ignore_user_abort(true);
+ if(file_exists($CACHEDIR."/".$info[2].".txt"))
+ failure('Already doing the request.', false);
# send 'cached' response in case we already have the video on disk
if(file_exists($CACHEDIR."/".$info[2]) && !file_exists($CACHEDIR."/".$info[2].".txt")){
echo "cached";
- } else {
- # but in most cases we don't, so let's download it
- $ret = video_dl($info[0], $CACHEDIR, $info[2]);
- if(!$ret)
- failure("Fetching the video failed.", false);
- else
- unlink($CACHEDIR."/".$info[2].".txt");
+ exit;
+ }
+ # but in most cases we don't, so let's download it
+ $ret = video_dl($info[0], $CACHEDIR, $info[2]);
+ if(!$ret)
+ failure("Fetching the video failed.", false);
+ else
+ unlink($CACHEDIR."/".$info[2].".txt");
}
break;
@@ -140,8 +143,30 @@ switch($_GET["task"]){
pr_player(htmlentities($CACHEDIR . "/" . $info[2]), htmlentities($info[4]), htmlentities($mime), htmlentities($info[1]), htmlentities($info[2]));
break;
+ case("convert"):
+ $dir = array_diff(scandir($CACHEDIR), array('.', '..'));
+ if(!in_array($_GET['vid'], $dir)){
+ failure('Video not found.' false);
+ }
+ if(file_exists($CACHEDIR."/".$info[2].".webm.txt"))
+ exit;
+ if(file_exists($CACHEDIR."/".$info[2]."webm")){
+ echo "cached";
+ exit;
+ }
+ if(!convert_video($info[2]))
+ failure("Converting video failed.", false);
+ else
+ unlink($CACHEDIR."/".$info[2].".webm.txt");
+
+ $finfo = new finfo(FILEINFO_MIME_TYPE);
+ $mime = $finfo->file($CACHEDIR . "/" . $info[2]);
+
+ pr_player(htmlentities($CACHEDIR . "/" . $info[2]), htmlentities($info[4]), htmlentities($mime), htmlentities($info[1]), htmlentities($info[2]), true);
+
+ break;
+
default:
failure("I don't understand your question.", true);
break;
-
}