Skip to content

Commit

Permalink
Fix: Allow also custom links from vimeo
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Sep 13, 2021
1 parent 8d3f0d9 commit 322eedb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 9 additions & 3 deletions Classes/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,23 @@ public function youtube(
/**
* Grab the data of a publicly embeddable video hosted on vimeo
*
* @param string $id The "id" of a video
* @param string|null $id The "id" of a video
* @return array|null The data or null if there's an error
* @throws InfiniteRedirectionException|JsonException
* @throws InfiniteRedirectionException
* @throws JsonException
*/
public function vimeo(string $id): ?array
public function vimeo(?string $id = null): ?array
{
if (!$id) {
return null;
}

if (!strpos($id, 'https://vimeo.com/')) {
$id = str_replace('https://vimeo.com/', '', $id);
}

$url = urlencode('https://vimeo.com/' . $id);

$data = $this->getJson(
'https://vimeo.com/api/oembed.json?width=2560&url=' . $url,
'video',
Expand Down
7 changes: 2 additions & 5 deletions Classes/Service/ParseIDService.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function platform($url = null): ?string
* http://vimeo.com/album/2222222/video/11111111
* https://vimeo.com/11111111?param=test
* http://vimeo.com/11111111?param=test
* https://vimeo.com/jonnitto/carbonplausible
*
* @param string|integer $url The URL or the plain id
* @return string|null The video id extracted from url
Expand All @@ -83,11 +84,7 @@ public function vimeo($url = null): ?string
if (preg_match('%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$%im', $url, $regs)) {
return (string) $regs[3];
}
// The ID has to start with a number
if (preg_match('/^[0-9]/', $url)) {
return (string) $url;
}
return null;
return str_replace('https://vimeo.com/', '', (string) $url);
}

/**
Expand Down

0 comments on commit 322eedb

Please sign in to comment.