function youtube_build_remote_image_path in YouTube Field 8
Same name and namespace in other branches
- 7 youtube.inc \youtube_build_remote_image_path()
Get YouTube image path by building correctly formed URL.
Parameters
string $video_id: The ID of the video to grab the thumbnail from.
string $version: Which version of the thumbnail to grab. See $versions for options.
Return value
string|bool The youtube.com image path to the specified version/video. FALSE if the supplied version is not an option.
2 calls to youtube_build_remote_image_path()
- template_preprocess_youtube_thumbnail in ./
youtube.module - Prepares variables for the YouTube Thumbnail template.
- youtube_get_remote_image in ./
youtube.module - Retrieves the thumbnail image for a given video from YouTube.
File
- ./
youtube.module, line 440 - Youtube field module adds a field for YouTube videos.
Code
function youtube_build_remote_image_path($video_id = NULL, $version = '0') {
// The different versions of the image made available by YouTube.
// http://stackoverflow.com/a/2068371
$versions = [
'0',
'hqdefault',
'mqdefault',
'maxresdefault',
'default',
'1',
'2',
'3',
];
if (!$video_id || !in_array($version, $versions)) {
return FALSE;
}
$version_path = 'http://img.youtube.com/vi/' . $video_id . '/' . $version . '.jpg';
return Url::fromUri($version_path)
->toString();
}