Page 1 of 1

How can I get the equivalent of this without using curl?

Posted: Wed Dec 05, 2007 10:11 am
by scheinarts
Hi,

I recently came accross this code that take a youtube video url (for example:http://youtube.com/watch?v=iZdF9PgZ_Dk) and converts that url into a readable path location to the flv file for that movie so that the flash player can read it and play it. The only problem for me is that it uses curl, and hosting account that I have doesnt have it enabled.. its one of those cheap shared server plans... so I need to use the same code just with out the curl part... How would I accomplish this?

Thanks for any suggestions!

Code: Select all

ini_set("max_execution_time","3600");
$baseUrl = "http://www.youtube.com/v/%s";
$idVideo = "3IcwG0jUFxU";
$urlVideo = sprintf($baseUrl,$idVideo);
$baseVideoUrl = "http://www.youtube.com/get_video.php?%s";

ob_start();
// get via CuRL da great library so fine 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlVideo);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
$out = ob_get_clean();

$strs = explode("&t=",$out);
$final = explode("\n",$strs[1]);
$t = $final[0];
$finalUrlVideo = getVideoUrl($idVideo,$t);

$filv = file_get_contents($finalUrlVideo);
$fo = fopen("file.flv","w+");
$fw = fwrite($fo,$filv);
$fc = fclose($fo);

/* getVideoUrl ( string idVideo , string tValue ) */
function getVideoUrl ($id,$tval) {
global $baseVideoUrl;
return sprintf($baseVideoUrl,"video_id=".$id."&t=".trim($tval));

}

Posted: Wed Dec 05, 2007 10:19 am
by Mordred
file() should do as well in this occasion if you know wht you're doing.

Posted: Wed Dec 05, 2007 11:52 am
by scheinarts
do you think you could show a simple example of how I would use that... im still learning php.. Thank you!