php 如何显示 YouTube 视频缩略图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3405059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to show youtube video thumbnails
提问by KoolKabin
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.
我的网站允许用户上传 youtube 视频代码。我试图通过显示上传视频的缩略图来制作播放列表,并在点击特定缩略图后播放相应的视频。
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?
我想知道使用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?
因此,从这些代码中,我如何首先找到视频 ID,然后再找到缩略图?
回答by retro
Thumbnails you can load from video url.
您可以从视频 url 加载的缩略图。
VIDEO URL
视频网址
THUMBNAIL URL
缩略图网址
http://i1.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg
http://i2.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg
http://i1.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg
http://i2.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg
It takes some time to replicate images to all thumbnails urls (maybe servers) for new videos.
将图像复制到新视频的所有缩略图 URL(可能是服务器)需要一些时间。
If there is no thumbnail, it returns image with camera (exactly 893 bytes length).
如果没有缩略图,则返回带有相机的图像(正好 893 字节长度)。
EXAMPLE
例子
回答by Rohit Suthar
You can try for different types of YouTube videos thumbnails by using these urls -
您可以使用这些网址尝试不同类型的 YouTube 视频缩略图 -
For the default & normal quality thumbnail:
对于默认和正常质量的缩略图:
http://img.youtube.com/vi/<youtube-video-id>/default.jpg
For the high quality (HQ) thumbnail:
对于高质量 (HQ) 缩略图:
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" />
回答by sprain
With YouTube API:
使用 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
都可以在这里找到:开发人员指南
回答by shofnee
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
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 语言而编写的代码
<?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 ...";
}
?>
回答by ?ukaszW.pl
If you have your video id you could use links described in this article
如果您有视频 ID,则可以使用本文中描述的链接
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:
那么这是视频ID:
-L8DFfSJbqU
so your thumbnail link is:
所以你的缩略图链接是:
http://img.youtube.com/vi/-L8DFfSJbqU/default.jpg
回答by Emyr
The GData API for youtube allos you to fetch information about feeds, users, video etc.
youtube 的 GData API 允许您获取有关提要、用户、视频等的信息。
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
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.
不要对 URL 进行硬编码,因为 Google 可以随时更改它们。使用 API。