From 16c3350c13c791f6edeb01999090eac08fbbac24 Mon Sep 17 00:00:00 2001 From: Tim de Jong Date: Wed, 2 Apr 2014 20:12:04 +0200 Subject: [PATCH] Use high-resolution thumbnails --- includes/MediaYouTubeStreamWrapper.inc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/MediaYouTubeStreamWrapper.inc b/includes/MediaYouTubeStreamWrapper.inc index 72b03f0..b8d1076 100644 --- a/includes/MediaYouTubeStreamWrapper.inc +++ b/includes/MediaYouTubeStreamWrapper.inc @@ -18,7 +18,20 @@ class MediaYouTubeStreamWrapper extends MediaReadOnlyStreamWrapper { function getOriginalThumbnailPath() { $parts = $this->get_parameters(); - return 'http://img.youtube.com/vi/' . check_plain($parts['v']) . '/0.jpg'; + $v = check_plain($parts['v']); + // Attempt to pull a HD thumbnail from YouTube. If it exists pass it on + // otherwise pass on the smaller one. + $thumbname = drupal_tempnam('temporary://', 'youtube'); + $response = drupal_http_request('http://img.youtube.com/vi/' . $v . '/maxresdefault.jpg'); + if (!isset($response->error)) { + file_unmanaged_save_data($response->data, $thumbname, $replace = FILE_EXISTS_REPLACE); + } + if ((filesize($thumbname)) == 0) { + return 'http://img.youtube.com/vi/' . $v . '/0.jpg'; + } + else { + return 'http://img.youtube.com/vi/' . $v . '/maxresdefault.jpg'; + } } function getLocalThumbnailPath() { -- 1.8.4.2