Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a youtube playlist thumbnail?

Is there a way to get youtube playlist thumbnail like how you can get a thumbnail of a video, explained here: How do I get a YouTube video thumbnail from the YouTube API?

like image 705
varchar1 Avatar asked May 17 '12 01:05

varchar1


People also ask

Can you give a playlist a thumbnail on YouTube?

Hi Silence Nogood, there isn't any way to add custom artwork to a YouTube playlist. You can choose which video and thumbnail displays.

How do I add a thumbnail to my playlist?

Mouse over to the right-hand side where you will see the Edit button. This will show you all of the different videos that are attached to that specific playlist. Choose which video you would like to have as the playlist thumbnail, on the right-hand side you can click on the More button and Set Playlist Thumbnail.


2 Answers

With the YouTube API v3, you can get the playlist thumbnail using their v3/playlists endpoint and drilling down to items.snippet.thumbnails.high.url

For the following playlist:

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

YouTube's 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 response:

    {
     "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"
       }
      }
     ]
    }
like image 56
Robert Chen Avatar answered Nov 05 '22 05:11

Robert Chen


This is what worked for me. Similar to the other post regarding playlist items but I just changed the API call. Hope it helps.

//get playlist itmes

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

//decode response from youtube

$json = json_decode($data);

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

//each items in the response corresponds to a video in the playlist so lets get the first video (items[0]) get its snippet and corresponding thumbnails and we will take the url for the default size. If you want the second video use items [1] etc.

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

//set the videos alt tag as the snippet description

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

//echo the image url into an image tag

echo '<img src="'. $video_thumbnail .'" alt="'. $video_alt .'" />';
like image 35
willeisbrenner Avatar answered Nov 05 '22 06:11

willeisbrenner