-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathpatterns.ts
More file actions
48 lines (45 loc) · 2.36 KB
/
Copy pathpatterns.ts
File metadata and controls
48 lines (45 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
export const AUDIO_EXTENSIONS =
/\.(m4a|m4b|mp4a|mpga|mp2|mp2a|mp3|m2a|m3a|wav|weba|aac|oga|spx)($|\?)/i;
export const VIDEO_EXTENSIONS = /\.(mp4|og[gv]|webm|mov|m4v)(#t=[,\d+]+)?($|\?)/i;
export const HLS_EXTENSIONS = /\.(m3u8)($|\?)/i;
export const DASH_EXTENSIONS = /\.(mpd)($|\?)/i;
// Match Mux m3u8 URLs without the extension so users can use hls.js with Mux by adding the `.m3u8` extension. https://regexr.com/7um5f
export const MATCH_URL_MUX = /stream\.mux\.com\/(?!\w+\.m3u8)(\w+)/;
export const MATCH_URL_YOUTUBE =
/(?:youtu\.be\/|youtube(?:-nocookie|education)?\.com\/(?:embed\/|v\/|watch\/|watch\?v=|watch\?.+&v=|shorts\/|live\/))((\w|-){11})|youtube\.com\/playlist\?list=|youtube\.com\/user\//;
export const MATCH_URL_VIMEO = /vimeo\.com\/(?!progressive_redirect).+/;
export const MATCH_URL_WISTIA =
/(?:wistia\.(?:com|net)|wi\.st)\/(?:medias|embed)\/(?:iframe\/)?([^?]+)/;
export const MATCH_URL_SPOTIFY = /open\.spotify\.com\/(\w+)\/(\w+)/i;
export const MATCH_URL_TWITCH = /(?:www\.|go\.)?twitch\.tv\/([a-zA-Z0-9_]+|(videos?\/|\?video=)\d+)($|\?)/;
export const MATCH_URL_TIKTOK = /tiktok\.com\/(?:player\/v1\/|share\/video\/|@[^/]+\/video\/)([0-9]+)/;
export const MATCH_URL_PEERTUBE = /(?:videos\/(?:watch|embed)|\/w)\/([^/?#&\s]+)/;
const canPlayFile = (url: string, test: (u: string) => boolean) => {
if (Array.isArray(url)) {
for (const item of url) {
if (typeof item === 'string' && canPlayFile(item, test)) {
return true;
}
if (canPlayFile(item.src, test)) {
return true;
}
}
return false;
}
return test(url);
};
export const canPlay = {
html: (url: string) =>
canPlayFile(url, (u: string) => AUDIO_EXTENSIONS.test(u) || VIDEO_EXTENSIONS.test(u)),
hls: (url: string) => canPlayFile(url, (u: string) => HLS_EXTENSIONS.test(u)),
dash: (url: string) => canPlayFile(url, (u: string) => DASH_EXTENSIONS.test(u)),
mux: (url: string) => MATCH_URL_MUX.test(url),
youtube: (url: string) => MATCH_URL_YOUTUBE.test(url),
vimeo: (url: string) =>
MATCH_URL_VIMEO.test(url) && !VIDEO_EXTENSIONS.test(url) && !HLS_EXTENSIONS.test(url),
wistia: (url: string) => MATCH_URL_WISTIA.test(url),
spotify: (url: string) => MATCH_URL_SPOTIFY.test(url),
twitch: (url: string) => MATCH_URL_TWITCH.test(url),
tiktok: (url: string) => MATCH_URL_TIKTOK.test(url),
peertube: (url: string)=> MATCH_URL_PEERTUBE.test(url)
};