You are here

function MediaYouTubeStreamWrapper::getLocalThumbnailPath in Media: YouTube 7.2

Same name and namespace in other branches
  1. 7.3 includes/MediaYouTubeStreamWrapper.inc \MediaYouTubeStreamWrapper::getLocalThumbnailPath()
  2. 7 includes/MediaYouTubeStreamWrapper.inc \MediaYouTubeStreamWrapper::getLocalThumbnailPath()

File

includes/MediaYouTubeStreamWrapper.inc, line 37
Extends the MediaReadOnlyStreamWrapper class to handle YouTube videos.

Class

MediaYouTubeStreamWrapper
Create an instance like this: $youtube = new MediaYouTubeStreamWrapper('youtube://v/[video-code]');

Code

function getLocalThumbnailPath() {
  $parts = $this
    ->get_parameters();

  // There's no need to hide thumbnails, always use the public system rather
  // than file_default_scheme().
  $local_path = 'public://media-youtube/' . check_plain($parts['v']) . '.jpg';
  if (!file_exists($local_path)) {
    $dirname = drupal_dirname($local_path);
    file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
    $response = drupal_http_request($this
      ->getOriginalThumbnailPath());
    if (!isset($response->error)) {
      file_unmanaged_save_data($response->data, $local_path, TRUE);
    }
    else {
      @copy($this
        ->getOriginalThumbnailPath(), $local_path);
    }
  }
  return $local_path;
}