Fetch YouTube video data with PHP 18 January, 2009

I’ve written a simple PHP5 class for fetching information about YouTube’s videos (nothing fancy). You can fetch title, description, key words, author, thumbnail URL, flv URL and you can save the flv file (like keepvid.com). You can grab the source code here. You can use it freely, just remember that I can’t guarantee anything.

You use the class like so:

$yt = new YouTubeFetcher ();
$yt->Fetch ( 'youtube url' ); // you can pass the URL to the constructor, and save a line

Then you have various getter methods you can use:

$yt->GetTitle ();
$yt->GetFlvUrl ();
...

And finally you can access the flv video file:

$flvVideo = $yt->GetVideoAsString (); // this will fetch the flv video into the $flvVideo variable
$yt->SaveVideo ( '/path/to/your/video.flv' ); // and this will save the flv video file to the local file system

If you wish to discuss this post please use twitter or contact me.

Comments

Inder January 26, 2009 at 7:57 pm

thx sir

i searched this script from long long time bye

Anil Dewani July 18, 2009 at 3:30 am

Thanks a lot. I was looking for this one.

L. Alexander February 14, 2012 at 1:55 am

Great class, thanks for the share and for the effort!

Nicholas Maietta December 29, 2012 at 8:43 am

Seems to me it’d send the entire contents to a variable, eating up memory. Plus there is the sneaky PHP execution time of 30 seconds for most hosts.

I propose a modifcation to this class to get content legnth and then get the file in 2mb chunks, saving each fetched offset chunk to the local file.

You can use cURLs’ context stream to help accomplish the chunking both on fetch and on save. I understand content-legth isn’t always available, but the method still applies. I would also

Keteki May 22, 2013 at 5:34 am

Hi Jan Hančič, thanks for the information. But i think, flv URL doesn’t fetch this days.