fredericmay of LMWR
2/21/2017 - 3:03 PM

Retrieve the id regardless of the format of the youtube url

Retrieve the id regardless of the format of the youtube url

youtube.com/v/{vidid}
youtube.com/vi/{vidid}
youtube.com/?v={vidid}
youtube.com/?vi={vidid}
youtube.com/watch?v={vidid}
youtube.com/watch?vi={vidid}
youtu.be/{vidid}

PHP code: preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $link, $matches);

Player Background Thumbnail (480x360 pixels)
› https://i1.ytimg.com/vi/G0wGs3useV8/0.jpg

Start Thumbnail (120x90 pixels)
› https://i1.ytimg.com/vi/G0wGs3useV8/1.jpg

Middle Thumbnail (120x90 pixels)
› https://i1.ytimg.com/vi/G0wGs3useV8/2.jpg

End Thumbnail (120x90 pixels)
› https://i1.ytimg.com/vi/G0wGs3useV8/3.jpg

High Quality Thumbnail (480x360 pixels)
› https://i1.ytimg.com/vi/G0wGs3useV8/hqdefault.jpg

Medium Quality Thumbnail (320x180 pixels)
› https://i1.ytimg.com/vi/G0wGs3useV8/mqdefault.jpg

Normal Quality Thumbnail (120x90 pixels)
› https://i1.ytimg.com/vi/G0wGs3useV8/default.jpg

And additionally, the next two thumbnails may or may not exist. For HQ videos they exist.

Standard Definition Thumbnail (640x480 pixels)
› https://i1.ytimg.com/vi/G0wGs3useV8/sddefault.jpg

Maximum Resolution Thumbnail (1920x1080 pixels)
› https://i1.ytimg.com/vi/G0wGs3useV8/maxresdefault.jpg