aboutsummaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorPriyansh <[email protected]>2025-08-19 13:19:30 +0530
committerPriyansh <[email protected]>2025-08-19 13:19:30 +0530
commit9fbf28c2f77ec74c75a5274cbda897217ceaf571 (patch)
tree87dab6adda634a08b3b1cf74c0dd1e616113aa30 /services
parent6a65e3927506b0e46f18c9c1b41e952418bfd78e (diff)
downloadmetachan-9fbf28c2f77ec74c75a5274cbda897217ceaf571.tar.xz
metachan-9fbf28c2f77ec74c75a5274cbda897217ceaf571.zip
episodes router; anilist support; general fixes
Diffstat (limited to 'services')
-rw-r--r--services/anime/helpers.go18
-rw-r--r--services/anime/service.go2
2 files changed, 18 insertions, 2 deletions
diff --git a/services/anime/helpers.go b/services/anime/helpers.go
index 3982ba0..3231676 100644
--- a/services/anime/helpers.go
+++ b/services/anime/helpers.go
@@ -53,6 +53,22 @@ func getEpisodeCount(malAnime *jikan.JikanAnimeResponse, anilistAnime *anilist.A
return episodes
}
+// getEpisodeCountWithAiredFallback determines the total episode count, using aired episodes as fallback for long-running series
+func getEpisodeCountWithAiredFallback(malAnime *jikan.JikanAnimeResponse, anilistAnime *anilist.AnilistAnimeResponse, airedCount int) int {
+ totalFromAPIs := getEpisodeCount(malAnime, anilistAnime)
+
+ // For long-running series, if the aired count is significantly higher than API-reported total,
+ // use the aired count as a more accurate total (since APIs often report season/arc counts)
+ if airedCount > totalFromAPIs && airedCount > 100 {
+ // This indicates a long-running series where APIs might be reporting seasonal data
+ // For ongoing series, total should be at least as high as aired episodes
+ return airedCount
+ }
+
+ // For normal series, use the maximum from APIs
+ return max(totalFromAPIs, airedCount)
+}
+
// sortSeasonsByAirDate sorts the seasons array chronologically by air date
func sortSeasonsByAirDate(seasons *[]types.AnimeSeason) {
// First, collect seasons with valid dates
@@ -219,7 +235,7 @@ func getNextAiringEpisode(anilistAnime *anilist.AnilistAnimeResponse) types.Anim
// If AniList doesn't provide a direct next episode, but we have airing schedule nodes
// Find the next episode that hasn't aired yet
- if anilistAnime.Data.Media.AiringSchedule.Nodes != nil && len(anilistAnime.Data.Media.AiringSchedule.Nodes) > 0 {
+ if len(anilistAnime.Data.Media.AiringSchedule.Nodes) > 0 {
var nextAiringEpisode types.AnimeAiringEpisode
for _, node := range anilistAnime.Data.Media.AiringSchedule.Nodes {
diff --git a/services/anime/service.go b/services/anime/service.go
index 17336d8..6f61680 100644
--- a/services/anime/service.go
+++ b/services/anime/service.go
@@ -375,7 +375,7 @@ func (s *Service) GetAnimeDetailsWithSource(mapping *entities.AnimeMapping, sour
Licensors: generateLicensors(anime.Data.Licensors),
Seasons: seasons,
Episodes: types.AnimeEpisodes{
- Total: getEpisodeCount(anime, anilistAnime),
+ Total: getEpisodeCountWithAiredFallback(anime, anilistAnime, len(episodes.Data)),
Aired: len(episodes.Data),
Subbed: subbedCount,
Dubbed: dubbedCount,