Skip to content

Commit

Permalink
support unlisted video url format (#19)
Browse files Browse the repository at this point in the history
* support unlisted video url format

* fix for parsing when no hash is present

* make second param non-greedy
  • Loading branch information
jamosmk7 authored Aug 11, 2023
1 parent 8f2255a commit 9f4ad84
Show file tree
Hide file tree
Showing 4 changed files with 14 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
2 changes: 2 additions & 0 deletions tests/Rules/EmbeddableUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function test_it_passes_a_validUrl_for_any_service()
'https://miro.com/miroverse/category/workshops/remote-ux-workshops',
'http://www.slideshare.net/haraldf/business-quotes-for-2011',
'https://vimeo.com/148751763',
'https://vimeo.com/148751763/243529c0ef',
'https://vimeo.com/148751763/243529c0ef?share=copy',
'https://youtu.be/dQw4w9WgXcQ',
'https://www.youtube.com/embed/dQw4w9WgXcQ',
];
Expand Down
2 changes: 2 additions & 0 deletions tests/Services/VimeoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ protected function validUrls(): array
{
return [
'https://vimeo.com/148751763',
'https://vimeo.com/148751763/243529c0ef',
'https://vimeo.com/148751763/243529c0ef?share=copy',
];
}
}

0 comments on commit 9f4ad84

Please sign in to comment.