feat: add type field to ModeSource and pass to loadVideoSource
This commit is contained in:
@@ -8,6 +8,7 @@ import { updateOverlay, isAutoplayEnabled, switchEpisodeRange } from "./ui";
|
||||
import { markEpisodeTransition } from "../progress";
|
||||
import { safeLocalStorage } from "../storage";
|
||||
import { completeAnime } from "./complete";
|
||||
import { loadVideoSource } from "../video";
|
||||
|
||||
/**
|
||||
* Handles video end: either marks complete or loads next episode.
|
||||
@@ -89,8 +90,9 @@ export const goToNextEpisode = async (): Promise<void> => {
|
||||
|
||||
// load new video (keep preferences)
|
||||
const preferredQuality = safeLocalStorage.getItem("mal:preferred-quality") || "best";
|
||||
state.video.src = `${state.streamURL}?mode=${encodeURIComponent(fallback)}&token=${encodeURIComponent(state.modeSources[fallback].token)}${preferredQuality !== "best" ? `&quality=${encodeURIComponent(preferredQuality)}` : ""}`;
|
||||
state.video.load();
|
||||
const source = state.modeSources[fallback];
|
||||
const nextSourceURL = `${state.streamURL}?mode=${encodeURIComponent(fallback)}&token=${encodeURIComponent(source.token)}${preferredQuality !== "best" ? `&quality=${encodeURIComponent(preferredQuality)}` : ""}`;
|
||||
loadVideoSource(nextSourceURL, source.type);
|
||||
if (!state.video.paused) {
|
||||
state.video.play().catch(() => undefined);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { setupSegmentEditor } from "./skip/editor";
|
||||
import { setupThumbnails } from "./episodes/thumbnails";
|
||||
import { markEpisodeTransition, saveEndedProgress, setupProgress } from "./progress";
|
||||
import { safeLocalStorage } from "./storage";
|
||||
import { destroyVideoSource, loadVideoSource } from "./video";
|
||||
import {
|
||||
absoluteTimeFromDisplay,
|
||||
absoluteTimeFromRatio,
|
||||
@@ -49,6 +50,7 @@ const showPreviewPopover = (): void => {
|
||||
};
|
||||
|
||||
const teardownPlayer = (): void => {
|
||||
destroyVideoSource();
|
||||
cleanup?.();
|
||||
cleanup = null;
|
||||
currentContainer = null;
|
||||
@@ -117,7 +119,9 @@ const initPlayer = (): void => {
|
||||
const preferredQuality = safeLocalStorage.getItem("mal:preferred-quality") || "best";
|
||||
const streamToken = state.modeSources[state.currentMode]?.token;
|
||||
if (streamToken) {
|
||||
state.video.src = `${state.streamURL}?mode=${encodeURIComponent(state.currentMode)}&token=${encodeURIComponent(streamToken)}${preferredQuality !== "best" ? `&quality=${encodeURIComponent(preferredQuality)}` : ""}`;
|
||||
const source = state.modeSources[state.currentMode];
|
||||
const url = `${state.streamURL}?mode=${encodeURIComponent(state.currentMode)}&token=${encodeURIComponent(streamToken)}${preferredQuality !== "best" ? `&quality=${encodeURIComponent(preferredQuality)}` : ""}`;
|
||||
loadVideoSource(url, source?.type);
|
||||
}
|
||||
|
||||
setupProgress();
|
||||
|
||||
@@ -33,6 +33,7 @@ const parseModeSources = (v: unknown): Record<string, ModeSource> => {
|
||||
const qualities = value.qualities;
|
||||
out[key] = {
|
||||
token: value.token,
|
||||
type: typeof value.type === "string" ? value.type : undefined,
|
||||
subtitles,
|
||||
qualities: isStringArray(qualities) ? qualities : undefined,
|
||||
};
|
||||
@@ -97,7 +98,7 @@ export const switchMode = (mode: string): void => {
|
||||
"[data-quality-select]",
|
||||
) as HTMLSelectElement | null;
|
||||
const url = streamUrlForMode(mode, qualitySelect?.value);
|
||||
loadVideoSource(url);
|
||||
loadVideoSource(url, state.modeSources[mode]?.type);
|
||||
|
||||
// Fallback: if the media element doesn't actually switch sources (some browsers can get "stuck"),
|
||||
// reload the page with the desired mode and resume time via sessionStorage.
|
||||
|
||||
@@ -11,7 +11,7 @@ export const switchQuality = (quality: string): void => {
|
||||
const url = streamUrlForMode(state.currentMode, quality);
|
||||
if (!url) return;
|
||||
safeLocalStorage.setItem("mal:preferred-quality", quality);
|
||||
loadVideoSource(url);
|
||||
loadVideoSource(url, state.modeSources[state.currentMode]?.type);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -203,6 +203,7 @@ export const initState = (c: HTMLElement): boolean => {
|
||||
const qualities = value.qualities;
|
||||
out[key] = {
|
||||
token: value.token,
|
||||
type: typeof value.type === "string" ? value.type : undefined,
|
||||
subtitles,
|
||||
qualities: isStringArray(qualities) ? qualities : undefined,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// stream source for a single mode (sub/dub)
|
||||
export interface ModeSource {
|
||||
token: string;
|
||||
type?: string;
|
||||
subtitles: SubtitleItem[];
|
||||
qualities?: string[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user