From c423d8f3ede219eae8e3e003a3795a243f72881c Mon Sep 17 00:00:00 2001 From: chrispr Date: Mon, 11 Nov 2024 21:44:36 -0500 Subject: [PATCH] Added implementation of episode groups with overrides for finale --- AnimeAnnouncer/Program.cs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/AnimeAnnouncer/Program.cs b/AnimeAnnouncer/Program.cs index 92e373b..9d62fc0 100644 --- a/AnimeAnnouncer/Program.cs +++ b/AnimeAnnouncer/Program.cs @@ -197,8 +197,42 @@ namespace AnimeAnnouncer if(latestSeasonNumber != int.Parse(season)) { - Console.WriteLine($"Failing release due to TMDB's season number {latestSeasonNumber} not matching title season {season}"); - return; + var titleSeason = int.Parse(season); + bool seasonOverride = false; + if(latestSeasonNumber ==1 && titleSeason > 1 && latestEpisodeNumber > 3) + { //Check episode groups to see if this is a single-season default show + var showResult = await tmdbClient.GetTvShowAsync(supposedShowId, TMDbLib.Objects.TvShows.TvShowMethods.EpisodeGroups); + var seasonEpisodeGroup = showResult.EpisodeGroups.Results.FirstOrDefault(eg => eg.Name == "Seasons"); + if(seasonEpisodeGroup != null) + { //Evaluate using new episode group + var targetEpisodeGroup = await tmdbClient.GetTvEpisodeGroupsAsync(seasonEpisodeGroup.Id); + if(targetEpisodeGroup != null) + { + var targetSeason = targetEpisodeGroup.Groups.FirstOrDefault(g => g.Order == titleSeason); + if(targetSeason != null) + { //Episode_Type isn't making it with the current client, guess based on ordering + var targetFinale = targetSeason.Episodes.OrderByDescending(g => g.Order).FirstOrDefault(e => e.EpisodeType.Equals("finale", StringComparison.InvariantCultureIgnoreCase)); + //Confirm it's aired within the last week + if(targetFinale != null && targetEpisodeGroup.Groups.OrderByDescending(g => g.Order).FirstOrDefault() == targetSeason) + { //confirm the episode is marked as finale and that this season is the latest one in the episode group + Console.WriteLine($"!!Choosing S{titleSeason}E{targetFinale.Order + 1} for finale using episode groups"); + cachedShow.LatestSeasonNumber = latestSeasonNumber = titleSeason; + cachedShow.LastEpisodeNumber = latestEpisodeNumber = targetFinale.Order + 1; + seasonOverride = true; + _ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow); + } + else + Console.WriteLine("Could not find a finale episode."); + } + } + + } + } + if(!seasonOverride) + { + Console.WriteLine($"Failing release due to TMDB's season number {latestSeasonNumber} not matching title season {season}"); + return; + } } if(latestEpisodeNumber != int.Parse(episode))