Opus changes
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
@page
|
||||
@page
|
||||
@model IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Airing Soon Anime";
|
||||
}
|
||||
|
||||
<div class="container-fluid airing-container">
|
||||
<div class="airing-container">
|
||||
<div class="d-flex flex-wrap align-items-center justify-content-between mb-2">
|
||||
<h1 class="display-5 mb-0 d-flex align-items-center flex-wrap">
|
||||
<span>🗓️ Airing Soon Anime</span>
|
||||
<span class="badge rounded-pill bg-dark text-white ms-2 fs-6">@(Model.AiringShows == null ? "No data" : (Model.AiringShows.Count + (Model.AiringShows.Count == 1 ? " show" : " shows")))</span>
|
||||
</h1>
|
||||
</div>
|
||||
<p class="lead text-secondary mb-4">Anime with an upcoming or recent latest episode, fetched from the TMDB cache. Sorted by air date (<strong>newest first</strong>).</p>
|
||||
<p class="lead text-secondary mb-4">Anime with an upcoming or recent latest episode, drawn from the TMDB and AniList caches. Sorted by air date (<strong>soonest first</strong>).</p>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
|
||||
{
|
||||
@@ -32,94 +32,158 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-5 row-cols-xxl-6 g-4">
|
||||
<div class="airing-list">
|
||||
@foreach (var show in Model.AiringShows)
|
||||
{
|
||||
<div class="col">
|
||||
<div class="card h-100 anime-card @(show.IsFuture ? "border-danger" : "")">
|
||||
<div class="anime-poster-container">
|
||||
<article class="airing-row @(show.IsFuture ? "is-upcoming" : "is-aired")">
|
||||
@if (!string.IsNullOrWhiteSpace(show.HeroImageUrl))
|
||||
{
|
||||
<div class="airing-backdrop" style="background-image: url('@show.HeroImageUrl');" aria-hidden="true"></div>
|
||||
}
|
||||
<div class="airing-scrim" aria-hidden="true"></div>
|
||||
|
||||
<div class="airing-content">
|
||||
<div class="airing-poster">
|
||||
@if (!string.IsNullOrWhiteSpace(show.PosterUrl))
|
||||
{
|
||||
<img src="@show.PosterUrl" class="anime-poster" alt="@show.Title" title="@show.Title" loading="lazy" />
|
||||
<img src="@show.PosterUrl" alt="@show.Title poster" title="@show.Title" loading="lazy" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="anime-poster d-flex align-items-center justify-content-center text-secondary">
|
||||
<span class="display-4">🗂️</span>
|
||||
<div class="airing-poster-placeholder"><span>🗂️</span></div>
|
||||
}
|
||||
@if (show.LatestSeasonNumber.HasValue && show.LatestSeasonNumber > 0)
|
||||
{
|
||||
<span class="airing-poster-tag">Season @show.LatestSeasonNumber</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="airing-body">
|
||||
<header class="airing-header">
|
||||
<div class="airing-titles">
|
||||
<h2 class="airing-title">@show.Title</h2>
|
||||
@if (show.AlternateTitles.Count > 0)
|
||||
{
|
||||
<p class="airing-alt-titles">@string.Join(" · ", show.AlternateTitles)</p>
|
||||
}
|
||||
</div>
|
||||
<div class="airing-scores">
|
||||
@if (show.VoteAverage.HasValue && show.VoteAverage > 0)
|
||||
{
|
||||
<span class="score-chip score-tmdb" title="TMDB user score">
|
||||
<span class="score-value">@string.Format("{0:0.0}", show.VoteAverage)</span>
|
||||
<span class="score-source">TMDB</span>
|
||||
</span>
|
||||
}
|
||||
@if (show.AnilistScore.HasValue && show.AnilistScore > 0)
|
||||
{
|
||||
<span class="score-chip score-anilist" title="AniList average score">
|
||||
<span class="score-value">@string.Format("{0:0.0}", show.AnilistScore)</span>
|
||||
<span class="score-source">AniList</span>
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="airing-meta">
|
||||
@if (show.LatestEpisodeNumber > 0)
|
||||
{
|
||||
<span class="meta-chip">
|
||||
@if (show.TotalEpisodes.HasValue && show.TotalEpisodes > 0)
|
||||
{
|
||||
<text>Episode @show.LatestEpisodeNumber of @show.TotalEpisodes</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>Episode @show.LatestEpisodeNumber</text>
|
||||
}
|
||||
</span>
|
||||
}
|
||||
@if (show.LatestOrdinalEpisodeNumber.HasValue && show.LatestOrdinalEpisodeNumber > 0)
|
||||
{
|
||||
<span class="meta-chip">@show.LatestOrdinalEpisodeNumber episodes overall</span>
|
||||
}
|
||||
@if (!string.IsNullOrWhiteSpace(show.AnilistStatus))
|
||||
{
|
||||
<span class="meta-chip">@show.AnilistStatus</span>
|
||||
}
|
||||
@if (show.SeasonYear.HasValue)
|
||||
{
|
||||
<span class="meta-chip">@show.SeasonYear</span>
|
||||
}
|
||||
@if (show.IsFinaleNext && show.IsFuture)
|
||||
{
|
||||
<span class="meta-chip meta-chip-finale">🏁 Season finale</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (show.EpisodeProgressPercent.HasValue)
|
||||
{
|
||||
<div class="airing-progress" title="@show.LatestEpisodeNumber of @show.TotalEpisodes episodes aired">
|
||||
<div class="airing-progress-bar" style="width: @(show.EpisodeProgressPercent)%;"></div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (show.VoteAverage.HasValue && show.VoteAverage > 0)
|
||||
@if (!string.IsNullOrWhiteSpace(show.Overview))
|
||||
{
|
||||
<span class="position-absolute top-0 start-0 badge rounded-pill bg-warning text-dark m-2 shadow-sm">⭐ @string.Format("{0:0.0}", show.VoteAverage)</span>
|
||||
<p class="airing-overview">
|
||||
@if (show.OverviewIsSeasonSpecific && show.LatestSeasonNumber > 0)
|
||||
{
|
||||
<span class="overview-label">Season @show.LatestSeasonNumber —</span>
|
||||
}
|
||||
@show.Overview
|
||||
</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="airing-overview text-secondary fst-italic">No overview available.</p>
|
||||
}
|
||||
|
||||
<footer class="airing-footer">
|
||||
<a href="https://www.themoviedb.org/tv/@show.ShowID" target="_blank" rel="noopener noreferrer" class="btn btn-sm btn-outline-light">TMDB</a>
|
||||
@if (!string.IsNullOrWhiteSpace(show.AnilistUrl))
|
||||
{
|
||||
<a href="@show.AnilistUrl" target="_blank" rel="noopener noreferrer" class="btn btn-sm btn-outline-info">AniList</a>
|
||||
}
|
||||
|
||||
@if (show.SecondaryImages.Count > 0)
|
||||
{
|
||||
<div class="airing-gallery">
|
||||
@foreach (var image in show.SecondaryImages)
|
||||
{
|
||||
<a href="@image.Url" target="_blank" rel="noopener noreferrer"
|
||||
class="gallery-thumb" title="@image.Label (@image.Source)">
|
||||
<img src="@image.Url" alt="@show.Title — @image.Label" loading="lazy" />
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<aside class="airing-countdown">
|
||||
@if (show.EffectiveLastAirDate.HasValue)
|
||||
{
|
||||
@if (show.IsFuture)
|
||||
{
|
||||
<span class="position-absolute top-0 end-0 badge rounded-pill bg-danger text-white m-2 shadow-sm">Airs in @Math.Max(show.DaysUntil, 1)d</span>
|
||||
<span class="countdown-number">@Math.Max(show.DaysUntil, 1)</span>
|
||||
<span class="countdown-unit">@(Math.Max(show.DaysUntil, 1) == 1 ? "day" : "days") away</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="position-absolute top-0 end-0 badge rounded-pill bg-secondary text-white m-2 shadow-sm">Aired @Math.Abs(show.DaysUntil)d ago</span>
|
||||
<span class="countdown-number">@Math.Abs(show.DaysUntil)</span>
|
||||
<span class="countdown-unit">@(Math.Abs(show.DaysUntil) == 1 ? "day" : "days") ago</span>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title text-truncate" title="@show.Title">@show.Title</h5>
|
||||
|
||||
<div class="show-meta mb-2 d-flex flex-wrap gap-1">
|
||||
@if (show.LatestSeasonNumber.HasValue && show.LatestSeasonNumber > 0)
|
||||
{
|
||||
<span class="badge rounded-pill bg-light text-dark border">Season @show.LatestSeasonNumber</span>
|
||||
}
|
||||
@if (show.LatestEpisodeNumber > 0)
|
||||
{
|
||||
@if (show.LastEpisodeNumber.HasValue && show.LastEpisodeNumber > 0)
|
||||
{
|
||||
<span class="badge rounded-pill bg-light text-dark border">Ep @show.LatestEpisodeNumber / @show.LastEpisodeNumber</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge rounded-pill bg-light text-dark border">Ep @show.LatestEpisodeNumber</span>
|
||||
}
|
||||
}
|
||||
@if (show.LatestOrdinalEpisodeNumber.HasValue && show.LatestOrdinalEpisodeNumber > 0)
|
||||
{
|
||||
<span class="badge rounded-pill bg-light text-dark border">Total: @show.LatestOrdinalEpisodeNumber</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="show-dates mb-2">
|
||||
@if (show.EffectiveLastAirDate.HasValue)
|
||||
{
|
||||
<small class="text-primary fw-semibold">📅 Last air date: @show.AirDateFormatted</small>
|
||||
}
|
||||
else
|
||||
{
|
||||
<small class="text-secondary">📅 Last air date: @show.AirDateFormatted</small>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-footer bg-transparent border-top-0 pt-0">
|
||||
@if (!string.IsNullOrWhiteSpace(show.Overview))
|
||||
{
|
||||
<p class="show-overview text-muted" title="@show.Overview">@show.Overview</p>
|
||||
<span class="countdown-date" title="@show.AirDateLongFormatted">@show.AirDateFormatted</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="show-overview text-secondary fst-italic">No overview available.</p>
|
||||
<span class="countdown-unit">Air date unknown</span>
|
||||
}
|
||||
<div class="d-grid mt-2">
|
||||
<a href="https://www.themoviedb.org/tv/@show.ShowID" target="_blank" rel="noopener noreferrer" class="btn btn-sm btn-outline-primary">View on TMDB</a>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using AnimeAnnouncer.Cache;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
@@ -50,10 +52,23 @@ public class IndexModel : PageModel
|
||||
_logger.LogWarning(ex, "Failed to retrieve cache item for title: {Title}", airingItem.Title);
|
||||
}
|
||||
|
||||
// The announcer stores Anilist details under a parallel key using the same
|
||||
// title, so the two caches line up one-to-one when Anilist was consulted.
|
||||
AnilistCacheItem? anilistItem = null;
|
||||
try
|
||||
{
|
||||
anilistItem = await _tmdbCache.GetCacheItem<AnilistCacheItem>($"AnilistCache-{airingItem.Title}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to retrieve Anilist cache item for title: {Title}", airingItem.Title);
|
||||
}
|
||||
|
||||
viewModels.Add(new AiringShowViewModel
|
||||
{
|
||||
AiringSoon = airingItem,
|
||||
CachedDetails = cacheItem
|
||||
CachedDetails = cacheItem,
|
||||
AnilistDetails = anilistItem
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,10 +95,20 @@ public class IndexModel : PageModel
|
||||
}
|
||||
}
|
||||
|
||||
public class ShowImage
|
||||
{
|
||||
public required string Url { get; set; }
|
||||
public required string Label { get; set; }
|
||||
public required string Source { get; set; }
|
||||
}
|
||||
|
||||
public class AiringShowViewModel
|
||||
{
|
||||
private static readonly Regex HtmlTagPattern = new("<[^>]+>", RegexOptions.Compiled);
|
||||
|
||||
public required AiringSoonItem AiringSoon { get; set; }
|
||||
public TMDBCacheItem? CachedDetails { get; set; }
|
||||
public AnilistCacheItem? AnilistDetails { get; set; }
|
||||
|
||||
public string Title => AiringSoon.Title;
|
||||
public int ShowID => AiringSoon.ShowID;
|
||||
@@ -95,25 +120,116 @@ public class IndexModel : PageModel
|
||||
public int? LatestSeasonNumber => CachedDetails?.LatestSeasonNumber;
|
||||
public int? LatestOrdinalEpisodeNumber => CachedDetails?.LatestOrdinalEpisodeNumber;
|
||||
public double? VoteAverage => CachedDetails?.VoteAverage;
|
||||
public string? Overview => !string.IsNullOrWhiteSpace(CachedDetails?.LatestSeasonOverview)
|
||||
? CachedDetails.LatestSeasonOverview
|
||||
: CachedDetails?.Overview;
|
||||
|
||||
public string? PosterUrl
|
||||
// --- Anilist ---------------------------------------------------------
|
||||
|
||||
public bool HasAnilist => AnilistDetails != null;
|
||||
public int? AnilistShowID => AnilistDetails?.ShowID;
|
||||
public string? AnilistUrl => AnilistShowID.HasValue ? $"https://anilist.co/anime/{AnilistShowID}" : null;
|
||||
|
||||
/// <summary>Anilist's 0-100 score, rescaled to the 0-10 range TMDB uses.</summary>
|
||||
public double? AnilistScore => AnilistDetails?.AverageScore.HasValue == true
|
||||
? AnilistDetails.AverageScore!.Value / 10.0
|
||||
: null;
|
||||
|
||||
public string? AnilistStatus => string.IsNullOrWhiteSpace(AnilistDetails?.Status)
|
||||
? null
|
||||
// Anilist statuses arrive as enum names like RELEASING / NOT_YET_RELEASED.
|
||||
: string.Join(' ', AnilistDetails.Status.Split('_', StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(word => char.ToUpperInvariant(word[0]) + word[1..].ToLowerInvariant()));
|
||||
|
||||
public int? SeasonYear => AnilistDetails?.SeasonYear;
|
||||
|
||||
/// <summary>Total episode count, preferring Anilist which the announcer treats as more reliable.</summary>
|
||||
public int? TotalEpisodes => AnilistDetails?.Episodes ?? (LastEpisodeNumber > 0 ? LastEpisodeNumber : null);
|
||||
|
||||
/// <summary>Alternate titles worth showing, i.e. anything that is not just the display title again.</summary>
|
||||
public List<string> AlternateTitles
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(CachedDetails?.LatestSeasonPosterPath))
|
||||
return CachedDetails.LatestSeasonPosterPath;
|
||||
if (!string.IsNullOrWhiteSpace(CachedDetails?.PosterPath))
|
||||
return CachedDetails.PosterPath;
|
||||
//if (!string.IsNullOrWhiteSpace(CachedDetails?.AnilistPosterPath))
|
||||
// return CachedDetails.AnilistPosterPath;
|
||||
return null;
|
||||
var candidates = new[] { AnilistDetails?.RomajiTitle, AnilistDetails?.NativeTitle, AnilistDetails?.EnglishTitle };
|
||||
return candidates
|
||||
.Where(t => !string.IsNullOrWhiteSpace(t))
|
||||
.Select(t => t!.Trim())
|
||||
.Where(t => !string.Equals(t, Title, StringComparison.OrdinalIgnoreCase))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public string? BackdropUrl => CachedDetails?.BackdropPath;
|
||||
/// <summary>Anilist descriptions are HTML fragments; flatten them to plain text for display.</summary>
|
||||
public string? AnilistDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(AnilistDetails?.Description))
|
||||
return null;
|
||||
|
||||
var text = AnilistDetails.Description
|
||||
.Replace("<br>", " ", StringComparison.OrdinalIgnoreCase)
|
||||
.Replace("<br/>", " ", StringComparison.OrdinalIgnoreCase)
|
||||
.Replace("<br />", " ", StringComparison.OrdinalIgnoreCase);
|
||||
text = WebUtility.HtmlDecode(HtmlTagPattern.Replace(text, string.Empty));
|
||||
text = Regex.Replace(text, @"\s{2,}", " ").Trim();
|
||||
|
||||
return string.IsNullOrWhiteSpace(text) ? null : text;
|
||||
}
|
||||
}
|
||||
|
||||
public string? Overview => !string.IsNullOrWhiteSpace(CachedDetails?.LatestSeasonOverview)
|
||||
? CachedDetails.LatestSeasonOverview
|
||||
: (!string.IsNullOrWhiteSpace(CachedDetails?.Overview) ? CachedDetails.Overview : AnilistDescription);
|
||||
|
||||
/// <summary>True when <see cref="Overview"/> describes the current season rather than the series.</summary>
|
||||
public bool OverviewIsSeasonSpecific => !string.IsNullOrWhiteSpace(CachedDetails?.LatestSeasonOverview);
|
||||
|
||||
// --- Artwork ---------------------------------------------------------
|
||||
|
||||
public string? SeasonPosterUrl => Clean(CachedDetails?.LatestSeasonPosterPath);
|
||||
public string? ShowPosterUrl => Clean(CachedDetails?.PosterPath);
|
||||
public string? BackdropUrl => Clean(CachedDetails?.BackdropPath);
|
||||
public string? AnilistCoverUrl => Clean(AnilistDetails?.CoverImageUrl);
|
||||
public string? AnilistBannerUrl => Clean(AnilistDetails?.BannerImageUrl);
|
||||
|
||||
/// <summary>The tall artwork shown alongside the entry; the season's own poster wins when present.</summary>
|
||||
public string? PosterUrl => SeasonPosterUrl ?? ShowPosterUrl ?? AnilistCoverUrl;
|
||||
|
||||
/// <summary>The wide artwork used as the row background.</summary>
|
||||
public string? HeroImageUrl => BackdropUrl ?? AnilistBannerUrl;
|
||||
|
||||
/// <summary>Every distinct piece of artwork, for the secondary thumbnail strip.</summary>
|
||||
public List<ShowImage> Gallery
|
||||
{
|
||||
get
|
||||
{
|
||||
var images = new List<ShowImage>();
|
||||
|
||||
void Add(string? url, string label, string source)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
return;
|
||||
if (images.Any(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase)))
|
||||
return;
|
||||
images.Add(new ShowImage { Url = url, Label = label, Source = source });
|
||||
}
|
||||
|
||||
// The primary poster is already displayed beside the row, so start after it.
|
||||
Add(SeasonPosterUrl, $"Season {LatestSeasonNumber} poster", "TMDB");
|
||||
Add(ShowPosterUrl, "Series poster", "TMDB");
|
||||
Add(AnilistCoverUrl, "Cover art", "AniList");
|
||||
Add(BackdropUrl, "Backdrop", "TMDB");
|
||||
Add(AnilistBannerUrl, "Banner", "AniList");
|
||||
|
||||
return images;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Gallery entries other than the one already shown as the main poster.</summary>
|
||||
public List<ShowImage> SecondaryImages =>
|
||||
Gallery.Where(i => !string.Equals(i.Url, PosterUrl, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
|
||||
// --- Air dates -------------------------------------------------------
|
||||
|
||||
public DateTime AirReferenceNow => DateTime.Now;
|
||||
|
||||
@@ -145,6 +261,24 @@ public class IndexModel : PageModel
|
||||
return date.HasValue ? date.Value.ToString("MM/dd/yyyy") : "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public string? AirDateLongFormatted => EffectiveLastAirDate?.ToString("dddd, MMMM d, yyyy");
|
||||
|
||||
/// <summary>How far into the season the latest aired episode sits, as a percentage.</summary>
|
||||
public int? EpisodeProgressPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
var total = TotalEpisodes;
|
||||
if (!total.HasValue || total.Value <= 0 || LatestEpisodeNumber <= 0)
|
||||
return null;
|
||||
return (int)Math.Round(Math.Clamp(LatestEpisodeNumber / (double)total.Value, 0, 1) * 100);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>True when the upcoming episode is the last one of the season.</summary>
|
||||
public bool IsFinaleNext => TotalEpisodes.HasValue && LatestEpisodeNumber > 0 && LatestEpisodeNumber >= TotalEpisodes.Value;
|
||||
|
||||
private static string? Clean(string? value) => string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user