Implemented redis caching; made docker build script for VS code builds
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
using AnimeAnnouncer.Cache;
|
using System.ComponentModel;
|
||||||
|
using AnimeAnnouncer.Cache;
|
||||||
using AnimeAnnouncer.RSS;
|
using AnimeAnnouncer.RSS;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using TMDbLib.Client;
|
using TMDbLib.Client;
|
||||||
|
|
||||||
namespace AnimeAnnouncer
|
namespace AnimeAnnouncer
|
||||||
@@ -34,6 +36,7 @@ namespace AnimeAnnouncer
|
|||||||
if(!String.IsNullOrEmpty(redisCacheConnectionString))
|
if(!String.IsNullOrEmpty(redisCacheConnectionString))
|
||||||
{
|
{
|
||||||
tmdbCache = new TMDBCache(redisCacheConnectionString);
|
tmdbCache = new TMDBCache(redisCacheConnectionString);
|
||||||
|
Console.WriteLine("Using cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
nyaaIndexer.NewPost += OnNewPost;
|
nyaaIndexer.NewPost += OnNewPost;
|
||||||
@@ -77,29 +80,79 @@ namespace AnimeAnnouncer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchResults = await tmdbClient.SearchTvShowAsync(title);
|
int latestSeasonNumber = 0, latestEpisodeNumber = 0, supposedShowId = 0;
|
||||||
|
|
||||||
var supposedShowId = searchResults.Results.First().Id;
|
if(tmdbCache != null)
|
||||||
|
|
||||||
var showResult = await tmdbClient.GetTvShowAsync(supposedShowId);
|
|
||||||
|
|
||||||
var latestSeason = showResult.Seasons.Where(s => s.AirDate.HasValue && s.AirDate.Value < DateTime.Now).OrderByDescending(s => s.SeasonNumber).FirstOrDefault();
|
|
||||||
|
|
||||||
if(latestSeason == null)
|
|
||||||
{
|
{
|
||||||
Console.WriteLine("Unable to find a viable season from TMDB.");
|
try
|
||||||
|
{
|
||||||
|
var cachedShow = await tmdbCache.GetCacheItem($"ShowCache-{title}");
|
||||||
|
if(cachedShow != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Cache hit");
|
||||||
|
latestSeasonNumber = cachedShow.LatestSeasonNumber;
|
||||||
|
latestEpisodeNumber = cachedShow.LastEpisodeNumber;
|
||||||
|
supposedShowId = cachedShow.ShowID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(supposedShowId == 0)
|
||||||
|
{ //no cache hit
|
||||||
|
|
||||||
|
var searchResults = await tmdbClient.SearchTvShowAsync(title);
|
||||||
|
|
||||||
|
supposedShowId = searchResults.Results.First().Id;
|
||||||
|
|
||||||
|
var showResult = await tmdbClient.GetTvShowAsync(supposedShowId);
|
||||||
|
|
||||||
|
var latestSeason = showResult.Seasons.Where(s => s.AirDate.HasValue && s.AirDate.Value < DateTime.Now).OrderByDescending(s => s.SeasonNumber).FirstOrDefault();
|
||||||
|
|
||||||
|
if(latestSeason == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Unable to find a viable season from TMDB.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
latestSeasonNumber = latestSeason.SeasonNumber;
|
||||||
|
|
||||||
|
latestEpisodeNumber = latestSeason.EpisodeCount;
|
||||||
|
|
||||||
|
if(tmdbCache != null && searchResults != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tmdbCache.SetCacheItem($"ShowCache-{title}", new TMDBCacheItem()
|
||||||
|
{
|
||||||
|
Title = title,
|
||||||
|
ShowID = supposedShowId,
|
||||||
|
LatestSeasonNumber = latestSeason.SeasonNumber,
|
||||||
|
LastEpisodeNumber = latestSeason.EpisodeCount
|
||||||
|
}).Start();
|
||||||
|
Console.WriteLine($"{title} Added to cache");
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(latestSeasonNumber != int.Parse(season))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Failing release due to TMDB's season number {latestSeasonNumber} not matching title season {season}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(latestSeason.SeasonNumber != int.Parse(season))
|
if(latestEpisodeNumber != int.Parse(episode))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Failing release due to TMDB's season number {latestSeason.SeasonNumber} not matching title season {season}");
|
Console.WriteLine($"Failing release due to TMDB's last episode number of {latestEpisodeNumber} not matching title episode number {episode}");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(latestSeason.EpisodeCount != int.Parse(episode))
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Failing release due to TMDB's last episode number of {latestSeason.EpisodeCount} not matching title episode number {episode}");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user