Skip to content

Commit

Permalink
Match params for unlisted videos (#43)
Browse files Browse the repository at this point in the history
- Increase regex matching to include h parameter value.
- Add h parameter to the video URL when present.
  • Loading branch information
xipasduarte authored Oct 24, 2024
1 parent 74bd3fd commit fc5ab4a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vimeo-video-element/vimeo-video-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import VimeoPlayerAPI from '@vimeo/player/dist/player.es.js';

const EMBED_BASE = 'https://player.vimeo.com/video';
const MATCH_SRC = /vimeo\.com\/(?:video\/)?(\d+)/;
const MATCH_SRC = /vimeo\.com\/(?:video\/)?(\d+)(?:\/([\w-]+))?/;

function getTemplateHTML(attrs) {
const iframeAttrs = {
Expand Down Expand Up @@ -39,6 +39,7 @@ function serializeIframeUrl(attrs) {

const matches = attrs.src.match(MATCH_SRC);
const srcId = matches && matches[1];
const hParam = matches && matches[2];

const params = {
// ?controls=true is enabled by default in the iframe
Expand All @@ -50,6 +51,7 @@ function serializeIframeUrl(attrs) {
preload: attrs.preload ?? 'metadata',
transparent: false,
autopause: attrs.autopause,
h: hParam, // This param is required when the video is Unlisted.
};

return `${EMBED_BASE}/${srcId}?${serialize(params)}`;
Expand Down

0 comments on commit fc5ab4a

Please sign in to comment.