Youtube
Youtube copied to clipboard
Improvements: Shorts video ID parsing support
@alaouy Thanks for this awesome plugin. We need to support new YouTube shorts.
I am using following for only parsing ID and everything is working fine including shorts videos.
/**
* @param string|null $url
* @return string|null
*/
public static function getYouTubeVideoIDFromUrl(?string $url)
{
// See https://stackoverflow.com/a/71006865/3501553
preg_match('/(youtu.*be.*)\/(watch\?v=|embed\/|v|shorts|)(.*?((?=[&#?])|$))/', $url, $matches);
return ($matches[3] ?? null);
}
I hope we can use this logic in \Alaouy\Youtube\Youtube::parseVidFromURL().