php - Comment obtenir une vignette vidéo YouTube de l'API YouTube

Mots clés : phpcurlyoutubeyoutube-apiyoutube-data-apiphp

meilleur 5 Réponses php - Comment obtenir une vignette vidéo YouTube de l'API YouTube

vote vote

92

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 
https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg 
https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg 
https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg 
https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg 
https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg 
vote vote

85

https://www.googleapis.com/youtube/v3/videos?key=YOUR_API_KEY&part=snippet&id=VIDEO_ID 
$data = file_get_contents("https://www.googleapis.com/youtube/v3/videos?key=YOUR_API_KEY&part=snippet&id=T0Jqdjbed40"); $json = json_decode($data); var_dump($json->items[0]->snippet->thumbnails); 
object(stdClass)#5 (5) {   ["default"]=>   object(stdClass)#6 (3) {     ["url"]=>     string(46) "https://i.ytimg.com/vi/T0Jqdjbed40/default.jpg"     ["width"]=>     int(120)     ["height"]=>     int(90)   }   ["medium"]=>   object(stdClass)#7 (3) {     ["url"]=>     string(48) "https://i.ytimg.com/vi/T0Jqdjbed40/mqdefault.jpg"     ["width"]=>     int(320)     ["height"]=>     int(180)   }   ["high"]=>   object(stdClass)#8 (3) {     ["url"]=>     string(48) "https://i.ytimg.com/vi/T0Jqdjbed40/hqdefault.jpg"     ["width"]=>     int(480)     ["height"]=>     int(360)   }   ["standard"]=>   object(stdClass)#9 (3) {     ["url"]=>     string(48) "https://i.ytimg.com/vi/T0Jqdjbed40/sddefault.jpg"     ["width"]=>     int(640)     ["height"]=>     int(480)   }   ["maxres"]=>   object(stdClass)#10 (3) {     ["url"]=>     string(52) "https://i.ytimg.com/vi/T0Jqdjbed40/maxresdefault.jpg"     ["width"]=>     int(1280)     ["height"]=>     int(720)   } } 
vote vote

73

Width | Height | URL ------|--------|---- 120   | 90     | https://i.ytimg.com/vi/<VIDEO ID>/1.jpg 120   | 90     | https://i.ytimg.com/vi/<VIDEO ID>/2.jpg 120   | 90     | https://i.ytimg.com/vi/<VIDEO ID>/3.jpg 120   | 90     | https://i.ytimg.com/vi/<VIDEO ID>/default.jpg 320   | 180    | https://i.ytimg.com/vi/<VIDEO ID>/mq1.jpg 320   | 180    | https://i.ytimg.com/vi/<VIDEO ID>/mq2.jpg 320   | 180    | https://i.ytimg.com/vi/<VIDEO ID>/mq3.jpg 320   | 180    | https://i.ytimg.com/vi/<VIDEO ID>/mqdefault.jpg 480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/0.jpg 480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/hq1.jpg 480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/hq2.jpg 480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/hq3.jpg 480   | 360    | https://i.ytimg.com/vi/<VIDEO ID>/hqdefault.jpg 
Width | Height | URL ------|--------|---- 640   | 480    | https://i.ytimg.com/vi/<VIDEO ID>/sd1.jpg 640   | 480    | https://i.ytimg.com/vi/<VIDEO ID>/sd2.jpg 640   | 480    | https://i.ytimg.com/vi/<VIDEO ID>/sd3.jpg 640   | 480    | https://i.ytimg.com/vi/<VIDEO ID>/sddefault.jpg 1280  | 720    | https://i.ytimg.com/vi/<VIDEO ID>/hq720.jpg 1920  | 1080   | https://i.ytimg.com/vi/<VIDEO ID>/maxresdefault.jpg 
vote vote

60

https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/default.jpg -   default https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg - medium  https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg - high https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/sddefault.jpg - standard 
https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg 
vote vote

50

http://i3.ytimg.com/vi/SomeVideoIDHere/0.jpg 
//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 file fwrite($fp, $rawdata);  // And then close it. fclose($fp); 

Questions similaires