Various minor changes to announcer to support Web version and include Anilist
This commit is contained in:
@@ -43,7 +43,7 @@ public class IndexModel : PageModel
|
|||||||
TMDBCacheItem? cacheItem = null;
|
TMDBCacheItem? cacheItem = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cacheItem = await _tmdbCache.GetCacheItem($"ShowCache-{airingItem.Title}");
|
cacheItem = await _tmdbCache.GetCacheItem<TMDBCacheItem>($"ShowCache-{airingItem.Title}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -68,7 +68,7 @@ public class IndexModel : PageModel
|
|||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
AiringShows = displayable
|
AiringShows = displayable
|
||||||
.Where(x => x.EffectiveLastAirDate.HasValue && x.EffectiveLastAirDate.Value > DateTime.Now)
|
.Where(x => x.EffectiveLastAirDate.HasValue && x.EffectiveLastAirDate.Value.Date >= DateTime.Now.Date)
|
||||||
.OrderBy(x => x.EffectiveLastAirDate)
|
.OrderBy(x => x.EffectiveLastAirDate)
|
||||||
.ThenBy(x => x.Title)
|
.ThenBy(x => x.Title)
|
||||||
.ToList();
|
.ToList();
|
||||||
@@ -107,8 +107,8 @@ public class IndexModel : PageModel
|
|||||||
return CachedDetails.LatestSeasonPosterPath;
|
return CachedDetails.LatestSeasonPosterPath;
|
||||||
if (!string.IsNullOrWhiteSpace(CachedDetails?.PosterPath))
|
if (!string.IsNullOrWhiteSpace(CachedDetails?.PosterPath))
|
||||||
return CachedDetails.PosterPath;
|
return CachedDetails.PosterPath;
|
||||||
if (!string.IsNullOrWhiteSpace(CachedDetails?.AnilistPosterPath))
|
//if (!string.IsNullOrWhiteSpace(CachedDetails?.AnilistPosterPath))
|
||||||
return CachedDetails.AnilistPosterPath;
|
// return CachedDetails.AnilistPosterPath;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,22 +17,22 @@ public class TMDBCache
|
|||||||
CacheExpiration = TimeSpan.FromDays(3);
|
CacheExpiration = TimeSpan.FromDays(3);
|
||||||
redis = ConnectionMultiplexer.Connect(redisConnectionString);
|
redis = ConnectionMultiplexer.Connect(redisConnectionString);
|
||||||
}
|
}
|
||||||
public async Task SetCacheItem(String key, TMDBCacheItem item)
|
public async Task SetCacheItem<T>(String key, T item)
|
||||||
{
|
{
|
||||||
var db = redis.GetDatabase();
|
var db = redis.GetDatabase();
|
||||||
|
|
||||||
String jsonItem = JsonSerializer.Serialize(item);
|
String jsonItem = JsonSerializer.Serialize(item);
|
||||||
await db.StringSetAsync(key, jsonItem, CacheExpiration);
|
await db.StringSetAsync(key, jsonItem, CacheExpiration);
|
||||||
}
|
}
|
||||||
public async Task<TMDBCacheItem> GetCacheItem(String key)
|
public async Task<T?> GetCacheItem<T>(String key)
|
||||||
{
|
{
|
||||||
var db = redis.GetDatabase();
|
var db = redis.GetDatabase();
|
||||||
String jsonItem = await db.StringGetAsync(key);
|
String? jsonItem = await db.StringGetAsync(key);
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(jsonItem))
|
if (!String.IsNullOrEmpty(jsonItem))
|
||||||
return JsonSerializer.Deserialize<TMDBCacheItem>(jsonItem);
|
return JsonSerializer.Deserialize<T>(jsonItem);
|
||||||
else
|
else
|
||||||
return null;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemoveCacheItem(String key)
|
public async Task RemoveCacheItem(String key)
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ namespace AnimeAnnouncer.Cache
|
|||||||
public int? LatestEpisodeNumber { get; set; }
|
public int? LatestEpisodeNumber { get; set; }
|
||||||
|
|
||||||
public Boolean? AnilistPopulated { get; set; }
|
public Boolean? AnilistPopulated { get; set; }
|
||||||
public String? AnilistPosterPath { get; set; }
|
|
||||||
|
public DateTime? Updated { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+27
-13
@@ -146,10 +146,13 @@ namespace AnimeAnnouncer
|
|||||||
|
|
||||||
TMDBCacheItem? cachedShow = null;
|
TMDBCacheItem? cachedShow = null;
|
||||||
|
|
||||||
|
latestEpisodeNumber = int.Parse(episode);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cachedShow = await tmdbCache.GetCacheItem($"ShowCache-{title}");
|
cachedShow = await tmdbCache.GetCacheItem<TMDBCacheItem>($"ShowCache-{title}");
|
||||||
if(cachedShow != null)
|
|
||||||
|
if(cachedShow != null && (cachedShow.Updated.HasValue && DateTime.Now.Subtract(cachedShow.Updated.Value).Days < 6))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Cache hit");
|
Console.WriteLine("Cache hit");
|
||||||
latestSeasonNumber = cachedShow.LatestSeasonNumber;
|
latestSeasonNumber = cachedShow.LatestSeasonNumber;
|
||||||
@@ -194,7 +197,7 @@ namespace AnimeAnnouncer
|
|||||||
|
|
||||||
lastEpisodeNumber = latestSeason.EpisodeCount;
|
lastEpisodeNumber = latestSeason.EpisodeCount;
|
||||||
|
|
||||||
latestEpisodeNumber = int.Parse(episode);
|
|
||||||
|
|
||||||
//if nearing the end of a season, confirm it's marked with season finale
|
//if nearing the end of a season, confirm it's marked with season finale
|
||||||
|
|
||||||
@@ -224,21 +227,32 @@ namespace AnimeAnnouncer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine("Looking up Anilist title " + title);
|
AnilistCacheItem? anilistCacheItem = await tmdbCache.GetCacheItem<AnilistCacheItem>($"AnilistCache-{title}");
|
||||||
var anilistMedia = await anilistClient.RetrieveAiringShowInformation(title);
|
if (anilistCacheItem == null)
|
||||||
if (anilistMedia != null)
|
|
||||||
{
|
{
|
||||||
if (anilistMedia.Episodes.HasValue && anilistMedia.Episodes != lastEpisodeNumber)
|
Console.WriteLine("Looking up Anilist title " + title);
|
||||||
|
var anilistMedia = await anilistClient.RetrieveAiringShowInformation(title);
|
||||||
|
if (anilistMedia != null)
|
||||||
|
{
|
||||||
|
anilistCacheItem = AnilistCacheItem.FromMedia(anilistMedia);
|
||||||
|
anilistCacheItem.Updated = DateTime.Now;
|
||||||
|
_ = tmdbCache.SetCacheItem($"AnilistCache-{title}", anilistCacheItem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Console.WriteLine("0 anilist results found");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anilistCacheItem != null)
|
||||||
|
{
|
||||||
|
if (anilistCacheItem.Episodes.HasValue && anilistCacheItem.Episodes != lastEpisodeNumber)
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
$"Overriding episode count of {lastEpisodeNumber} using Anilist's showID {anilistMedia.Id} titled {anilistMedia.Title.EnglishTitle} with {anilistMedia.Episodes} episodes.");
|
$"Overriding episode count of {lastEpisodeNumber} using Anilist's showID {anilistCacheItem.ShowID} titled {anilistCacheItem.EnglishTitle} with {anilistCacheItem.Episodes} episodes.");
|
||||||
lastEpisodeNumber = anilistMedia.Episodes.Value;
|
lastEpisodeNumber = anilistCacheItem.Episodes.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
anilistPosterPath = anilistMedia.BannerImageUrl?.ToString();
|
anilistPosterPath = anilistCacheItem.BannerImageUrl;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
Console.WriteLine("0 anilist results found");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -276,7 +290,7 @@ namespace AnimeAnnouncer
|
|||||||
LastAirDate = lastAirDate,
|
LastAirDate = lastAirDate,
|
||||||
LatestEpisodeNumber = latestEpisodeNumber,
|
LatestEpisodeNumber = latestEpisodeNumber,
|
||||||
AnilistPopulated = anilistPosterPath != null,
|
AnilistPopulated = anilistPosterPath != null,
|
||||||
AnilistPosterPath = anilistPosterPath
|
Updated = DateTime.Now
|
||||||
};
|
};
|
||||||
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow);
|
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow);
|
||||||
Console.WriteLine($"{title} Added to cache");
|
Console.WriteLine($"{title} Added to cache");
|
||||||
|
|||||||
Reference in New Issue
Block a user