Get season detail to look for episodes marked as finale; multiple tweaks to avoid announcing at the incorrect time
This commit is contained in:
@@ -7,6 +7,7 @@ using Mastonet;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using TMDbLib.Client;
|
using TMDbLib.Client;
|
||||||
|
using TMDbLib.Objects.Authentication;
|
||||||
|
|
||||||
namespace AnimeAnnouncer
|
namespace AnimeAnnouncer
|
||||||
{
|
{
|
||||||
@@ -144,9 +145,24 @@ namespace AnimeAnnouncer
|
|||||||
|
|
||||||
latestEpisodeNumber = latestSeason.EpisodeCount;
|
latestEpisodeNumber = latestSeason.EpisodeCount;
|
||||||
|
|
||||||
|
//if nearing the end of a season, confirm it's marked with season finale
|
||||||
|
|
||||||
|
if(int.Parse(episode) >= (latestEpisodeNumber - 2))
|
||||||
|
{
|
||||||
|
var latestSeasonDetail = await tmdbClient.GetTvSeasonAsync(supposedShowId, latestSeasonNumber);
|
||||||
|
|
||||||
|
var seasonFinale = latestSeasonDetail.Episodes.FirstOrDefault(e => e.EpisodeType.Equals("finale", StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
|
||||||
|
if(seasonFinale != null)
|
||||||
|
{
|
||||||
|
latestEpisodeNumber = seasonFinale.EpisodeNumber;
|
||||||
|
Console.WriteLine($"Overriding finale choice due to season detail response");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(showResult.Seasons.Count > 1)
|
if(showResult.Seasons.Count > 1)
|
||||||
{
|
{
|
||||||
latestOrdinalEpisodeNumber = showResult.Seasons.Sum(s => s.EpisodeCount);
|
latestOrdinalEpisodeNumber = showResult.Seasons.Where(s => s.SeasonNumber != 0).Sum(s => s.EpisodeCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tmdbCache != null && searchResults != null)
|
if(tmdbCache != null && searchResults != null)
|
||||||
@@ -164,8 +180,8 @@ namespace AnimeAnnouncer
|
|||||||
Overview = showResult.Overview,
|
Overview = showResult.Overview,
|
||||||
VoteAverage = showResult.VoteAverage,
|
VoteAverage = showResult.VoteAverage,
|
||||||
ShowID = supposedShowId,
|
ShowID = supposedShowId,
|
||||||
LatestSeasonNumber = latestSeason.SeasonNumber,
|
LatestSeasonNumber = latestSeasonNumber,
|
||||||
LastEpisodeNumber = latestSeason.EpisodeCount
|
LastEpisodeNumber = latestEpisodeNumber
|
||||||
};
|
};
|
||||||
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow);
|
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow);
|
||||||
Console.WriteLine($"{title} Added to cache");
|
Console.WriteLine($"{title} Added to cache");
|
||||||
@@ -193,6 +209,12 @@ namespace AnimeAnnouncer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Sometimes TMDB metadata hasn't been filled in yet
|
||||||
|
if(latestEpisodeNumber < 3)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Skipping announcement due to a low episode number");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Announce if unique
|
// Announce if unique
|
||||||
if(await tmdbCache.KeyExists($"ShowAnnounced-{supposedShowId}"))
|
if(await tmdbCache.KeyExists($"ShowAnnounced-{supposedShowId}"))
|
||||||
|
|||||||
Reference in New Issue
Block a user