PDA

View Full Version : Youtube Download Link


wonko
04-15-2008, 09:02 AM
I'm trying to make a script where someone can enter the URL of a youtube video, and it puts out a donwload link to the .flv that the user can then download. I've been scouring the internet and I can't find a tutorial or anything, but I did manage to write this code which doesn't ouput anything for some reason:

<?php

$txt = file_get_contents('http://www.youtube.com/watch?v=i0TXut4Oc2g');

preg_match('/video_id:\'[\w]{11}\'/', $txt, $video_id_temp);
preg_match('/[\w]{11}/',$video_id_temp[0],$video_id_temp2);
$video_id = $video_id_temp2[0];

preg_match('/l:\'[\d]{1,15}\'/',$txt,$l_temp);
preg_match('/[\d]{1,15}/',$l_temp[0],$l_temp2);
$l = $l_temp2[0];

preg_match('/t:\'[\w]{32}\'/',$txt,$t_temp);
preg_match('/[\w]{32}/',$t_temp[0],$t_temp2);
$t = $t_temp2[0];

$test="&l=".$l;
$test2="&t=".$t;

$url="http://youtube.com/get_video.php?video_id=";

print "<td><tr><a href='".$url.$video_id.$test.$test2."'> Download it!</a></td></tr>";

?>

anyone know what's wrong? Also if anyone knows a site they can direct me to that'd be awesome

Iszak
04-15-2008, 09:47 AM
I suggest looking at scripts from userscripts.org although these are in javascript I'm sure it'll be no trouble changing it. It requires "greasemonkey" for firefox if you didn't know here are some samples. http://userscripts.org/scripts/search?q=youtube+download

wonko
04-16-2008, 12:28 AM
I think for those scripts to work the browser needs the actual youtube page to be open. Is there any way to do this with PHP? or why my PHP code isn't working?