summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot2014-09-14 23:44:49 +0200
committerroot2014-09-14 23:44:49 +0200
commitdfc4ee6bfbff601328f6bf8dadf9716a58cbd903 (patch)
tree6860b0def3434f40b95ccbfb87fd216d91ef5a1c
parenteb414bfb80480c1fcac7ded7e07a3dd579d3712c (diff)
parent3a8085d8981c6521cdf5dd3b5ed3412b2aac011e (diff)
downloadvideo-dl-dfc4ee6bfbff601328f6bf8dadf9716a58cbd903.tar.gz
Merge branch 'master' of git.iamfabulous.de:bootstrap-video-dl
-rw-r--r--dl.php43
-rw-r--r--func.php22
-rw-r--r--stream.php17
3 files changed, 72 insertions, 10 deletions
diff --git a/dl.php b/dl.php
index 0881018..65178a7 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;
-
}
diff --git a/func.php b/func.php
index 3c6adb7..e1bf9bb 100644
--- a/func.php
+++ b/func.php
@@ -68,7 +68,26 @@ function video_xt_audio($VIDEO, $CACHEDIR, $FILENAME){
return true;
}
-function pr_player($file, $thumb, $mime, $title, $vid){
+function convert_video($FILENAME){
+ $fp=fopen($CACHEDIR."/".$FILENAME.".webm.txt", "w");
+ $content="extracting audio: ".$FILENAME."\n";
+ fputs($fp, $content);
+ fclose($fp);
+ if(file_exists($FILENAME.".mp4") || file_exists($FILENAME.".webm"))
+ return;
+ rename($CACHEDIR . "/" . $FILENAME, $CACHEDIR . "/" . $FILENAME. ".mp4");
+ exec("ffmpeg -i " . $CACHEDIR . "/" . $VID . ".mp4 " . $CACHEDIR . "/" . $VID . ".webm", $pid, $ret);
+ rename($CACHEDIR . "/" . $FILENAME . ".mp4", $CACHEDIR . "/" . $FILENAME);
+ if($ret != 0){
+ return false;
+ }
+
+ return true;
+}
+
+function pr_player($file, $thumb, $mime, $title, $vid, $html5 = false){
+if($html5)
+ $WEBMVIDEO = "<source src=\"/".htmlentities($file.".webm")."\" type='video/webm' />";
echo "
<h1>".htmlentities($title)."</h1>
<br>
@@ -78,6 +97,7 @@ echo "
poster=\"".htmlentities($thumb)."\"
data-setup='{\"techOrder\":[\"html5\",\"flash\"]}'>
<source src=\"/".htmlentities($file)."\" type='".htmlentities($mime)."' />
+ ".$WEBMVIDEO."
<p class=\"vjs-no-js\">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href=\"http://videojs.com/html5-video-support/\" target=\"_blank\">supports HTML5 video</a></p>
<object id=\"flash_fallback_1\" class=\"vjs-flash-fallback\" width=\"640\" height=\"264\" type=\"application/x-shockwave-flash\"
diff --git a/stream.php b/stream.php
index bbcc9a7..e304d9c 100644
--- a/stream.php
+++ b/stream.php
@@ -53,6 +53,23 @@ unset($db);
}
else if(task == "player"){
document.getElementById('middle').innerHTML=r.responseText;
+ var canPlay = false;
+ var v = document.createElement('video');
+ if(v.canPlayType && v.canPlayType('video/mp4').replace(/no/, '')) {
+ canPlay = true;
+ }
+ if(canPlay != true){
+ var canWebm = false;
+ if(v.canPlayType && v.canPlayType('video/webm').replace(/no/, '')){
+ if(window.confirm("It seems your browser doesn't support mp4 videos. Do you want to convert it to webm?")){
+ doVideo("convert");
+ }
+ } else {
+ alert("Sorry, it seems your browser doesn't support our video formats.");
+ }
+ }
+ } else if(task == "convert"){
+ document.getElementById('middle').innerHTML=r.responseText;
} else {
doVideo("player");
}