Issue Bug Closed

#97446VimeoHelper and VimeoRenderer build wrong URLs

Gerald Rintisch 04/22/22, 10:18 updated 07/09/24, 12:46

Description

In Vimeo you can copy a link to a video in two different (relevant) ways:

Copy Video Link returns scheme

vimeo.com/<videocode>/<optionalPrivateCode>

Copy embed code returns scheme

<iframe src="https://player.vimeo.com/video/<videocode>?h=<optionalPrivateCode>"  ... ></iframe>

So here are 2 problems to solve:
1. The regex in \TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper::transformUrlToFile must adapted to also recognize the code of the embed snippet.
2. Storing (in \TYPO3\CMS\Core\Resource\Rendering\VimeoHelper::transformUrlToFile()) our outputting (in VimeoRenderer::createVimeoUrl()) must be adapted so that the created URL contains the paramater h (so .../<videocode>?h=<optionalPrivateCode>&... instead of .../<videocode>/<optionalPrivateCode>?...

Under the condition that the two parts are still stored with / a solution would be to write https://github.com/TYPO3/typo3/blob/main/typo3/sysext/core/Classes/Resource/Rendering/VimeoRenderer.php#L155

$videocode = $videoId;
if(str_contains('/', $videoId)){
    $videoIdElements = explode('/',$videoId);
    $videocode = $videoIdElements[0];
    $optionalPrivateCode = $videoIdElements[1];
    $urlParams[] = 'h=' . $optionalPrivateCode;
}

return sprintf('https://player.vimeo.com/video/%s?%s', $videocode, implode('&', $urlParams));

But I am sure here are people capable to make it more elegant…

Reviews 2

History 713

  1. Frank Nägler commented 07/12/22, 10:41

    Here is a kind of reference for possible URL schema: https://developer.vimeo.com/api/oembed/videos
    The whole parser looks a bit wired and should maybe be refactored. E.g. by using an URL object to parse the data instead of doing the string parsing with RegExp.
    Also, the tests should be checked and verified.

  2. Leonie Philine commented 07/25/22, 14:43

    There’s another issue in https://github.com/TYPO3/typo3/blob/ae00ad424a1b04ab30712d4558acab276396cb13/typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/VimeoHelper.php#L99

    rawurlencode(sprintf('https://vimeo.com/%s', rawurlencode($mediaId)))

    The media ID is double URL encoded. This causes the slash between video ID and video hash to be encoded as “%252F” rather than “%2F”. (The added “%25” is the second-time-encoded percent sigil.)

    Correct would be:

    rawurlencode(sprintf('https://vimeo.com/%s', $mediaId))

    Example with a fake ‘unlisted’ video URL:

    Original URL:
    @https://vimeo.com/123456789/abcdef1234@

    Correct (succeeding) encoded URL to attach to https://vimeo.com/api/oembed.json?width=2048&url=

    Incorrect (failing) encoded URL which TYPO3 actually attaches instead (with “%252F” rather than “%2F”):
    @https%3A%2F%2Fvimeo.com%2F123456789%252Fabcdef1234@

  3. Leonie Philine commented 07/25/22, 15:28

    Proposed elegant solution for the vimeo renderer (replacing lines 136-147 https://github.com/TYPO3/typo3/blob/main/typo3/sysext/core/Classes/Resource/Rendering/VimeoRenderer.php#L136-L137):

    protected function createVimeoUrl(array $options, FileInterface $file)
        {
            [$videoId, $videoHash] = explode('/', $this->getVideoIdFromFile($file), 2);
    
            $urlParams = [];
    
            if (!empty($videoHash)) {
                $urlParams[] = 'h=' . $videoHash;
            }
    
            // Rest of the method remains unchanged.
        }
  4. Markus Klein changed status New Accepted target version TYPO3 Version 11 10 12/16/22, 14:42

  5. Dmitry Dulepov commented 01/23/23, 10:11

    I came to a similar solution:

             $videoId = $this->getVideoIdFromFile($file);
             $urlParams = [];
    +        if (str_contains($videoId, '/')) {
    +            [$videoId, $privateId] = explode('/', $videoId, 2);
    +            $urlParams[] = 'h=' . htmlspecialchars($privateId);
    +        }
             if (!empty($options['autoplay'])) {
                 $urlParams[] = 'autoplay=1';
             }
  6. Gerrit Code Review pushed patch set 1 for main to change 77609 status Accepted Under Review 01/26/23, 12:36

  7. Gerrit Code Review pushed patch set 2 for main to change 77609 01/26/23, 14:57

  8. Gerrit Code Review pushed patch set 3 for main to change 77609 05/03/23, 09:52

  9. Gerrit Code Review pushed patch set 4 for main to change 77609 09/20/23, 13:43

  10. Gerrit Code Review pushed patch set 5 for main to change 77609 09/20/23, 13:45

  11. Gerrit Code Review pushed patch set 1 for 12.4 to change 81070 09/20/23, 14:21

  12. Philipp Kitzberger commented and changed status Under Review Resolved done 0 % 100 % 09/20/23, 14:35

    Applied in changeset commit:ef48a91c09a333399631af703980f5110c664f4f.

  13. Benni Mack changed status Resolved Closed 07/09/24, 12:46