If I have a YouTube video URL, is there any way to use PHP and cURL to get the associated thumbnail from the YouTube API?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Top answer optimized for manual use. Video ID token without separators enables selecting with a double click.
Each YouTube video has 4 generated images. They are predictably formatted as follows:
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of
1.jpg
,2.jpg
,3.jpg
) is:For the high quality version of the thumbnail use a url similar to this:
There is also a medium quality version of the thumbnail, using a url similar to the HQ:
For the standard definition version of the thumbnail, use a url similar to this:
For the maximum resolution version of the thumbnail use a url similar to this:
All of the above urls are available over http too. Additionally, the slightly shorter hostname
i3.ytimg.com
works in place ofimg.youtube.com
in the example urls above.Alternatively, you can use the YouTube Data API (v3) to get thumbnail images.
I found this nifty tool that allows you to create the image with the YouTube play button placed over the image:
Use this - img.youtube.com/vi/YouTubeID/ImageFormat.jpg here image formats are different like default, hqdefault, maxresdefault.
In YouTube API V3 we can also use these URLs for obtaining thumbnails... They are classified based on their quality.
And for the maximum resolution..
One advantage of these URLs over the URLs in the first answer is that these URLs don't get blocked by firewalls.
You can use YouTube Data API to retrieve video thumbnails, caption, description, rating, statistics and more. API version 3 requires a key*. Obtain the key and create a videos: list request:
Example PHP Code
Output
* Not only that you need a key, you might be asked for billing information depending on the number of API requests you plan to make. However, few million requests per day are free.
Source article.