Numerous fixes to improve functionality
This commit is contained in:
@@ -6,5 +6,6 @@ namespace AnimeAnnouncer.Cache
|
||||
public required String Title { get; set; }
|
||||
public int ShowID { get; set; }
|
||||
public DateTime? LastAirDate { get; set; }
|
||||
public int LatestEpisodeNumber { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,12 @@ public class TMDBCache
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task RemoveCacheItem(String key)
|
||||
{
|
||||
var db =redis.GetDatabase();
|
||||
_ = await db.KeyDeleteAsync(key);
|
||||
}
|
||||
|
||||
public async Task SetAiringSoon(List<AiringSoonItem> list)
|
||||
{
|
||||
var db = redis.GetDatabase();
|
||||
|
||||
@@ -223,7 +223,7 @@ namespace AnimeAnnouncer
|
||||
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow);
|
||||
Console.WriteLine($"{title} Added to cache");
|
||||
if(latestSeason.AirDate < DateTime.Now && (latestSeason.AirDate + TimeSpan.FromDays(180)) > DateTime.Now &&
|
||||
((showResult.Status == "Ended" ? showResult.LastAirDate : showResult.NextEpisodeToAir.AirDate) + TimeSpan.FromDays(30)) > DateTime.Now)
|
||||
((showResult.Status == "Ended" || showResult.NextEpisodeToAir == null ? showResult.LastAirDate : showResult.NextEpisodeToAir.AirDate) + TimeSpan.FromDays(30)) > DateTime.Now)
|
||||
UpdateAiringShowList(cachedShow);
|
||||
}
|
||||
catch(Exception ex)
|
||||
@@ -253,7 +253,7 @@ namespace AnimeAnnouncer
|
||||
{ //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)
|
||||
if(targetFinale != null && targetEpisodeGroup.Groups.Where(g => g.Episodes.Count != 0).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} airing on {targetFinale.AirDate} for finale using episode groups");
|
||||
cachedShow.LatestSeasonNumber = latestSeasonNumber = titleSeason;
|
||||
@@ -311,6 +311,8 @@ namespace AnimeAnnouncer
|
||||
else if (!finaleConfirmed)
|
||||
{
|
||||
Console.WriteLine($"Would have announced finale for {title}, on S{cachedShow.LatestSeasonNumber}E{cachedShow.LastEpisodeNumber} but the finale episode type was not found.");
|
||||
//Remove from cache so subsequent releases cause a fresh lookup
|
||||
await tmdbCache.RemoveCacheItem($"ShowCache-{title}");
|
||||
return;
|
||||
}
|
||||
if(mastodonClient != null && cachedShow != null)
|
||||
@@ -336,7 +338,7 @@ namespace AnimeAnnouncer
|
||||
DateTime beginningOfMonth = DateTime.Today;
|
||||
DateTime endOfMonth = DateTime.Today.AddMonths(1);
|
||||
var airingThisMonth = airingSoon.Where(p => p.LastAirDate >= beginningOfMonth && p.LastAirDate <= endOfMonth).ToList();
|
||||
String statusText = $"DUBBED anime airing this month (probably){Environment.NewLine + Environment.NewLine}";
|
||||
String statusText = $"DUBBED airing anime ending this month (probably){Environment.NewLine + Environment.NewLine}";
|
||||
int cnt = 1;
|
||||
for(int i = 0;i < airingThisMonth.Count;i++)
|
||||
{
|
||||
@@ -416,14 +418,21 @@ namespace AnimeAnnouncer
|
||||
{
|
||||
Title = cachedShow.Title,
|
||||
ShowID = cachedShow.ShowID,
|
||||
LastAirDate = cachedShow.LastAirDate ?? DateTime.MaxValue
|
||||
LastAirDate = cachedShow.LastAirDate ?? DateTime.MaxValue,
|
||||
LatestEpisodeNumber = cachedShow.LatestEpisodeNumber ?? 0
|
||||
};
|
||||
if(!airingSoonList.Any(s => s.ShowID == cachedShow.ShowID))
|
||||
var existingAiringItem = airingSoonList.FirstOrDefault(s => s.ShowID == cachedShow.ShowID);
|
||||
if(existingAiringItem == null)
|
||||
{
|
||||
airingSoonList.Add(airingSoonItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(existingAiringItem.LatestEpisodeNumber >= cachedShow.LatestEpisodeNumber)
|
||||
{
|
||||
Console.WriteLine($"Not updating {cachedShow.Title} airdate due to episode number not incrementing");
|
||||
return;
|
||||
}
|
||||
airingSoonList.RemoveAll(s => s.ShowID == cachedShow.ShowID);
|
||||
airingSoonList.Add(airingSoonItem);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user