Compare commits
2 Commits
acac2a25e8
...
5cfcecc5c3
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cfcecc5c3 | |||
| 6a50c94cf2 |
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public class TMDBCache
|
||||
public async Task SetCacheItem(String key, TMDBCacheItem item)
|
||||
{
|
||||
var db = redis.GetDatabase();
|
||||
|
||||
String jsonItem = JsonSerializer.Serialize(item);
|
||||
await db.StringSetAsync(key, jsonItem, CacheExpiration);
|
||||
}
|
||||
@@ -34,17 +35,24 @@ 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();
|
||||
String jsonItem = JsonSerializer.Serialize(list);
|
||||
await db.StringSetAsync("AiringSoon", jsonItem, CacheExpiration);
|
||||
await db.StringSetAsync("AiringSoon", jsonItem, TimeSpan.FromDays(60));
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<AiringSoonItem>> GetAiringList()
|
||||
{
|
||||
var db = redis.GetDatabase();
|
||||
|
||||
String jsonItem = await db.StringGetAsync("AiringSoon");
|
||||
|
||||
if(!String.IsNullOrEmpty(jsonItem))
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace AnimeAnnouncer
|
||||
|
||||
nyaaIndexer.NewPost += OnNewPost;
|
||||
nyaaIndexer.RssReadFinished += OnRssReadFinished;
|
||||
//nyaaIndexer.IterationSleepTime = 60;
|
||||
nyaaIndexer.Start(true);
|
||||
|
||||
Console.WriteLine("Press enter to quit...");
|
||||
@@ -222,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.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)
|
||||
@@ -252,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;
|
||||
@@ -310,15 +311,15 @@ 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.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = tmdbCache.SetPair($"ShowAnnounced-{supposedShowId}", latestSeasonNumber.ToString());
|
||||
//Remove from cache so subsequent releases cause a fresh lookup
|
||||
await tmdbCache.RemoveCacheItem($"ShowCache-{title}");
|
||||
return;
|
||||
}
|
||||
if(mastodonClient != null && cachedShow != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_ = tmdbCache.SetPair($"ShowAnnounced-{supposedShowId}", latestSeasonNumber.ToString());
|
||||
PostStatus(cachedShow);
|
||||
}
|
||||
catch(Exception ex)
|
||||
@@ -337,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++)
|
||||
{
|
||||
@@ -417,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