mehulmpt
mehulmpt

Reputation: 16587

How To Grab Youtube Download Links Decrypting Cipher Used by Youtube?

I'm working on a small project which downloads youtube video. I came across a stunning site:

http://vimow.com/watch?v=VID_ID_HERE

Suprisingly, every video works here and streams perfectly with clean youtube video links but I'm not able to figure out how this guy is extracting video links cleanly. (This works even for VEVO and Sony Copyrighted to YouTube videos)

I googled and found that youtube has installed certain ciphers to encode their URL paths and have a similar script to decipher that. I'm not sure how to implement that. I'm just able to create a poor set of code which uses fake user agent to browse to mobile view of youtube and get only HD MP4 link.

How Do I implement this? Or can anyone tell me how that vimow site is working?

And for those interested in my code till now:

<?php

if(!empty($_GET['url'])) { 
    $url = "https://www.youtube.com/watch?v=".$_GET['url'];

$ch1= curl_init();
curl_setopt ($ch1, CURLOPT_URL, "$url" );
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1,CURLOPT_VERBOSE,1);
//curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5');
curl_setopt ($ch1, CURLOPT_REFERER,'http://www.google.com');  //just a fake referer
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1,CURLOPT_POST,0);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 20);

$htmlContent= curl_exec($ch1);;
$source = urldecode($htmlContent);

$downloadURL = explode('url_encoded_fmt_stream_map', $source);
$downloadURL = substr($downloadURL[1], 0, 15600);

    $downloadURL = explode("url=", $downloadURL);

    $mp4link = str_split($downloadURL[1]);

    $newmp4link = array();

    for($i=0;$i<count($mp4link);$i++) {
    array_push($newmp4link, $mp4link[$i]);
    if($mp4link[$i] == '\\' || $mp4link[$i] == ',') {
        break;
    }
    }

    $newmp4link = join("", $newmp4link);

    $newmp4link = str_replace("\\","", $newmp4link);
    $newmp4link = str_replace(",","", $newmp4link);
    $newmp4link = str_replace(";","", $newmp4link);

    $ext = "mp4";

 function generateRandomString($length) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}
$rand = generateRandomString(100);
$target = "tmp/$rand.mp4";
copy($newmp4link, $target);
echo "$newmp4link";
header("Location: tmp/$rand.mp4");

?>

Upvotes: 0

Views: 5188

Answers (2)

Cobuz Alexandru
Cobuz Alexandru

Reputation: 322

I am one of the developers in that website, thanks for asking questions. Indeed we used the cypher algorithms to get into youtube videos, but we still had to stream the majority of the videos due to hard limits. There were less than 10k requests per ip, before getting blanks from docs. In the end, the streaming went thru our massive server clusters and we managed to grow based on them.

I hope this clears the old question and as a bonus our solution.

Upvotes: 1

Suleman Muhammad
Suleman Muhammad

Reputation: 68

This is how you get file links of youtube videos.

http://youtube.com/get_video_info?video_id=XXX 

but This site is doing a trick. they are not streaming from youtube but Google docs. so their links are in format of http://blah.c.docs.google.com/videoplayback instead of http://blah.c.docs.googlevideo.com/videoplayback. I am also searching for this method. so if you can find it let me know

Upvotes: 0

Related Questions