Skip to content

Instantly share code, notes, and snippets.

@adis-io
Created June 25, 2012 13:11
Show Gist options
  • Save adis-io/2988480 to your computer and use it in GitHub Desktop.
Save adis-io/2988480 to your computer and use it in GitHub Desktop.
prosha.php
<?
/*
* Bast Castle firmware (YouTube Processor)
*
* Copyright (c) 2012, Sekator500 <sekator500@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$ctx = stream_context_create(array('http' => array('timeout' => 10, 'header' => "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 (I'm not Googlebot)")));
switch ($_GET['method']) {
case "data":
$id = $_GET['feed'];
$jsn = json_decode(@file_get_contents("http://gdata.youtube.com/feeds/api/$id&fields=entry(author(name),yt:statistics,gd:rating,media:group(yt:videoid,media:title,yt:uploaded,yt:duration,media:thumbnail(@url)))&alt=json"));
for ($i = 0,$c = 0; $i < count($jsn->feed->entry); $i++) {
if ($jsn->feed->entry[$i]->{'media$group'}->{'yt$duration'}->seconds > 0) {
echo $jsn->feed->entry[$i]->{'media$group'}->{'yt$videoid'}->{'$t'} ."\t".
$jsn->feed->entry[$i]->{'media$group'}->{'media$title'}->{'$t'} ."\t".
$jsn->feed->entry[$i]->{'media$group'}->{'yt$uploaded'}->{'$t'} ."\t".
$jsn->feed->entry[$i]->{'media$group'}->{'yt$duration'}->seconds ."\t".
$jsn->feed->entry[$i]->{'media$group'}->{'media$thumbnail'}[2]->url ."\t".
$jsn->feed->entry[$i]->{'gd$rating'}->average ."\t".
($jsn->feed->entry[$i]->{'yt$statistics'}->viewCount == "" ? 0 : $jsn->feed->entry[$i]->{'yt$statistics'}->viewCount) ."\t".
$jsn->feed->entry[$i]->{'gd$rating'}->numRaters ."\t".
$jsn->feed->entry[$i]->author[0]->name->{'$t'} ."\n";
}
}
break;
case "playlist":
$id = $_GET['feed'];
$jsn = json_decode(@file_get_contents("http://gdata.youtube.com/feeds/api/$id&fields=entry(author(name),published,title,yt:playlistId,media:group(yt:duration,media:thumbnail(@url)))&alt=json"));
for ($i = 0,$c = 0; $i < count($jsn->feed->entry); $i++) {
echo $jsn->feed->entry[$i]->{'yt$playlistId'}->{'$t'} ."\t".
$jsn->feed->entry[$i]->title->{'$t'} ."\t".
$jsn->feed->entry[$i]->published->{'$t'} ."\t".
$jsn->feed->entry[$i]->{'media$group'}->{'yt$duration'}->seconds ."\t".
$jsn->feed->entry[$i]->{'media$group'}->{'media$thumbnail'}[2]->url ."\t0\t0\t0\t". $jsn->feed->entry[$i]->author[0]->name->{'$t'} . "\n";
}
break;
case "video":
$id = $_GET['video_id'];
if(false == ($data = @file_get_contents("http://www.youtube.com/watch?v=$id", 0, $ctx))) {
die();
}
$a = strpos($data,"url_encoded_fmt_stream_map=");
$b = strpos($data,"&", $a + 1);
$data = urldecode(substr($data, $a + 33 , $b - $a - 33));
$tmArr = explode("url=",$data);
for ($i = 0; $i < count($tmArr); $i++) {
$a = strpos($tmArr[$i],"video%2Fmp4");
if ($a === false) {
$a = strpos($tmArr[$i],"video%2Fx-flv");
if ($a === false) {
continue;
} else {
$url = urldecode(substr($tmArr[$i], 0, $a + 13));
}
} else {
$url = urldecode(substr($tmArr[$i], 0, $a + 11));
}
$a = strpos($url,"&itag=");
$b = strpos($url,"&", $a + 1);
$tag = substr($url,$a + 6,$b - $a - 6);
switch ($tag) {
case "34": //360p
case "22": //720p
case "37": //1080p
case "35": //480p
case "18": //360p
echo $tag."\t".$url."\n";
break;
}
}
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment