feat: add cache busting and hls query param
This commit is contained in:
@@ -91,7 +91,7 @@ export const goToNextEpisode = async (): Promise<void> => {
|
||||
// load new video (keep preferences)
|
||||
const preferredQuality = safeLocalStorage.getItem("mal:preferred-quality") || "best";
|
||||
const source = state.modeSources[fallback];
|
||||
const nextSourceURL = `${state.streamURL}?mode=${encodeURIComponent(fallback)}&token=${encodeURIComponent(source.token)}${preferredQuality !== "best" ? `&quality=${encodeURIComponent(preferredQuality)}` : ""}`;
|
||||
const nextSourceURL = `${state.streamURL}?mode=${encodeURIComponent(fallback)}&token=${encodeURIComponent(source.token)}${source.type === "m3u8" ? "&hls=1" : ""}${preferredQuality !== "best" ? `&quality=${encodeURIComponent(preferredQuality)}` : ""}`;
|
||||
loadVideoSource(nextSourceURL, source.type);
|
||||
if (!state.video.paused) {
|
||||
state.video.play().catch(() => undefined);
|
||||
|
||||
@@ -120,7 +120,7 @@ const initPlayer = (): void => {
|
||||
const streamToken = state.modeSources[state.currentMode]?.token;
|
||||
if (streamToken) {
|
||||
const source = state.modeSources[state.currentMode];
|
||||
const url = `${state.streamURL}?mode=${encodeURIComponent(state.currentMode)}&token=${encodeURIComponent(streamToken)}${preferredQuality !== "best" ? `&quality=${encodeURIComponent(preferredQuality)}` : ""}`;
|
||||
const url = `${state.streamURL}?mode=${encodeURIComponent(state.currentMode)}&token=${encodeURIComponent(streamToken)}${source?.type === "m3u8" ? "&hls=1" : ""}${preferredQuality !== "best" ? `&quality=${encodeURIComponent(preferredQuality)}` : ""}`;
|
||||
loadVideoSource(url, source?.type);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ export const streamUrlForMode = (mode: string, quality?: string): string => {
|
||||
if (!src?.token) return "";
|
||||
|
||||
let url = `${state.streamURL}?mode=${encodeURIComponent(mode)}&token=${encodeURIComponent(src.token)}`;
|
||||
if (src.type === "m3u8") {
|
||||
url += "&hls=1";
|
||||
}
|
||||
if (quality && quality !== "best") {
|
||||
url += `&quality=${encodeURIComponent(quality)}`;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ const shouldUseHLS = (type: string | undefined, url: string): boolean => {
|
||||
if (type === "m3u8") return true;
|
||||
try {
|
||||
const parsed = new URL(url, window.location.href);
|
||||
if (parsed.searchParams.get("hls") === "1") return true;
|
||||
return parsed.pathname.toLowerCase().endsWith(".m3u8");
|
||||
} catch {
|
||||
return url.toLowerCase().includes(".m3u8");
|
||||
|
||||
Reference in New Issue
Block a user