From c5639ee890215e4e8e0f544821ea8d285ca58eb8 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 13 Sep 2014 22:26:58 +0200 Subject: init --- func.php | 245 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 func.php (limited to 'func.php') diff --git a/func.php b/func.php new file mode 100644 index 0000000..6ad7894 --- /dev/null +++ b/func.php @@ -0,0 +1,245 @@ +/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 " +

".htmlentities($title)."

+
+
+ +
+
+ back +"; + // + // +} + +function failure($reason, $ajax = NULL){ + if($ajax == false){ + header("HTTP/1.1 404 Not Found"); + // TODO: make it prettier + echo "

".$reason."

"; + 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 "

Error :/


".$reason."

"; + exit; + } + } else if($_SERVER["REQUEST_METHOD"] == "POST"){ + if($_POST["ajax"] == 1){ + header("HTTP/1.1 404 Not Found"); + // TODO: make it prettier + echo "

Error :/


".$reason."

"; + 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 = "

size: ".$filesize." (not supported!)

"; +} else { + $size = "

size: ".$filesize."

"; +} +*/ +$size = "

Size: checking...

"; + +echo " +
+ + + + + + +
+

".$title."

+

Duration: ".$duration."

".$size." +
   + + ".$url." +
+

[source]

+
+
+
+
+

What do you want to do? Choose one option.

+ Stream! Direct download Extract the audio +
+"; +/* +

What do you want to do? Choose one option.

+ Stream! or Direct download or Extract the audio + +echo " +
+
+

".$title."

+
+

Duration: ".$duration."

".$size."

+
+
+ ".$url." +
+

[source]

+
+
+ +

What do you want to do? Choose one option.

+ Stream! or Direct download or Extract the audio + +"; +*/ +} + +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; +} -- cgit v1.2.3