Skip to content

Commit

Permalink
support unlisted video url format
Browse files Browse the repository at this point in the history
  • Loading branch information
jamosmk7 committed Jul 6, 2023
1 parent 8f2255a commit ded310c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion resources/views/services/vimeo.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<x-embed-responsive-wrapper :aspect-ratio="$aspectRatio">
<iframe src="https://player.vimeo.com/video/{{ $videoId }}" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
<iframe src="https://player.vimeo.com/video/{{ $videoId }}@if($videoHash)?h={{ $videoHash}}@endif" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
</x-embed-responsive-wrapper>
17 changes: 9 additions & 8 deletions src/Services/Vimeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@ class Vimeo extends ServiceBase
{
public static function detect(Url $url): bool
{
return (new self($url))->videoId() !== null;
return (new self($url))->parseUrl() !== null;
}

protected function viewData(): array
{
return [
'videoId' => $this->videoId(),
];
return $this->parseUrl();
}

/**
* @link https://stackoverflow.com/a/16841070/3498182
*/
protected function videoId(): ?string
protected function parseUrl(): ?array
{
preg_match('/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/', $this->url, $match);

preg_match('/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})\/([a-z0-9]+)[?]?.*/', $this->url, $match);
if (array_key_exists(5, $match)) {
return $match[5];
return [
'videoId' => $match[5],
'videoHash' => isset($match[6]) ? $match[6] : NULL
];
}

return null;
Expand Down

0 comments on commit ded310c

Please sign in to comment.