public function MediaInternetYouTubeHandler::parse in Media: YouTube 7.2
Same name and namespace in other branches
- 7.3 includes/MediaInternetYouTubeHandler.inc \MediaInternetYouTubeHandler::parse()
- 7 includes/MediaInternetYouTubeHandler.inc \MediaInternetYouTubeHandler::parse()
3 calls to MediaInternetYouTubeHandler::parse()
- MediaInternetYouTubeHandler::claim in includes/
MediaInternetYouTubeHandler.inc - MediaInternetYouTubeHandler::getFileObject in includes/
MediaInternetYouTubeHandler.inc - MediaInternetYouTubeHandler::getOEmbed in includes/
MediaInternetYouTubeHandler.inc - Returns information about the media.
File
- includes/
MediaInternetYouTubeHandler.inc, line 14 - Extends the MediaInternetBaseHandler class to handle YouTube videos.
Class
- MediaInternetYouTubeHandler
- Implementation of MediaInternetBaseHandler.
Code
public function parse($embedCode) {
// http://youtube.com/watch/*
// http://youtube.com/embed/*
// http://youtube.com/v/*
// http://youtube.com/?v=*
// http://youtu.be/*
// http://gdata.youtube.com/feeds/api/videos/*
$patterns = array(
'@youtube\\.com/watch[#\\?].*?v=([^"\\& ]+)@i',
'@youtube\\.com/embed/([^"\\&\\? ]+)@i',
'@youtube\\.com/v/([^"\\&\\? ]+)@i',
'@youtube\\.com/\\?v=([^"\\& ]+)@i',
'@youtu\\.be/([^"\\&\\? ]+)@i',
'@gdata\\.youtube\\.com/feeds/api/videos/([^"\\&\\? ]+)@i',
);
foreach ($patterns as $pattern) {
preg_match($pattern, $embedCode, $matches);
// @TODO: Parse is called often. Refactor so that valid ID is checked
// when a video is added, but not every time the embedCode is parsed.
if (isset($matches[1]) && self::validId($matches[1])) {
return file_stream_wrapper_uri_normalize('youtube://v/' . $matches[1]);
}
}
}