From 416fceba8814ea06360e72748b59f453f8637769 Mon Sep 17 00:00:00 2001 From: bytedream Date: Thu, 3 Apr 2025 23:43:39 +0200 Subject: [PATCH] Update match function to manually specify media type --- src/entries/contentScript/main.ts | 23 +++++++++++++++++++---- src/entries/player/player.ts | 5 +++-- src/lib/match.ts | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/entries/contentScript/main.ts b/src/entries/contentScript/main.ts index 94d34a4..573e556 100644 --- a/src/entries/contentScript/main.ts +++ b/src/entries/contentScript/main.ts @@ -35,13 +35,28 @@ async function main() { } let url: string | null; + let urlType: 'hls' | 'native'; try { - url = await match.match(re); + const matchResult = await match.match(re); + if (matchResult && typeof matchResult === 'string') { + url = matchResult; + urlType = url.includes('.m3u8') ? 'hls' : 'native'; + } else if (matchResult && typeof matchResult === 'object') { + if ('hls' in matchResult) { + url = matchResult['hls']; + urlType = 'hls'; + } else if ('native' in matchResult) { + url = matchResult['native']; + urlType = 'native'; + } + } } catch { return; } - if (!url) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + if (!url || !urlType) { return; } @@ -50,7 +65,7 @@ async function main() { await chrome.runtime.sendMessage({ action: 'ff2mpv', url: url }); } - if (match.replace && !url.includes('.m3u8')) { + if (match.replace && urlType !== 'hls') { // this destroys all intervals that may spawn popups or events let intervalId = window.setInterval(() => {}, 0); while (intervalId--) { @@ -81,7 +96,7 @@ async function main() { chrome.runtime.getURL( `src/entries/player/player.html?id=${match.id}&url=${encodeURIComponent(url)}&domain=${ window.location.hostname - }` + }&type=${urlType}` ) ); } diff --git a/src/entries/player/player.ts b/src/entries/player/player.ts index a5a5543..7403236 100644 --- a/src/entries/player/player.ts +++ b/src/entries/player/player.ts @@ -31,6 +31,7 @@ export async function play(videoElem: HTMLVideoElement) { const id = urlQuery.get('id') as string; const url = decodeURIComponent(urlQuery.get('url') as string); const domain = urlQuery.get('domain') as string; + const urlType = urlQuery.get('urlType') as string; const match = matches[id]; if (match === undefined) { @@ -38,9 +39,9 @@ export async function play(videoElem: HTMLVideoElement) { } document.title = `Stream Bypass (${domain})`; - if (new URL(url).pathname.endsWith('.m3u8')) { + if (urlType === 'hls') { await playHls(url, domain, videoElem); - } else { + } else if (urlType === 'native') { await playNative(url, domain, videoElem); } } diff --git a/src/lib/match.ts b/src/lib/match.ts index 2969384..23a832e 100644 --- a/src/lib/match.ts +++ b/src/lib/match.ts @@ -9,7 +9,7 @@ export interface Match { regex: RegExp[]; notice?: string; - match(match: RegExpMatchArray): Promise; + match(match: RegExpMatchArray): Promise; } export const Doodstream: Match = {