You are here

function youtube_build_remote_image_path in YouTube Field 7

Same name and namespace in other branches
  1. 8 youtube.module \youtube_build_remote_image_path()

Get YouTube image path by building correctly formed URL.

Parameters

string|null $video_id: (optional) The ID of the video to grab the thumbnail from.

string|null $version: (optional) Which version of the thumbnail to grab.

Return value

string|null The youtube.com image path to the specified version/video.

2 calls to youtube_build_remote_image_path()
theme_youtube_thumbnail in ./youtube.theme.inc
Theme function for thumbnails.
youtube_get_remote_image in ./youtube.inc
Retrieves the thumbnail image for a given video from YouTube.

File

./youtube.inc, line 241
YouTube field helper functions.

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/questions/2068344/how-to-get-thumbnail-of-youtube-video-link-using-youtube-api
  $versions = array(
    '0',
    'hqdefault',
    'mqdefault',
    'maxresdefault',
    'default',
    '1',
    '2',
    '3',
  );
  if (!$video_id || !in_array($version, $versions)) {
    return;
  }
  $version_path = 'http://img.youtube.com/vi/' . $video_id . '/' . $version . '.jpg';
  return url($version_path);
}