summaryrefslogtreecommitdiff
path: root/func.php
diff options
context:
space:
mode:
authorroot2014-09-13 22:26:58 +0200
committerroot2014-09-13 22:26:58 +0200
commitc5639ee890215e4e8e0f544821ea8d285ca58eb8 (patch)
tree29f685943c61c4d7ec0e376e485686e985b97065 /func.php
parentf8c60cae423fc78ed21d17a9217716ccc1e6dab1 (diff)
downloadvideo-dl-c5639ee890215e4e8e0f544821ea8d285ca58eb8.tar.gz
init
Diffstat (limited to 'func.php')
-rw-r--r--func.php245
1 files changed, 245 insertions, 0 deletions
diff --git a/func.php b/func.php
new file mode 100644
index 0000000..6ad7894
--- /dev/null
+++ b/func.php
@@ -0,0 +1,245 @@
+<?php
+
+function curlInfo($url){
+ //$agent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/30.0";
+ $agent="";
+ $ch=curl_init();
+ curl_setopt ($ch, CURLOPT_URL,$url );
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_USERAGENT, $agent);
+ curl_setopt($ch, CURLOPT_NOBODY, true);
+ curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt ($ch,CURLOPT_VERBOSE,false);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 5);
+ curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
+ curl_setopt($ch,CURLOPT_SSLVERSION,3);
+ curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
+ $page=curl_exec($ch);
+ //echo curl_error($ch);
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ $mime = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
+ $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
+ $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
+ curl_close($ch);
+
+ return $ret = array($httpcode, $mime, $size, $url);
+}
+
+function vid_info($url){
+ exec("youtube-dl --get-url --get-title --get-id --get-thumbnail --get-duration --get-filename --get-format -q --output '%(title)s.%(ext)s' '".escapeshellarg($url)."' 2>/dev/null &", $output, $ret);
+// preg_match("/[0-9]+x[0-9]+/", $output[6], $match);
+// $output[6]=$match[0];
+
+ if($ret != 0){
+ return false;
+ }
+
+ return $output;
+}
+
+function video_dl($VIDEO, $CACHEDIR, $FILENAME){
+ $fp=fopen($CACHEDIR."/".$FILENAME.".txt", "w");
+ $content="downloading ".$FILENAME."\n";
+ fputs($fp, $content);
+ fclose($fp);
+ exec("youtube-dl --no-part --output '".$CACHEDIR."/".$FILENAME."' '$VIDEO'", $pid, $ret);
+ if($ret != 0){
+ return false;
+ } else {
+ return true;
+ }
+}
+
+function video_xt_audio($VIDEO, $CACHEDIR, $FILENAME){
+
+ //exec("youtube-dl --no-part -x --output '".escapeshellarg($CACHEDIR."/".$FILENAME.".%(ext)s' " .escapeshellarg($VIDEO), $pid, $ret);
+ exec("youtube-dl --no-part -x --output ".escapeshellarg($CACHEDIR."/".$FILENAME.".%(ext)s")." " .escapeshellarg($VIDEO), $pid, $ret);
+// echo "youtube-dl --no-part -x --output ".escapeshellarg($CACHEDIR."/".$FILENAME.".%(ext)s")." " .escapeshellarg($VIDEO); //, $pid, $ret);
+ if($ret != 0){
+ return false;
+ } else {
+ return true;
+ }
+ return true;
+}
+
+function pr_player($file, $thumb, $mime, $title, $vid){
+echo "
+<h1>".htmlentities($title)."</h1>
+<br>
+<br>
+<video id=\"".htmlentities($thumb)."\" class=\"video-js vjs-default-skin \"
+ controls preload=\"auto\" width=\"640\" height=\"360\"
+ poster=\"".htmlentities($thumb)."\"
+ data-setup='{\"techOrder\":[\"html5\",\"flash\"]}'>
+ <source src=\"/".htmlentities($file)."\" type='".htmlentities($mime)."' />
+ <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\"
+ data=\"/player/video-js.swf\">
+ <param name=\"movie\" value=\"/player/video-js.swf\" />
+ <param name=\"allowfullscreen\" value=\"true\" />
+ <param name=\"flashvars\"
+ value=\"confing={videoFile: '".htmlentities($file)."'}\"
+ <!-- Image Fallback. Typically the same as the poster image. -->
+ <img src=\"".htmlentities($thumb)."\" width=\"640\" height=\"264\" alt=\"Poster Image\"
+ title=\"No video playback capabilities.\" />
+ </object>
+
+ </video>
+ <br>
+ <br>
+ <a href='/video/".$vid."' class='mail'>back</a>
+";
+ //<param name=\"movie\" value=\"//releases.flowplayer.org/swf/flowplayer-3.2.1.swf\" />
+ //<param name=\"flashvars\"
+ //value='config={\"playlist\":[\"http://video-js.zencoder.com/oceans-clip.png\", {\"url\": \"http://video-js.zencoder.com/oceans-clip.mp4\",\"autoPlay\":false,\"autoBuffering\":true}]}' />
+}
+
+function failure($reason, $ajax = NULL){
+ if($ajax == false){
+ header("HTTP/1.1 404 Not Found");
+ // TODO: make it prettier
+ echo "<p style='font-size: 1.3em;'>".$reason."</p>";
+ exit;
+ }
+ if($_SERVER["REQUEST_METHOD"] == "GET"){
+ if(isset($_GET["ajax"]) && $_GET["ajax"] == 1){
+ header("HTTP/1.1 404 Not Found");
+ // TODO: make it prettier
+ echo "<h1>Error :/</h1><br><p style='font-size: 1.3em;'>".$reason."</p>";
+ exit;
+ }
+ } else if($_SERVER["REQUEST_METHOD"] == "POST"){
+ if($_POST["ajax"] == 1){
+ header("HTTP/1.1 404 Not Found");
+ // TODO: make it prettier
+ echo "<h1>Error :/</h1><br><p style='font-size: 1.3em;'>".$reason."</p>";
+ exit;
+ }
+ }
+ if($ajax == true || $ajax == NULL){
+ $error = "Error. :/";
+ require("error.php");
+ exit;
+ }
+}
+
+function get_all_yt_data($id){
+ $data = file_get_contents("https://gdata.youtube.com/feeds/api/videos/".$id."");
+ $data = preg_replace("/yt:statistics/", "ytstatistics", $data);
+ $data = preg_replace("/media:group/", "mediagroup", $data);
+ $data = preg_replace("/media:description/", "mediadescription", $data);
+ $data = preg_replace("/gd:rating/", "gdrating", $data);
+ $xmldata = simplexml_load_string($data);
+
+ $title = $xmldata->title[0];
+ $viewCount = $xmldata->ytstatistics["viewCount"];
+ $author = $xmldata->author->name[0];
+ $desc = $xmldata->mediagroup->mediadescription[0];
+ $date = $xmldata->published[0];
+ $rate = $xmldata->gdrating["average"];
+
+ $res["title"] = $title;
+ $res["viewCount"] = $viewCount;
+ $res["author"] = $author;
+ $res["desc"] = $desc;
+ $res["date"] = $date;
+ $res["rate"] = $rate;
+
+ return $res;
+}
+
+function get_yt_title($id){
+ $data = file_get_contents("https://gdata.youtube.com/feeds/api/videos/".$id."");
+ $xmldata = simplexml_load_string($data);
+ $title = $xmldata->title[0];
+ return $title;
+}
+
+function getId($video) {
+ exec("youtube-dl --get-id " . escapeshellarg($video), $output, $ret);
+ if($ret != 0)
+ return false;
+
+ $output = $output[0];
+ return $output;
+}
+
+function print_info($title, $vid, $thumb, $duration, $url){
+
+
+//if($filesize > 50000000){ /* 50M */
+// $filesize = $filesize/1000000;
+/*
+ $size = "<p color='red'>size: ".$filesize." (not supported!)</p>";
+} else {
+ $size = "<p color='green'>size: ".$filesize."</p>";
+}
+*/
+$size = "<span id='size'><p>Size: checking...</p></span>";
+
+echo "
+<hr>
+<table width='60%' class='table-center'>
+ <tr>
+ <td>
+ <h3><u>".$title."</u></h3>
+ <br><p>Duration: ".$duration."</p>".$size."
+ </td>
+ <td>&nbsp;&nbsp;
+ </td>
+ <td>
+ <img src='".$thumb."' width='300' border='1' alt='".$url."'>
+ <br>
+ <p><a href='".$url."' title='".$title."' target='__blank' style='text-decoration:underline;color: #333;'>[source]</a></p>
+ <br>
+ </td>
+ </tr>
+</table>
+<div class='row' id='options'>
+<hr>
+ <h4 id='options-heading'><p>What do you want to do? Choose one option.</p></h4>
+ <a href='/stream/".$vid."' title='Stream ".$title."' id='streaming' class='btn btn-link'>Stream!</a> <a href='/ddl/".$vid."' title='Download ".$title."' id='download' class='btn btn-link'>Direct download</a> <a href='/audio/".$vid."' title='Get the audio track' id='audio' class='btn btn-link'>Extract the audio</a>
+</div>
+";
+/*
+ <p>What do you want to do? Choose one option.</p>
+ <b><a href='/stream/".$vid."' class='mail'>Stream!</a></b> or <b><a href='/ddl/".$vid."' class='mail'>Direct download</a></b> or <b><a href='/audio/".$vid."' class='mail'>Extract the audio</a></b>
+
+echo "
+<dl class='dl-horizontal'>
+ <dt>
+ <h3><u>".$title."</u></h3>
+ <br>
+ <p>Duration: ".$duration."</p>".$size."</p>
+ </dt>
+ <dd>
+ <img src='".$thumb."' width='300' border='1' alt='".$url."'>
+ <br>
+ <p><a href='".$url."' title='".$title."' target='__blank'>[source]</a></p>
+ </dd>
+</dl>
+
+ <p>What do you want to do? Choose one option.</p>
+ <a href='/stream/".$vid."' >Stream!</a> or <a href='/ddl/".$vid."' >Direct download</a> or <a href='/aud io/".$vid."' >Extract the audio</a>
+
+";
+*/
+}
+
+function BytesHumanSize($Bytes){
+ $Type=array("", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta");
+ $Index=0;
+ while($Bytes>=1024) {
+ $Bytes/=1024;
+ $Index++;
+ }
+ $Bytes = substr($Bytes, 0, 4);
+
+ //return("".$Bytes." ".$Type[$Index]."bytes");
+ $string = "".$Bytes." ".$Type[$Index]."bytes";
+ if(preg_match("/[0-9]+\. /", $string))
+ $string = preg_replace("/([0-9]+)\. /", "$1 ", $string);
+ return $string;
+}