Get youtube download token code

Started on the old forum in November 2009 · view the original in the archive · old links redirect here

6 replies · 3,894 views · started 17 years ago · 1 min read

3 participants
GumSlone Administrator Principal · 1,690 posts #1
<?
$token_code = get_video_token($_REQUEST['vid']);
if($token_code == false)exit(0);
else echo $token_code;

function get_video_token($youtube_id,$extra='')
{
	/* STEP 2. visit the homepage to set the cookie properly */
		$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg'; 
		$headers[] = 'Connection: Keep-Alive'; 
		$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'; 
		$user_agent = '"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11';
		$url = 'http://www.youtube.com/';
		$ckfile = tempnam ("/tmp", "CURLCOO".rand(1,99)."KIE");
		$ch = curl_init ($url);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
		curl_setopt($ch, CURLOPT_HEADER, 1); 
		curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

		curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
		curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
		$output = curl_exec ($ch);
		$info_url = 'http://www.youtube.com/get_video_info?video_id='.$youtube_id.'';
		/* STEP 3. visit cookiepage */
		$ch = curl_init ($info_url);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
		curl_setopt($ch, CURLOPT_HEADER, 0); 
		curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
		curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
		curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); 
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
		$output = curl_exec ($ch);
		$vars = explode('&', $output);
		foreach($vars as $var){ //search the headers for the location url of youtube video
			$variable = explode('=', $var, 2);
			$$variable[0] = $variable[1];
		}
	if($token!="")
	{
	return $token;
	} else return false;
}
?>

if someone knows other ways please let me know

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

subzero Super moderator Fellow · 3,954 posts #2

I use YouTube script that will search for videos

this what i use as download page

<?php

$item = $_POST['item'];

function getContent($url) {
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);

    ob_start();
    curl_exec ($ch);
    curl_close ($ch);
    $string = ob_get_contents();
    ob_end_clean();
    return $string;    
}
function fetch_headers($url) {
	$headers = array();
	$url = trim($url);

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, 1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_NOBODY ,1);
	$data = curl_exec($ch);
	$errormsg = curl_error($ch);
	curl_close($ch);
					
	$headers = explode("\n", $data);
	return $headers;
}
function getYoutubeToken($id) {
	$path = "http://www.youtube.com/get_video_info?";
	$cont = getContent($path."&video_id=".$id);
	parse_str($cont, $opts);
	return $opts['token'];
}

$videoItem = trim($_GET['item']);
$videoType = "";
$videoPath = "http://www.youtube.com/get_video";

if ($_GET['type'] != "0") {
	$videoType = "&fmt=".$_GET['type'];
}
if ($videoItem != "") {
	$videoTokn = getYoutubeToken($videoItem);
	$videoURL = $videoPath."?video_id=".$videoItem."&t=".$videoTokn.$videoType;
	$headers = fetch_headers($videoURL);
	for ($i=0; $i<count($headers); $i++) {
		if (strstr($headers[$i], "ocation:")) {
			$str1 = explode("ocation:", $headers[$i]);
			$link = trim($str1[1]);
			break;
		}
	}
	header("Location: ".$link);
	exit;
}
?>

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

GumSlone Administrator Principal · 1,690 posts #3

shh... why the site adds

????: Coding-Talk /t/4013-get-youtube-download-token-code

to all posts 😳

<span class="copyright">????: Coding-Talk <a href="http://coding-talk.com/f46/get-youtube-download-token-code-5153/">http://coding-talk.com/f46/get-youtube-download-token-code-5153/</a></span>

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

subzero Super moderator Fellow · 3,954 posts #4

i dont know bro

added ?? 

Got to test it lol

its not always gets added in code it

when ppl using scripting.

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

GiLL Senior · 356 posts #5

in every post when people post code it added auto and make error for new users lol must be add // front if its a ads

left wap stuff

subzero Super moderator Fellow · 3,954 posts #7

Thank god for that error i did try to edit your post lol

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close