media-embed
media-embed copied to clipboard
Better support for vimeo
A couple things concerning the url-match for vimeo urls:
- Doesn't support player.vimeo.com/{id}
- Doesn't support videos from accounts set to "Unlisted", which can still be embedded, but do not appear in google search.
Regarding the unlisted videos, they have an additional identifier in their url, which causes the video not to load as it gets stripped from the iframe output. Example
https://www.vimeo.com/{video id}/{additional id}
Would you be able to make a PR here?
@dereuromark appreciate the quick response. Unfortunately my regex game isn't fantastic. I can give it a go, but I'm also not sure how to fulfill the requirements on this one since there's a single id() method for the MediaObject class. Would we add an additional method for the extra id, or return the full path as the id from the id() method, or something else?
Maybe the id is then x/y together?
Proposal for Better Vimeo Support
I've analyzed the current implementation and identified the issues:
Current Problems
Looking at data/stubs.php:96-103, the Vimeo stub has two limitations:
- Missing
player.vimeo.com/{id}URL support - Direct player URLs aren't recognized - Unlisted video handling - URLs with format
vimeo.com/{video_id}/{hash_id}have the hash stripped, causing embed failures
Proposed Solution
1. Update URL matching patterns:
'url-match' => [
'https?:\/\/(www\.)?vimeo.com\/(channels\/[a-zA-Z0-9]*\/)?([0-9]*)(?:\/([a-zA-Z0-9]+))?(\#t=(\d+)s)?',
'https?:\/\/player\.vimeo\.com\/video\/([0-9]+)',
],
2. Modify ID extraction logic:
- For standard URLs: Use video ID only
- For unlisted URLs: Combine both IDs as
{video_id}/{hash_id} - For player URLs: Extract ID directly
3. Update iframe-player template:
'iframe-player' => '//player.vimeo.com/video/$2',
This should support both single IDs and combined {id}/{hash} format.
4. Testing:
- Standard:
https://vimeo.com/123456789 - Unlisted:
https://vimeo.com/123456789/abc123def456 - Player:
https://player.vimeo.com/video/123456789 - Channels:
https://vimeo.com/channels/staffpicks/123456789
Implementation Effort
Low - primarily regex updates and ID handling logic
Would appreciate feedback on this approach! Happy to submit a PR if this looks good.