diff --git a/static/player/episodes/nav.ts b/static/player/episodes/nav.ts index 463764b..9a50f67 100644 --- a/static/player/episodes/nav.ts +++ b/static/player/episodes/nav.ts @@ -91,7 +91,7 @@ export const goToNextEpisode = async (): Promise => { // 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); diff --git a/static/player/main.ts b/static/player/main.ts index cfc8974..ea58a6d 100644 --- a/static/player/main.ts +++ b/static/player/main.ts @@ -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); } diff --git a/static/player/source.ts b/static/player/source.ts index ec786ca..cb735d0 100644 --- a/static/player/source.ts +++ b/static/player/source.ts @@ -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)}`; } diff --git a/static/player/video.ts b/static/player/video.ts index 91d7a0e..6b0df55 100644 --- a/static/player/video.ts +++ b/static/player/video.ts @@ -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"); diff --git a/templates/base.gohtml b/templates/base.gohtml index 0e98d97..bea0dc0 100644 --- a/templates/base.gohtml +++ b/templates/base.gohtml @@ -19,14 +19,14 @@ - + - + - + {{block "scripts" .}}{{end}} diff --git a/templates/funcs.go b/templates/funcs.go index 4dc887e..5ba80ff 100644 --- a/templates/funcs.go +++ b/templates/funcs.go @@ -5,6 +5,7 @@ import ( "fmt" "html/template" "net/url" + "os" "slices" "strconv" "strings" @@ -284,3 +285,14 @@ func episodeRangeStart(epNum, step int) int { } return ((epNum-1)/step)*step + 1 } + +func assetURL(assetPath string) string { + info, err := os.Stat(strings.TrimPrefix(assetPath, "/")) + if err != nil { + return assetPath + } + + values := url.Values{} + values.Set("v", fmt.Sprintf("%d-%d", info.ModTime().Unix(), info.Size())) + return assetPath + "?" + values.Encode() +} diff --git a/templates/renderer.go b/templates/renderer.go index 9a688cd..103fb2c 100644 --- a/templates/renderer.go +++ b/templates/renderer.go @@ -69,6 +69,7 @@ func rendererFuncs() template.FuncMap { "urlquery": url.QueryEscape, "posterURL": posterURL, "episodeRangeStart": episodeRangeStart, + "assetURL": assetURL, } } diff --git a/templates/watch.gohtml b/templates/watch.gohtml index b61b31d..303b38c 100644 --- a/templates/watch.gohtml +++ b/templates/watch.gohtml @@ -1,5 +1,5 @@ {{define "title"}}Watch {{.Anime.Title}}{{end}} -{{define "scripts"}}{{end}} +{{define "scripts"}}{{end}} {{define "page_container"}}
{{template "content" .}}