fix: stop autoplay after final episode
This commit is contained in:
@@ -93,6 +93,7 @@ func (h *Handler) HandleWatchPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
MalID: data.MalID,
|
MalID: data.MalID,
|
||||||
Title: data.Title,
|
Title: data.Title,
|
||||||
CurrentEpisode: data.CurrentEpisode,
|
CurrentEpisode: data.CurrentEpisode,
|
||||||
|
TotalEpisodes: anime.Episodes,
|
||||||
StartTimeSeconds: data.StartTimeSeconds,
|
StartTimeSeconds: data.StartTimeSeconds,
|
||||||
CurrentStatus: data.CurrentStatus,
|
CurrentStatus: data.CurrentStatus,
|
||||||
InitialMode: data.InitialMode,
|
InitialMode: data.InitialMode,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ type WatchPageData struct {
|
|||||||
MalID int
|
MalID int
|
||||||
Title string
|
Title string
|
||||||
CurrentEpisode string
|
CurrentEpisode string
|
||||||
|
TotalEpisodes int
|
||||||
StartTimeSeconds float64
|
StartTimeSeconds float64
|
||||||
CurrentStatus string
|
CurrentStatus string
|
||||||
InitialMode string
|
InitialMode string
|
||||||
@@ -196,6 +197,7 @@ templ VideoPlayer(data WatchPageData) {
|
|||||||
<div
|
<div
|
||||||
class="flex flex-col gap-4 w-full"
|
class="flex flex-col gap-4 w-full"
|
||||||
data-mal-id={ fmt.Sprintf("%d", data.MalID) }
|
data-mal-id={ fmt.Sprintf("%d", data.MalID) }
|
||||||
|
data-total-episodes={ fmt.Sprintf("%d", data.TotalEpisodes) }
|
||||||
data-video-player
|
data-video-player
|
||||||
data-stream-url="/watch/proxy/stream"
|
data-stream-url="/watch/proxy/stream"
|
||||||
data-current-episode={ data.CurrentEpisode }
|
data-current-episode={ data.CurrentEpisode }
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ const initPlayer = (): void => {
|
|||||||
const streamURL = container.getAttribute('data-stream-url') || '/watch/proxy/stream'
|
const streamURL = container.getAttribute('data-stream-url') || '/watch/proxy/stream'
|
||||||
const currentEpisode = container.getAttribute('data-current-episode') || '1'
|
const currentEpisode = container.getAttribute('data-current-episode') || '1'
|
||||||
const malID = Number.parseInt(container.getAttribute('data-mal-id') || '', 10)
|
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 startTimeSeconds = Number.parseFloat(container.getAttribute('data-start-time-seconds') || '0')
|
||||||
const modeSources = JSON.parse(container.getAttribute('data-mode-sources') || '{}')
|
const modeSources = JSON.parse(container.getAttribute('data-mode-sources') || '{}')
|
||||||
const availableModes = JSON.parse(container.getAttribute('data-available-modes') || '[]')
|
const availableModes = JSON.parse(container.getAttribute('data-available-modes') || '[]')
|
||||||
@@ -603,6 +604,10 @@ const initPlayer = (): void => {
|
|||||||
const currentEpisode = Number.parseInt(pathParts[3], 10)
|
const currentEpisode = Number.parseInt(pathParts[3], 10)
|
||||||
if (Number.isNaN(currentEpisode)) return
|
if (Number.isNaN(currentEpisode)) return
|
||||||
|
|
||||||
|
if (Number.isInteger(totalEpisodes) && totalEpisodes > 0 && currentEpisode >= totalEpisodes) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const nextEpisode = currentEpisode + 1
|
const nextEpisode = currentEpisode + 1
|
||||||
markEpisodeTransition(nextEpisode)
|
markEpisodeTransition(nextEpisode)
|
||||||
const nextUrl = `/watch/${animeID}/${nextEpisode}`
|
const nextUrl = `/watch/${animeID}/${nextEpisode}`
|
||||||
|
|||||||
Reference in New Issue
Block a user