views:

293

answers:

4

hi guys,

my site lets users upload the youtube video codes. I am trying to make playlist by showing the thumbnails of the uploaded videos and play the respective video after clicking on specific thumbnail.

i would like to know the method of getting the caption and the thumbnail pictures of those videos which has been uploaded using embed code of youtube?

Edit:

To make question more clear, my users uploads code like one given below:

<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/-L8DFfSJbqU&amp;hl=en_US&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/-L8DFfSJbqU&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>

so from those code how can i find the vedio id first then secondly the thumbnail picture?

+1  A: 

If you have your video id you could use links described in this article

The link format is following:

http://img.youtube.com/vi/VIDEO_ID/default.jpg

Update

If this is code you have:

<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/-L8DFfSJbqU&amp;hl=en_US&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/-L8DFfSJbqU&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>

then this is video link:

http://www.youtube.com/v/-L8DFfSJbqU&amp;hl=en_US&amp;fs=1

then this is video id:

-L8DFfSJbqU

so your thumbnail link is:

http://img.youtube.com/vi/-L8DFfSJbqU/default.jpg
ŁukaszW.pl
how can i get the video ID
KoolKabin
check the update ;)
ŁukaszW.pl
how to extract it using php? any suggestion
KoolKabin
you can use regular expression, for example this is regular expression that can help you "http://www.youtube.com/v/(.{11})". You can get it using this function http://php.net/manual/en/function.preg-match.php
ŁukaszW.pl
thnx it helped.... worked
KoolKabin
+2  A: 

Thumbnails you can load from video url.

VIDEO URL

http://www.youtube.com/watch?v=Xzf0rvQa4Mc

THUMBNAIL URL

http://i1.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg

http://i2.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg

http://i3.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg

http://i4.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg

It takes some time to replicate images to all thumbnails urls (maybe servers) for new videos.

If there is no thumbnail, it returns image with camera (exactly 893 bytes length).

EXAMPLE

http://i4.ytimg.com/vi/Xzf0rvQa4Md/default.jpg

retro
plz help me getting video id
KoolKabin
better with this regexp (youtube\.com\/(watch\?v=)?(v\/)?([\w\-]+)) it can handle both urls (with /v/ and with watch?v=)preg_match('/youtube\.com\/v\/([\w\-]+)/', $code, $match); echo $match[3];
retro
thnx it worked...
KoolKabin
No problem. But study GData API for youtube. If you are able to parse video ID now, you can fetch more informations (title, ...).
retro
+1  A: 

The GData API for youtube allos you to fetch information about feeds, users, video etc.

This link describes the section of the reply relating to thumbnails:

http://code.google.com/apis/youtube/2.0/reference.html#youtube_data_api_tag_media:thumbnail

Do not hardcode URLs because Google can change them whenever they like. Use the APIs.

Emyr
it was very useful about knowing the api... will be checking out it soon too
KoolKabin
+1  A: 

With YouTube API:

   /* Some stuff goes before here to initialize API connection */

   /* Then get started: */
   $yt = new Zend_Gdata_YouTube()
   $videoEntry = $yt->getVideoEntry('the0KZLEacs'); //Video-ID
   $videoThumbnails = $videoEntry->getVideoThumbnails()

   echo 'Video: ' . $videoEntry->getVideoTitle() . "\n";
   echo 'Video ID: ' . $videoEntry->getVideoId() . "\n";
   echo 'Updated: ' . $videoEntry->getUpdated() . "\n";
   echo 'Description: ' . $videoEntry->getVideoDescription() . "\n";
   echo 'Category: ' . $videoEntry->getVideoCategory() . "\n";
   echo 'Tags: ' . implode(", ", $videoEntry->getVideoTags()) . "\n";
   echo 'Watch page: ' . $videoEntry->getVideoWatchPageUrl() . "\n";
   echo 'Flash Player Url: ' . $videoEntry->getFlashPlayerUrl() . "\n";
   echo 'Duration: ' . $videoEntry->getVideoDuration() . "\n";
   echo 'View count: ' . $videoEntry->getVideoViewCount() . "\n";
   echo 'Rating: ' . $videoEntry->getVideoRatingInfo() . "\n";
   echo 'Geo Location: ' . $videoEntry->getVideoGeoLocation() . "\n";
   echo 'Recorded on: ' . $videoEntry->getVideoRecorded() . "\n";

Can all be found here: http://code.google.com/apis/youtube/2.0/developers_guide_php.html

sprain
how to extract the "the0KZLEacs" video id for the api from my above code
KoolKabin