how to show youtube video thumbnails

╄→гoц情女王★ 提交于 2019-12-03 10:09:11

问题


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&hl=en_US&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/-L8DFfSJbqU&hl=en_US&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:


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




回答2:


You can try for different types of YouTube videos thumbnails by using these urls -

For the default & normal quality thumbnail:

http://img.youtube.com/vi/<youtube-video-id>/default.jpg

For the high quality (HQ) thumbnail:

http://img.youtube.com/vi/<youtube-video-id>/hqdefault.jpg

There is also a medium quality thumbnail:

http://img.youtube.com/vi/<youtube-video-id>/mqdefault.jpg

For the maximum resolution thumbnail:

http://img.youtube.com/vi/<youtube-video-id>/maxresdefault.jpg

For eg .

YouTube link - http://www.youtube.com/watch?v=4EvNxWhskf8
YouTube video id - 4EvNxWhskf8

So that -

<img src="http://img.youtube.com/vi/4EvNxWhskf8/hqdefault.jpg" title="YouTube Video" alt="YouTube Video" />



回答3:


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: Developers Guide




回答4:


easily you can go to my website i created an application for this purpose,

http://shofnee.com/metal_shofnee/apps/youtube_app/youtube_app.php

also this is the code i wrote to get this application live with php language

 <?php
                //getting and validating the embed code
                $cde = $_POST['txt_embd'];
                if(!empty($cde))
                {
                $part_one_cde = explode("/",$cde);

                $part_2_cde = explode("?",$part_one_cde[4]);

                $img_1 = "http://img.youtube.com/vi/$part_2_cde[0]/0.jpg";
                $img_2 = "http://img.youtube.com/vi/$part_2_cde[0]/1.jpg";
                $img_3 = "http://img.youtube.com/vi/$part_2_cde[0]/2.jpg";

                echo "Img 1";
                echo "<br />";
                echo "<img src=\"$img_3\" width=\"100\" height=\"100\" />";
                echo"<br /><br />";
                echo "Img 2";
                echo "<br />";
                echo "<img src=\"$img_2\" width=\"150\" height=\"150\" />";
                echo"<br /><br />";
                echo "Img 3";
                echo "<br />";
                echo "<img src=\"$img_1\" width=\"200\" height=\"200\" />";

                }
                else
                {
                echo "Please put any embed code to get it's pics ...";  

                }
                ?>



回答5:


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.




回答6:


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&hl=en_US&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/-L8DFfSJbqU&hl=en_US&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&hl=en_US&fs=1

then this is video id:

-L8DFfSJbqU

so your thumbnail link is:

http://img.youtube.com/vi/-L8DFfSJbqU/default.jpg


来源:https://stackoverflow.com/questions/3405059/how-to-show-youtube-video-thumbnails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!