mirror of
https://github.com/bytedream/stream-bypass.git
synced 2025-05-09 12:15:14 +02:00
Use enum to specify media type
This commit is contained in:
parent
f6fcfd354a
commit
50f400b8b9
@ -1,6 +1,5 @@
|
||||
import type { Match } from '~/lib/match';
|
||||
import { getMatch } from '~/lib/match';
|
||||
import { Other, Redirect } from '~/lib/settings';
|
||||
import {getMatch, type Match, MatchMediaType} from '~/lib/match';
|
||||
import {Other, Redirect} from '~/lib/settings';
|
||||
|
||||
async function main() {
|
||||
let match: Match | null;
|
||||
@ -35,19 +34,19 @@ async function main() {
|
||||
}
|
||||
|
||||
let url: string | null;
|
||||
let urlType: 'hls' | 'native';
|
||||
let urlType: MatchMediaType | null;
|
||||
try {
|
||||
const matchResult = await match.match(re);
|
||||
if (matchResult && typeof matchResult === 'string') {
|
||||
url = matchResult;
|
||||
urlType = url.includes('.m3u8') ? 'hls' : 'native';
|
||||
urlType = url.includes('.m3u8') ? MatchMediaType.Hls : MatchMediaType.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';
|
||||
if (MatchMediaType.Hls in matchResult) {
|
||||
url = matchResult[MatchMediaType.Hls];
|
||||
urlType = MatchMediaType.Hls;
|
||||
} else if (MatchMediaType.Native in matchResult) {
|
||||
url = matchResult[MatchMediaType.Native];
|
||||
urlType = MatchMediaType.Native;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
@ -65,7 +64,7 @@ async function main() {
|
||||
await chrome.runtime.sendMessage({ action: 'ff2mpv', url: url });
|
||||
}
|
||||
|
||||
if (match.replace && urlType !== 'hls') {
|
||||
if (match.replace && urlType != MatchMediaType.Hls) {
|
||||
// this destroys all intervals that may spawn popups or events
|
||||
let intervalId = window.setInterval(() => {}, 0);
|
||||
while (intervalId--) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { matches } from '~/lib/match';
|
||||
import {matches, MatchMediaType} from '~/lib/match';
|
||||
import Hls from 'hls.js';
|
||||
import { UrlReferer } from '~/lib/settings';
|
||||
import {UrlReferer} from '~/lib/settings';
|
||||
|
||||
async function playNative(url: string, domain: string, videoElem: HTMLVideoElement) {
|
||||
await UrlReferer.set(new URL(url).hostname, domain);
|
||||
@ -31,7 +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 urlType = urlQuery.get('urlType') as MatchMediaType;
|
||||
|
||||
const match = matches[id];
|
||||
if (match === undefined) {
|
||||
@ -39,9 +39,9 @@ export async function play(videoElem: HTMLVideoElement) {
|
||||
}
|
||||
document.title = `Stream Bypass (${domain})`;
|
||||
|
||||
if (urlType === 'hls') {
|
||||
if (urlType === MatchMediaType.Hls) {
|
||||
await playHls(url, domain, videoElem);
|
||||
} else if (urlType === 'native') {
|
||||
} else if (urlType === MatchMediaType.Native) {
|
||||
await playNative(url, domain, videoElem);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,12 @@ export interface Match {
|
||||
regex: RegExp[];
|
||||
notice?: string;
|
||||
|
||||
match(match: RegExpMatchArray): Promise<string | { hls: string } | { native: string } | null>;
|
||||
match(match: RegExpMatchArray): Promise<string | {[MatchMediaType.Hls]: string} | {[MatchMediaType.Native]: string} | null>;
|
||||
}
|
||||
|
||||
export enum MatchMediaType {
|
||||
Hls = 'hls',
|
||||
Native = 'native',
|
||||
}
|
||||
|
||||
export const Doodstream: Match = {
|
||||
@ -129,7 +134,7 @@ export const LoadX: Match = {
|
||||
const videoSource: string = responseJson['videoSource'];
|
||||
|
||||
// extension of extracted url is '.txt', so we have to manually specify that it's a hls
|
||||
return {hls: videoSource.replace('\\/', '/')};
|
||||
return {[MatchMediaType.Hls]: videoSource.replace('\\/', '/')};
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user