fix: stop autoplay after final episode

This commit is contained in:
2026-04-18 23:48:33 +02:00
parent ed73400b83
commit e336e2aa40
3 changed files with 8 additions and 0 deletions

View File

@@ -93,6 +93,7 @@ func (h *Handler) HandleWatchPage(w http.ResponseWriter, r *http.Request) {
MalID: data.MalID,
Title: data.Title,
CurrentEpisode: data.CurrentEpisode,
TotalEpisodes: anime.Episodes,
StartTimeSeconds: data.StartTimeSeconds,
CurrentStatus: data.CurrentStatus,
InitialMode: data.InitialMode,

View File

@@ -14,6 +14,7 @@ type WatchPageData struct {
MalID int
Title string
CurrentEpisode string
TotalEpisodes int
StartTimeSeconds float64
CurrentStatus string
InitialMode string
@@ -196,6 +197,7 @@ templ VideoPlayer(data WatchPageData) {
<div
class="flex flex-col gap-4 w-full"
data-mal-id={ fmt.Sprintf("%d", data.MalID) }
data-total-episodes={ fmt.Sprintf("%d", data.TotalEpisodes) }
data-video-player
data-stream-url="/watch/proxy/stream"
data-current-episode={ data.CurrentEpisode }

View File

@@ -48,6 +48,7 @@ const initPlayer = (): void => {
const streamURL = container.getAttribute('data-stream-url') || '/watch/proxy/stream'
const currentEpisode = container.getAttribute('data-current-episode') || '1'
const malID = Number.parseInt(container.getAttribute('data-mal-id') || '', 10)
const totalEpisodes = Number.parseInt(container.getAttribute('data-total-episodes') || '0', 10)
const startTimeSeconds = Number.parseFloat(container.getAttribute('data-start-time-seconds') || '0')
const modeSources = JSON.parse(container.getAttribute('data-mode-sources') || '{}')
const availableModes = JSON.parse(container.getAttribute('data-available-modes') || '[]')
@@ -603,6 +604,10 @@ const initPlayer = (): void => {
const currentEpisode = Number.parseInt(pathParts[3], 10)
if (Number.isNaN(currentEpisode)) return
if (Number.isInteger(totalEpisodes) && totalEpisodes > 0 && currentEpisode >= totalEpisodes) {
return
}
const nextEpisode = currentEpisode + 1
markEpisodeTransition(nextEpisode)
const nextUrl = `/watch/${animeID}/${nextEpisode}`