//Grab the default thumbnail image$attrs = $media->group->thumbnail[1]->attributes();$thumbnail = $attrs['url'];$thumbnail = substr($thumbnail, 0, -5);$thumb1 = $thumbnail."default.jpg";
// Grab the third thumbnail image$thumb2 = $thumbnail."2.jpg";
// Grab the fourth thumbnail image.$thumb3 = $thumbnail."3.jpg";
// Using simple cURL to save it your server.// You can extend the cURL below if you want it as fancy, just like// the rest of the folks here.
$ch = curl_init ("$thumb1");curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);$rawdata = curl_exec($ch);curl_close($ch);
// Using fwrite to save the above$fp = fopen("SomeLocationInReferenceToYourScript/AnyNameYouWant.jpg", 'w');
// Write the filefwrite($fp, $rawdata);
// And then close it.fclose($fp);
// Get image form video URL$url = $video['video_url'];
$urls = parse_url($url);
//Expect the URL to be http://youtu.be/abcd, where abcd is the video IDif ($urls['host'] == 'youtu.be') :
$imgPath = ltrim($urls['path'],'/');
//Expect the URL to be http://www.youtube.com/embed/abcdelseif (strpos($urls['path'],'embed') == 1) :
$imgPath = end(explode('/',$urls['path']));
//Expect the URL to be abcd onlyelseif (strpos($url,'/') === false):
$imgPath = $url;
//Expect the URL to be http://www.youtube.com/watch?v=abcdelse :
parse_str($urls['query']);
$imgPath = $v;
endif;
{"height":270,"width":480,"title":"example video for 2020","thumbnail_width":480,"html":"...","thumbnail_height":360,"version":"1.0","provider_name":"YouTube","author_url":"https:\/\/www.youtube.com\/channel\/UCza6VSQUzCON- AzlsrOLwaA","thumbnail_url":"https:\/\/i.ytimg.com\/vi\/xUeJdWYdMmQ\/hqdefault.jpg","author_name":"Pokics","provider_url":"https:\/\/www.youtube.com\/","type":"video"}
Now change your video ID and your API key to the your respective video-id and api-key and its response will be a JSON output providing you the four links in the thumbnails of snippet variable (if all are available).