Added some guard rails around airing list to avoid announcing old shows

This commit is contained in:
2025-02-05 00:24:32 -05:00
parent 47b44fb59a
commit acac2a25e8

View File

@@ -221,7 +221,9 @@ namespace AnimeAnnouncer
}; };
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow); _ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow);
Console.WriteLine($"{title} Added to cache"); Console.WriteLine($"{title} Added to cache");
UpdateAiringShowList(cachedShow); if(latestSeason.AirDate < DateTime.Now && (latestSeason.AirDate + TimeSpan.FromDays(180)) > DateTime.Now &&
(showResult.NextEpisodeToAir.AirDate + TimeSpan.FromDays(30)) > DateTime.Now)
UpdateAiringShowList(cachedShow);
} }
catch(Exception ex) catch(Exception ex)
{ {
@@ -266,7 +268,9 @@ namespace AnimeAnnouncer
seasonOverride = finaleConfirmed = true; seasonOverride = finaleConfirmed = true;
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow); _ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow);
UpdateAiringShowList(cachedShow);
if(targetSeason != null && (targetSeason.Episodes.OrderBy(e => e.Order).First().AirDate + TimeSpan.FromDays(180)) > DateTime.Now && (showResult.NextEpisodeToAir.AirDate + TimeSpan.FromDays(30)) > DateTime.Now)
UpdateAiringShowList(cachedShow);
} }
else else
Console.WriteLine("Could not find a finale episode."); Console.WriteLine("Could not find a finale episode.");
@@ -426,7 +430,7 @@ namespace AnimeAnnouncer
} }
airingSoonList.Sort((showOne, showTwo) => showOne.LastAirDate.Value.CompareTo(showTwo.LastAirDate.Value)); airingSoonList.Sort((showOne, showTwo) => showOne.LastAirDate.Value.CompareTo(showTwo.LastAirDate.Value));
_ = tmdbCache.SetAiringSoon(airingSoonList); _ = tmdbCache.SetAiringSoon(airingSoonList);
Console.WriteLine("Updated airing soon list"); Console.WriteLine($"Updated airing soon list, setting {cachedShow.Title} Season {cachedShow.LatestSeasonNumber} to end on {cachedShow.LastAirDate ?? DateTime.MaxValue}");
} }
private static bool HasAiringEndDate(int showID) private static bool HasAiringEndDate(int showID)
{ {