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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scheinarts
Forum Commoner
Posts: 52
Joined: Wed Jul 25, 2007 2:37 am

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

Post 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));

}
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

file() should do as well in this occasion if you know wht you're doing.
scheinarts
Forum Commoner
Posts: 52
Joined: Wed Jul 25, 2007 2:37 am

Post by scheinarts »

do you think you could show a simple example of how I would use that... im still learning php.. Thank you!
Post Reply