Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getVideoInfo($url) {
- if (preg_match("/(?:youtube(?:-nocookie)?\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^\"&?\/ ]{11})/i", $url, $match)) {
- $thumb = "https://i.ytimg.com/vi/".$match[1]."/maxresdefault.jpg";
- $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");
- $video_info = json_decode($video_info);
- if (isset($video_info->items[0])) {
- $thumbs = $video_info->items[0]->snippet->thumbnails;
- end($thumbs);
- $key = key($thumbs);
- $thumb = $thumbs->$key->url;
- $ratio = $thumbs->$key->width / $thumbs->$key->height;
- return [
- 'source' => 'youtube',
- 'video_id' => $match[1],
- 'thumb' => $thumb,
- 'ratio' => $ratio,
- ];
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement