function MediaYouTubeStreamWrapper::getLocalThumbnailPath in Media: YouTube 7.3
Same name and namespace in other branches
- 7 includes/MediaYouTubeStreamWrapper.inc \MediaYouTubeStreamWrapper::getLocalThumbnailPath()
- 7.2 includes/MediaYouTubeStreamWrapper.inc \MediaYouTubeStreamWrapper::getLocalThumbnailPath()
File
- includes/
MediaYouTubeStreamWrapper.inc, line 59 - 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();
$id = array_pop($parts);
$local_path = file_default_scheme() . '://media-youtube/' . check_plain($id) . '.jpg';
if (!file_exists($local_path)) {
// getOriginalThumbnailPath throws an exception if there are any errors
// when retrieving the original thumbnail from YouTube.
try {
$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 {
system_retrieve_file($this
->getOriginalThumbnailPath(), $local_path, FALSE, FILE_EXISTS_REPLACE);
}
} catch (Exception $e) {
// In the event of an endpoint error, use the mime type icon provided
// by the Media module.
$file = file_uri_to_object($this->uri);
$icon_dir = variable_get('media_icon_base_directory', 'public://media-icons') . '/' . variable_get('media_icon_set', 'default');
$local_path = file_icon_path($file, $icon_dir);
}
}
return $local_path;
}