Jump to content

Why not working? cURL Testing - Trying to cURL videos from vk.com website


Recommended Posts

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.
//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>';

The result will be something like this:
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:
Can someone help me?

Thanks in advance!

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.