From 310c615d3e79d03f9d56d722cf2e511d78809276 Mon Sep 17 00:00:00 2001
From: Oliver Bartsch <bo@cedev.de>
Date: Tue, 26 Apr 2022 21:56:59 +0200
Subject: [PATCH] [BUGFIX] Add maxwidth / maxheight parameters to YouTube
 oembed url

When uploading new assets to the filelist,
the metadata (e.g. width and height) are
automatically extracted from the corresponding
files. This does not work for online media files,
e.g. a YouTube video. Therefore, the corresponding
services' oembed API is used to retrieve the
related metadata.

YouTube however changed their oembed API recently
to always set a width of "200" and a height of "113"
by default. This is obviously far too small for any
use case.

Since YouTube is following the oembed specification
(https://oembed.com/#section2.2), it's possible to
provide the "maxwidth" and "maxheight" parameters
to the oembed URL. This way YouTube returns
meaningful values for width and height.

Actually a similar change was already done to
the Vimeo integration in #85176. Vimeo however
supports the custom "width" parameter, which is
not mentioned in the specification and also not
supported by YouTube.

Resolves: #97481
Related: #85176
Releases: main, 11.5, 10.4
Change-Id: If902cf17b12fc510592a48828d8304fad42e2bfa
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74454
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
---
 .../core/Classes/Resource/OnlineMedia/Helpers/YouTubeHelper.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/YouTubeHelper.php b/typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/YouTubeHelper.php
index 1d6198476045..557fe396bdb1 100644
--- a/typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/YouTubeHelper.php
+++ b/typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/YouTubeHelper.php
@@ -101,7 +101,7 @@ class YouTubeHelper extends AbstractOEmbedHelper
     protected function getOEmbedUrl($mediaId, $format = 'json')
     {
         return sprintf(
-            'https://www.youtube.com/oembed?url=%s&format=%s',
+            'https://www.youtube.com/oembed?url=%s&format=%s&maxwidth=2048&maxheight=2048',
             rawurlencode(sprintf('https://www.youtube.com/watch?v=%s', rawurlencode($mediaId))),
             rawurlencode($format)
         );
-- 
GitLab