Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. function getVideoInfo($url) {
  2.     if (preg_match("/(?:youtube(?:-nocookie)?\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^\"&?\/ ]{11})/i", $url, $match)) {
  3.         $thumb = "https://i.ytimg.com/vi/".$match[1]."/maxresdefault.jpg";
  4.         $video_info = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&fields=items(snippet(thumbnails))&id=".$match[1]."&key=AIzaSyAdNFfW-9NVCOvU346sgh2_PFJSQpSFGJw");
  5.         $video_info = json_decode($video_info);
  6.         if (isset($video_info->items[0])) {
  7.             $thumbs = $video_info->items[0]->snippet->thumbnails;
  8.             end($thumbs);
  9.             $key = key($thumbs);
  10.             $thumb = $thumbs->$key->url;
  11.             $ratio = $thumbs->$key->width / $thumbs->$key->height;
  12.             return [
  13.                 'source' => 'youtube',
  14.                 'video_id' => $match[1],
  15.                 'thumb' => $thumb,
  16.                 'ratio' => $ratio,
  17.             ];
  18.         }
  19.     }
  20.     return false;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement