feat: add deep fallback for latest anime episodes

This commit is contained in:
2026-05-02 17:20:38 +02:00
committed by Mikkel Elvers
parent 8fb7b1b72f
commit dd301384c5
7 changed files with 120 additions and 21 deletions

View File

@@ -2,6 +2,7 @@ package playback
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
@@ -107,6 +108,31 @@ func (h *Handler) HandleWatchPage(w http.ResponseWriter, r *http.Request) {
log.Printf("watch data error: %v", err)
}
// Update episodes list if fallback has more
if watchData.FallbackEpisodes != nil {
maxCount := 0
for _, count := range watchData.FallbackEpisodes {
if count > maxCount {
maxCount = count
}
}
if maxCount > len(episodes.Data) {
// Add dummy episodes for the ones Jikan is missing
start := len(episodes.Data) + 1
for i := start; i <= maxCount; i++ {
dummy := jikan.Episode{
MalID: i,
Episode: fmt.Sprintf("Episode %d", i),
Title: fmt.Sprintf("Episode %d", i),
Images: &jikan.EpisodeImages{},
}
dummy.Images.Jpg.ImageURL = dummy.GetFallbackImage(id)
episodes.Data = append(episodes.Data, dummy)
}
}
}
if err := templates.GetRenderer().ExecuteTemplate(w, "watch.gohtml", map[string]any{
"Anime": anime,
"Episodes": episodes.Data,