How do I get a YouTube video thumbnail from the YouTube API?
Each YouTube video has four generated images. They are predictably formatted as follows:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (i.e., one of 1.jpg
, 2.jpg
, 3.jpg
) is:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
For the high quality version of the thumbnail use a URL similar to this:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
There is also a medium quality version of the thumbnail, using a URL similar to the HQ:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
For the standard definition version of the thumbnail, use a URL similar to this:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
For the maximum resolution version of the thumbnail use a URL similar to this:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
All of the above URLs are available over HTTP too. Additionally, the slightly shorter hostname i3.ytimg.com
works in place of img.youtube.com
in the example URLs above.
Alternatively, you can use the YouTube Data API (v3) to get thumbnail images.
How to get a YouTube video thumbnail using API?
You can get your image using this url . In this tutorial "I-tBhNwVa7w" is YouTube vidio ID . you can replace it with other video ID.
http://img.youtube.com/vi/I-tBhNwVa7w/0.jpg (full size).
http://img.youtube.com/vi/I-tBhNwVa7w/1.jpg (thumbnail).
http://img.youtube.com/vi/I-tBhNwVa7w/2.jpg (thumbnail).
http://img.youtube.com/vi/I-tBhNwVa7w/3.jpg (thumbnail).
http://img.youtube.com/vi/I-tBhNwVa7w/maxresdefault.jpg (maximum resolution ).
http://img.youtube.com/vi/I-tBhNwVa7w/sddefault.jpg (standard default).
http://img.youtube.com/vi/I-tBhNwVa7w/mqdefault.jpg (medium quality).
http://img.youtube.com/vi/I-tBhNwVa7w/hqdefault.jpg (high quality).
http://img.youtube.com/vi/I-tBhNwVa7w/default.jpg (default).
For More detail please visit to https://developers.google.com/youtube/v3/
How to get video thumbnail from YouTube URL and set it to image view in android
You can use YouTube API v3 to retrieve related video thumbnail info like title, image and length:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet&fields=items/snippet(title,thumbnails),items/contentDetails/duration&key={{ YOUR_API_KEY }}&id={{ YOUR_YOUTUBE_VIDEO_ID }}
Or this url
if you only want to get only thumbnail image with medium size:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet&fields=items/snippet(title,thumbnails/medium/url),items/contentDetails/duration&key={{ YOUR_API_KEY }}&id={{ YOUR_YOUTUBE_VIDEO_ID }}
Your response may look like this:
{
"items": [
{
"snippet": {
"title": "F..k This S..t I'm Out",
"thumbnails": {
"medium": {
"url": "https://i.ytimg.com/vi/5FjWe31S_0g/mqdefault.jpg"
}
}
},
"contentDetails": {
"duration": "PT25S"
}
}
]
}
How to get the youtube video thumbnail in java swing from the youtube api
Assuming you get the SearchListResponse
from youtube v3 data api. Now you can easily fetch the thumb url using following code.
SearchListResponse response = // data fetched from yt data api.
java.util.List<SearchResult> searchResultList = response.getItems();
for (SearchResult sr : searchResultList) {
String thumburl = sr.getSnippet().getThumbnails().getDefault().getUrl();
//for high resolution you can use: sr.getSnippet().getThumbnails().getHigh().getUrl();
}
related links. https://developers.google.com/youtube/v3/docs/search/list
How do I get a YouTube video thumbnail from the YouTube API?
Each YouTube video has four generated images. They are predictably formatted as follows:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (i.e., one of 1.jpg
, 2.jpg
, 3.jpg
) is:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
For the high quality version of the thumbnail use a URL similar to this:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
There is also a medium quality version of the thumbnail, using a URL similar to the HQ:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
For the standard definition version of the thumbnail, use a URL similar to this:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
For the maximum resolution version of the thumbnail use a URL similar to this:
https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
All of the above URLs are available over HTTP too. Additionally, the slightly shorter hostname i3.ytimg.com
works in place of img.youtube.com
in the example URLs above.
Alternatively, you can use the YouTube Data API (v3) to get thumbnail images.
Wanted to get the full size thumbnails from a youtube video
You may refer with this thread. It stated that each YouTube video has 4 generated images. 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:https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
For the high quality version of the thumbnail use a url similar to
this:https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
There is also a medium quality version of the thumbnail, using a url
similar to the HQ:https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
For the standard definition version of the thumbnail, use a url
similar to this:https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
For the maximum resolution version of the thumbnail use a url similar
to this:https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
All of the above urls are available over http too. Additionally, the
slightly shorter hostnamei3.ytimg.com
works in place of
img.youtube.com
in the example urls above.
Also based from this link, be noted that YouTube only generates high-res stills for high-res videos. Hope this helps!
Get YouTube video thumbnail and use it with PHP
YouTube stores many different types of thumbnails on its server for different devices. You can access it by using the video id which
every YouTube video has. You can display the images on your website using a variable $link
which holds the id of the video and substituting it
in the place for video_ID in the link.
Low quality thumbnail:
http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/sddefault.jpg
Medium quality thumbnail:
http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/mqdefault.jpg
High quality thumbnail:
http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/hqdefault.jpg
Maximum quality thumbnail:
http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/maxresdefault.jpg
Example:
If you want to access the thumbnail of the following video:
https://www.youtube.com/watch?v=Q-GYwhqDo6o
Video ID : Q-GYwhqDo6o
So, this is how video thumbnail link looks like:
http://img.youtube.com/vi/Q-GYwhqDo6o/mqdefault.jpg
Hope it helps. Enjoy coding.
Related Topics
Finding the Longest Gap Between Multiple Intervals
Success Message Pop-Up After from Submit Button Clicked
Stop Inserting Data in the Database When Refreshing the Page
Displaying a Base64 Images from a Database Via PHP
Displaying Data from an Array in a HTML Table Using PHP
How to Get Values of Checkbox Array in Laravel 5
Convert Doc/Docx Files to Pdf Using PHP
How to Edit Specific Json Key Values Using PHP
Phpexcel Write Long Number in Cell
How Remove the Backslash ("\") in the Json Response Using PHP
How Does PHP 'Foreach' Actually Work
Invalid Argument Supplied For Foreach()
Warning: MySQL_Fetch_Array(): Supplied Argument Is Not a Valid MySQL Result
Why Would One Omit the Close Tag
How to Access and Manipulate Multi-dimensional Array by Key Names/Path