Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/patterns.ts
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
19 changes: 19 additions & 0 deletions test/patterns.js
Original file line number Diff line number Diff line change
@@ -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'));
});