Skip to content

Commit 5d5ae75

Browse files
authored
fix(player): improve unlisted vimeo video handling (#1315)
1 parent 8889118 commit 5d5ae75

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

packages/vidstack/src/providers/vimeo/loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export class VimeoProviderLoader implements MediaProviderLoader<VimeoProvider> {
5050

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

53-
const { videoId } = resolveVimeoVideoId(src.src);
53+
const { videoId, hash } = resolveVimeoVideoId(src.src);
5454
if (videoId) {
55-
return getVimeoVideoInfo(videoId, abort).then((info) => (info ? info.poster : null));
55+
return getVimeoVideoInfo(videoId, abort, hash).then((info) => (info ? info.poster : null));
5656
}
5757

5858
return null;

packages/vidstack/src/providers/vimeo/provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class VimeoProvider
228228

229229
this._videoInfoPromise = promise;
230230

231-
getVimeoVideoInfo(videoId, abort)
231+
getVimeoVideoInfo(videoId, abort, this._hash)
232232
.then((info) => {
233233
promise.resolve(info);
234234
})

packages/vidstack/src/providers/vimeo/utils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { VimeoOEmbedData, VimeoVideoInfo } from './embed/misc';
22

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

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

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

14-
export async function getVimeoVideoInfo(videoId: string, abort: AbortController) {
15+
export async function getVimeoVideoInfo(
16+
videoId: string,
17+
abort: AbortController,
18+
videoHash?: string | null,
19+
) {
1520
if (infoCache.has(videoId)) return infoCache.get(videoId)!;
1621

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

19-
const oembedSrc = `https://vimeo.com/api/oembed.json?url=https://player.vimeo.com/video/${videoId}`;
24+
let oembedSrc = `https://vimeo.com/api/oembed.json?url=https://player.vimeo.com/video/${videoId}`;
25+
if (videoHash) {
26+
oembedSrc = oembedSrc.concat(`?h=${videoHash}`);
27+
}
2028

2129
const promise = window
2230
.fetch(oembedSrc, {

0 commit comments

Comments
 (0)