function emvideo_youtube_extract in Embedded Media Field 6
hook emvideo_PROVIDER_extract this is called to extract the video code from a pasted URL or embed code.
Parameters
$code: an optional string with the pasted URL or embed code
Return value
either an array of regex expressions to be tested, or a string with the video code to be used if the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array. otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
File
- contrib/
emvideo/ providers/ youtube.inc, line 322 - This include processes youtube.com media files for use by emfield.module.
Code
function emvideo_youtube_extract($code = '') {
// Special extraction for playlists.
$playlist_regex = array(
'@youtube\\.com/p/([^"\\& ]+)@i',
// A playlist
'@youtube\\.com/view_play_list\\?p=([^"\\& ]+)@i',
);
foreach ($playlist_regex as $regex) {
if (preg_match($regex, trim($code), $matches)) {
return 'PLAYLIST_' . $matches[1];
}
}
// Single videos.
// src="http://www.youtube.com/v/nvbQQnvxXDk"
// http://youtube.com/watch?v=nvbQQnvxXDk
// http://www.youtube.com/watch?v=YzFCA-xUc8w&feature=dir
return array(
'@youtube\\.com/v/([^\\?"\\& ]+)@i',
'@youtube\\.com/watch\\?v=([^"\\& ]+)@i',
'@youtube\\.com/\\?v=([^"\\& ]+)@i',
);
}