Hi, my name is Felipe (aka Sabino) and I am new here! This is my first post!
I am working on a code to make you grab a direct MP4 file from the vk.com (a russian facebook like social network)
My goal is to use another player with the file, like jPlayer, for example.
Here is what I've got so far:
I know it's ugly coded, but still, I just want to make it work.
<?php
//pretending to be a browser
function download_pretending($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)')
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_REFERER, 'http://vk.com/');
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
}//function download_pretending($url,$user_agent)
$url = $_GET["url"];
$id = $_GET["id"];
$hash = $_GET["hash"];
$url = $url . "&id=" . $id . "&hash=" . $hash . "&hd=2";
$pagina = download_pretending($url,'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10');
$host = get_string_between($pagina, 'host=', '&');
echo $host;
echo "<br>";
$ps = array();
$count = preg_match_all('/<source[^>]*>(.*?)<\/source>/is', $pagina, $match);
for ($i = 0; $i < $count; ++$i) {
$ps[] = $match[0][$i];
}
// Function to get the MP4 file URL from the page
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
//I know I can make a for, I was lazy
echo '<br>';
echo get_string_between($match[0][0], 'src="', '" type=');
echo '<br>';
echo get_string_between($match[0][1], 'src="', '" type=');
echo '<br>';
echo get_string_between($match[0][2], 'src="', '" type=');
echo '<br>';
echo get_string_between($match[0][3], 'src="', '" type=');
echo '<br>';
?>
If you test with this url: http://vk.com/video_ext.php?oid=15318088&id=151930229&hash=e5fb57179b1830c3&hd=1
The result will be something like this:
http://cs12492.vk.me/u15318088/videos/aa6b0afa06.720.mp4
http://cs12492.vk.me/u15318088/videos/aa6b0afa06.480.mp4
http://cs12492.vk.me/u15318088/videos/aa6b0afa06.360.mp4
http://cs12492.vk.me/u15318088/videos/aa6b0afa06.240.mp4
But if I try to access any of those links, I gives me a 404 error, from vk.com
So, I don't know if this is a protection, if the link works only for the IP that loads the page, don't know...
If you want to try the script, go here:
http://sabino.net16.net/vk/?url=http://vk.com/video_ext.php?oid=15318088&id=151930229&hash=e5fb57179b1830c3&hd=1
Can someone help me?
Thanks in advance!