Handled case where TMDB doesn't return a show; First attempt at ordinal-based episode count;Handled null string Overview

This commit is contained in:
2024-09-30 20:33:07 -04:00
parent f63631df89
commit 09f65f9a31
2 changed files with 25 additions and 3 deletions

View File

@@ -14,5 +14,6 @@ namespace AnimeAnnouncer.Cache
public string? LatestSeasonOverview { get; internal set; } public string? LatestSeasonOverview { get; internal set; }
public double VoteAverage { get; internal set; } public double VoteAverage { get; internal set; }
public string? Overview { get; internal set; } public string? Overview { get; internal set; }
public int? LatestOrdinalEpisodeNumber { get; internal set; }
} }
} }

View File

@@ -1,5 +1,6 @@
using System.ComponentModel; using System.ComponentModel;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using AnimeAnnouncer.Cache; using AnimeAnnouncer.Cache;
using AnimeAnnouncer.RSS; using AnimeAnnouncer.RSS;
using Mastonet; using Mastonet;
@@ -93,6 +94,8 @@ namespace AnimeAnnouncer
int latestSeasonNumber = 0, latestEpisodeNumber = 0, supposedShowId = 0; int latestSeasonNumber = 0, latestEpisodeNumber = 0, supposedShowId = 0;
int? latestOrdinalEpisodeNumber = null;
TMDBCacheItem? cachedShow = null; TMDBCacheItem? cachedShow = null;
try try
@@ -103,6 +106,7 @@ namespace AnimeAnnouncer
Console.WriteLine("Cache hit"); Console.WriteLine("Cache hit");
latestSeasonNumber = cachedShow.LatestSeasonNumber; latestSeasonNumber = cachedShow.LatestSeasonNumber;
latestEpisodeNumber = cachedShow.LastEpisodeNumber; latestEpisodeNumber = cachedShow.LastEpisodeNumber;
latestOrdinalEpisodeNumber = cachedShow.LatestOrdinalEpisodeNumber;
supposedShowId = cachedShow.ShowID; supposedShowId = cachedShow.ShowID;
} }
} }
@@ -116,6 +120,14 @@ namespace AnimeAnnouncer
var searchResults = await tmdbClient.SearchTvShowAsync(title); var searchResults = await tmdbClient.SearchTvShowAsync(title);
Console.WriteLine($"Searching {title} on TMDB");
if(!searchResults.Results.Any())
{
Console.WriteLine("TMDB did not return any results.");
return;
}
supposedShowId = searchResults.Results.First().Id; supposedShowId = searchResults.Results.First().Id;
var showResult = await tmdbClient.GetTvShowAsync(supposedShowId); var showResult = await tmdbClient.GetTvShowAsync(supposedShowId);
@@ -132,6 +144,11 @@ namespace AnimeAnnouncer
latestEpisodeNumber = latestSeason.EpisodeCount; latestEpisodeNumber = latestSeason.EpisodeCount;
if(showResult.Seasons.Count > 1)
{
latestOrdinalEpisodeNumber = showResult.Seasons.Sum(s => s.EpisodeCount);
}
if(tmdbCache != null && searchResults != null) if(tmdbCache != null && searchResults != null)
{ {
try try
@@ -143,6 +160,7 @@ namespace AnimeAnnouncer
BackdropPath = showResult.BackdropPath.Length > 0 ? $"https://image.tmdb.org/t/p/original{showResult.BackdropPath}" : String.Empty, BackdropPath = showResult.BackdropPath.Length > 0 ? $"https://image.tmdb.org/t/p/original{showResult.BackdropPath}" : String.Empty,
LatestSeasonPosterPath = latestSeason.PosterPath.Length > 0 ? $"https://image.tmdb.org/t/p/original{latestSeason.PosterPath}" : String.Empty, LatestSeasonPosterPath = latestSeason.PosterPath.Length > 0 ? $"https://image.tmdb.org/t/p/original{latestSeason.PosterPath}" : String.Empty,
LatestSeasonOverview = latestSeason.Overview, LatestSeasonOverview = latestSeason.Overview,
LatestOrdinalEpisodeNumber = latestOrdinalEpisodeNumber,
Overview = showResult.Overview, Overview = showResult.Overview,
VoteAverage = showResult.VoteAverage, VoteAverage = showResult.VoteAverage,
ShowID = supposedShowId, ShowID = supposedShowId,
@@ -169,8 +187,11 @@ namespace AnimeAnnouncer
if(latestEpisodeNumber != int.Parse(episode)) if(latestEpisodeNumber != int.Parse(episode))
{ {
Console.WriteLine($"Failing release due to TMDB's last episode number of {latestEpisodeNumber} not matching title episode number {episode}"); if(!latestOrdinalEpisodeNumber.HasValue || (latestOrdinalEpisodeNumber.HasValue && latestOrdinalEpisodeNumber.Value != int.Parse(episode)))
return; {
Console.WriteLine($"Failing release due to TMDB's last episode number of {latestEpisodeNumber}|{latestOrdinalEpisodeNumber ?? 0} not matching title episode number {episode}");
return;
}
} }
// Announce if unique // Announce if unique
@@ -213,7 +234,7 @@ namespace AnimeAnnouncer
} }
//Prepare Status //Prepare Status
String statusText = $"{cachedShow.Title} ({cachedShow.VoteAverage}/10) DUBBED has finished airing season {cachedShow.LatestSeasonNumber}! Episode {cachedShow.LastEpisodeNumber} is now available for download. {Environment.NewLine + Environment.NewLine}"; String statusText = $"{cachedShow.Title} ({cachedShow.VoteAverage}/10) DUBBED has finished airing season {cachedShow.LatestSeasonNumber}! Episode {cachedShow.LastEpisodeNumber} is now available for download. {Environment.NewLine + Environment.NewLine}";
String overview = !String.IsNullOrWhiteSpace(cachedShow.LatestSeasonOverview) ? cachedShow.LatestSeasonOverview : cachedShow.Overview; String overview = !String.IsNullOrWhiteSpace(cachedShow.LatestSeasonOverview) ? cachedShow.LatestSeasonOverview : cachedShow.Overview ?? String.Empty;
if(!String.IsNullOrWhiteSpace(overview)) if(!String.IsNullOrWhiteSpace(overview))
{ {
statusText += $"Overview: {overview}"; statusText += $"Overview: {overview}";