[sourcecode language=’php’]
getRemoteFile($orgurl);
if(preg_match(‘/”fmt_url_map”:\s+”([^”]+)”/i’, $body,$matches) || preg_match(‘/fmt_url_map=([^&]+)/i’, $body,$matches) ) {
//$urls = explode(‘,’,urldecode($matches[1]));
$urls = explode(‘,’,$matches[1]);
$links = array();
$videos = false;
$formats = array(
‘6’=>array(‘flv’,’Low Quality’),
’13’=>array(‘3gp’,’Low Quality’),
’18’=>array(‘mp4′,’Low Quality (480p)’),
’22’=>array(‘mp4′,’High Quality (720p)’),
’34’=>array(‘flv’,’High Quality (320p)’),
’35’=>array(‘flv’,’High Quality (480p)’),
’37’=>array(‘mp4′,’High Quality (1080p)’),
);
foreach($urls as $url) {
//echo “
url:”.$url;
$format = explode(‘|’,$url,2);
if(isset($formats[$format[0]])) {
$meta = $formats[$format[0]];
$videos[] = array(‘ext’ => $meta[0], ‘type’ => $meta[1], ‘url’ => $format[1]);
//echo “
format[1]:”.$format[1];
//echo “
format[0]:”.$format[0];
if ($meta[1] == “High Quality (320p)”) { $stream1 = $format[1]; }
if ($meta[1] == “Low Quality (480p)”) { $stream2 = $format[1]; }
if ($meta[1] == “High Quality (720p)”) { $stream3 = $format[1]; }
if (($meta[1] == “Low Quality”) && ($meta[0] == “3gp”)) { $stream4 = $format[1]; }
}
}
}
if (isset($stream4)) {
$flvUrl = $stream4;
}
else if (isset($stream3)) {
$flvUrl = $stream3;
}
else if (isset($stream2)) {
$flvUrl = $stream2;
}
else if (isset($stream1)) {
$flvUrl = $stream1;
} else {
$flvUrl = null;
}
return $flvUrl;
}
function getRemoteFile($url) {
// get the host name and url path
$parsedUrl = parse_url($url);
$host = $parsedUrl[‘host’];
if (isset($parsedUrl[‘path’])) {
$path = $parsedUrl[‘path’];
} else {
// the url is pointing to the host like http://www.mysite.com
$path = ‘/’;
}
if (isset($parsedUrl[‘query’])) {
$path .= ‘?’ . $parsedUrl[‘query’];
}
if (isset($parsedUrl[‘port’])) {
$port = $parsedUrl[‘port’];
} else {
// most sites use port 80
$port = ’80’;
}
$timeout = 10;
$response = ”;
// connect to the remote server
$fp = @fsockopen($host, ’80’, $errno, $errstr, $timeout );
if( !$fp ) {
echo “Cannot retrieve $url”;
} else {
// send the necessary headers to get the file
fputs($fp, “GET $path HTTP/1.0\r\n” .
“Host: $host\r\n” .
“User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3\r\n” .
“Accept: */*\r\n” .
“Accept-Language: en-us,en;q=0.5\r\n” .
“Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n” .
“Keep-Alive: 300\r\n” .
“Connection: keep-alive\r\n” .
“Referer: http://$host\r\n\r\n”);
// retrieve the response from the remote server
while ( $line = fread( $fp, 4096 ) ) {
$response .= $line;
}
fclose( $fp );
// strip the headers
$pos = strpos($response, “\r\n\r\n”);
$response = substr($response, $pos + 4);
}
return $response;
}
}
?>
[/sourcecode]