mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-13 03:15:56 +00:00
add urlhelper to extract youtube video id from url
This commit is contained in:
@@ -487,4 +487,26 @@ class UrlHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static function url_to_youtube_vid($url) {
|
||||
$url = str_replace("youtube.com", "youtube-nocookie.com", $url);
|
||||
|
||||
$regexps = [
|
||||
"/\/\/www\.youtube-nocookie\.com\/v\/([\w-]+)/",
|
||||
"/\/\/www\.youtube-nocookie\.com\/embed\/([\w-]+)/",
|
||||
"/\/\/www\.youtube-nocookie\.com\/watch?v=([\w-]+)/",
|
||||
"/\/\/youtu.be\/([\w-]+)/",
|
||||
];
|
||||
|
||||
foreach ($regexps as $re) {
|
||||
$matches = [];
|
||||
|
||||
if (preg_match($re, $url, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user