How to get youtube playlist thumbnail?

Is there a way to get a thumbnail of a youtube playlist, for example, how can you get a thumbnail of the video described here: How to get a thumbnail of a YouTube video with the YouTube API?

+6
source share
3 answers

With the YouTube API v3, you can get a playlist thumbnail using the v3/playlists endpoint and drill up to items.snippet.thumbnails.high.url

For the following playlist:

https://www.youtube.com/playlist?list=PL50C17441DA8A565D

The YouTube API Explorer has a playlist endpoint:

https://developers.google.com/youtube/v3/docs/playlists/list

This is the API call:

GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=PL50C17441DA8A565D&key={YOUR_API_KEY}

And here is the answer:

  { "kind": "youtube#playlistListResponse", "items": [ { "kind": "youtube#playlist", "id": "PL50C17441DA8A565D", "snippet": { "title": "Jay Chou Playlist", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/kGbDymJ75PU/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/kGbDymJ75PU/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/kGbDymJ75PU/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "it23" } } ] } 
+5
source

This is what worked for me. Like another post regarding playlist elements, but I just changed the API call. Hope this helps.

// get the itmes playlist

 $data = file_get_contents("https://www.googleapis.com/youtube/v3/playlistItems?key=< YOUR API KEY >&part=snippet&playlistId="<Put your playlist id here>"); 

// decode the response from youtube

 $json = json_decode($data); 

// if you want to see the full answer, use print_r ($ json);

// each element in the response corresponds to a video in the playlist, therefore it allows us to get the first video (points [0]) to get its fragment and corresponding thumbnails, and we will take the url for the default size. If you want the second video to use elements [1], etc.

 $video_thumbnail = $json->items[0]->snippet->thumbnails->default->url; 

// set the video tag alt as a description of the fragment

 $video_alt = $json->items[0]->snippet->description; 

// echo image URL to image tag

 echo '<img src="'. $video_thumbnail .'" alt="'. $video_alt .'" />'; 
+3
source

There is no API for this purpose. Here is a workaround that I can think of.

1) What is the thumbnail for youtube playlist? Playing with my account and this seems to be the rule:

 if playlist has 5+ videos thumbnail = first 5 video images else if playlist has 1+ videos thumbnail = all video images else shows this list is empty 

2) Then you can use the same method to get thumbnails of the video.

3) combine images either on the client side (some CSS) or on the server side

-1
source

Source: https://habr.com/ru/post/915951/


All Articles