[TASK] Better preview image quality for youtube videos 72/48972/5
authorRaphael Graf <graf@netvertising.ch>
Thu, 14 Jul 2016 12:02:51 +0000 (14:02 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 15 Jul 2016 19:30:24 +0000 (21:30 +0200)
Resolves: #77085
Releases: master, 7.6
Change-Id: Id5e5067b226431bff136339d14b9592d2aa3fdf6
Reviewed-on: https://review.typo3.org/48972
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/YouTubeHelper.php

index 89c8163..961e95e 100644 (file)
@@ -48,12 +48,16 @@ class YouTubeHelper extends AbstractOEmbedHelper
         $temporaryFileName = $this->getTempFolderPath() . 'youtube_' . md5($videoId) . '.jpg';
 
         if (!file_exists($temporaryFileName)) {
-            $previewImage = GeneralUtility::getUrl(
-                sprintf('https://img.youtube.com/vi/%s/0.jpg', $videoId)
-            );
-            if ($previewImage !== false) {
-                file_put_contents($temporaryFileName, $previewImage);
-                GeneralUtility::fixPermissions($temporaryFileName);
+            $tryNames = ['maxresdefault.jpg', '0.jpg'];
+            foreach ($tryNames as $tryName) {
+                $previewImage = GeneralUtility::getUrl(
+                    sprintf('https://img.youtube.com/vi/%s/%s', $videoId, $tryName)
+                );
+                if ($previewImage !== false) {
+                    file_put_contents($temporaryFileName, $previewImage);
+                    GeneralUtility::fixPermissions($temporaryFileName);
+                    break;
+                }
             }
         }