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.
There are a number of sample applications for the Javascript v3 client library that can be found here:
https://developers.google.com/youtube/v3/code_samples/javascript
The call you are probably after is PlaylistItems:list
and can be seen here:
https://developers.google.com/youtube/v3/docs/playlistItems/list
and can be called using:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&id=YOUR-PLAYLIST-ID&key={YOUR_API_KEY}
Something along these lines will get details of the first 50 records in a specified playlist using the Javascript client library. The result is stored in the response
object.
<!doctype html>
<html>
<head>
<title>YouTube</title>
</head>
<body>
<script>
function onGoogleLoad() {
gapi.client.setApiKey('{YOUR-API-KEY}');
gapi.client.load('youtube', 'v3', function() {
var request = gapi.client.youtube.playlistItems.list({
part: 'snippet',
playlistId: '{PLAYLIST-ID-HERE}',
maxResults: 50
});
request.execute(function(response) {
for (var i = 0; i < response.items.length; i++) {
console.log(response.items[i].snippet.title + " published at " + response.items[i].snippet.publishedAt)
}
});
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=onGoogleLoad"></script>
</body>
</html>
Best Answer
YouTube Data API v3 results are paginated. So you need to get the next page of results for the others.
Basically in the response you have nextPageToken.
To get the remaining results, do the same exact call but setting pageToken into that token you received.