Skip to content

Commit

Permalink
fix(player): improve unlisted vimeo video handling (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
faelmorais authored Jun 18, 2024
1 parent 8889118 commit 5d5ae75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/vidstack/src/providers/vimeo/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export class VimeoProviderLoader implements MediaProviderLoader<VimeoProvider> {

if (!isString(src.src)) return null;

const { videoId } = resolveVimeoVideoId(src.src);
const { videoId, hash } = resolveVimeoVideoId(src.src);
if (videoId) {
return getVimeoVideoInfo(videoId, abort).then((info) => (info ? info.poster : null));
return getVimeoVideoInfo(videoId, abort, hash).then((info) => (info ? info.poster : null));
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/vidstack/src/providers/vimeo/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class VimeoProvider

this._videoInfoPromise = promise;

getVimeoVideoInfo(videoId, abort)
getVimeoVideoInfo(videoId, abort, this._hash)
.then((info) => {
promise.resolve(info);
})
Expand Down
14 changes: 11 additions & 3 deletions packages/vidstack/src/providers/vimeo/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { VimeoOEmbedData, VimeoVideoInfo } from './embed/misc';

const videoIdRE = /(?:https:\/\/)?(?:player\.)?vimeo(?:\.com)?\/(?:video\/)?(\d+)(?:\?hash=(.*))?/;
const videoIdRE =
/(?:https:\/\/)?(?:player\.)?vimeo(?:\.com)?\/(?:video\/)?(\d+)(?:(?:\?hash=|\?h=|\/)(.*))?/;

const infoCache = new Map<string, VimeoVideoInfo>();

Expand All @@ -11,12 +12,19 @@ export function resolveVimeoVideoId(src: string) {
return { videoId: matches?.[1], hash: matches?.[2] };
}

export async function getVimeoVideoInfo(videoId: string, abort: AbortController) {
export async function getVimeoVideoInfo(
videoId: string,
abort: AbortController,
videoHash?: string | null,
) {
if (infoCache.has(videoId)) return infoCache.get(videoId)!;

if (pendingFetch.has(videoId)) return pendingFetch.get(videoId);

const oembedSrc = `https://vimeo.com/api/oembed.json?url=https://player.vimeo.com/video/${videoId}`;
let oembedSrc = `https://vimeo.com/api/oembed.json?url=https://player.vimeo.com/video/${videoId}`;
if (videoHash) {
oembedSrc = oembedSrc.concat(`?h=${videoHash}`);
}

const promise = window
.fetch(oembedSrc, {
Expand Down

0 comments on commit 5d5ae75

Please sign in to comment.