diff --git a/src/patterns.ts b/src/patterns.ts index 37809c31..e3a87d13 100644 --- a/src/patterns.ts +++ b/src/patterns.ts @@ -1,8 +1,8 @@ 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; + /\.(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)($|[?#])/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 = diff --git a/test/patterns.js b/test/patterns.js new file mode 100644 index 00000000..2744dd74 --- /dev/null +++ b/test/patterns.js @@ -0,0 +1,19 @@ +import { test } from 'zora'; +import { canPlay } from '../src/patterns'; + +test('manifest URLs remain HLS or DASH sources when they contain media fragments', (t) => { + t.ok(canPlay.hls('https://example.com/live.m3u8#t=10.5')); + t.ok(canPlay.dash('https://example.com/movie.mpd#t=258')); + t.notOk(canPlay.html('https://example.com/live.m3u8#t=10.5')); + t.notOk(canPlay.html('https://example.com/movie.mpd#t=258')); +}); + +test('audio and video extensions accept fragments and query strings', (t) => { + t.ok(canPlay.html('https://example.com/audio.mp3#t=5')); + t.ok(canPlay.html('https://example.com/movie.mp4#t=10.5')); + t.ok(canPlay.html('https://example.com/movie.mp4#chapter=1')); + t.ok(canPlay.html('https://example.com/movie.mp4?token=abc#t=10.5')); + t.ok(canPlay.hls('https://example.com/live.m3u8?token=abc#t=10')); + t.notOk(canPlay.html('https://example.com/movie.mp4x#t=10')); + t.notOk(canPlay.dash('https://example.com/movie.mpdx#t=10')); +});