From fca8220160dd7d6053c889d6f8ee909e4d32b211 Mon Sep 17 00:00:00 2001 From: Harshith Mohan <26010946+harshithmohan@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:19:46 +0530 Subject: [PATCH] Fix FirstAirSeason in webui controller --- Shoko.Server/API/v3/Helpers/FilterFactory.cs | 29 ++------------------ Shoko.Server/API/v3/Helpers/WebUIFactory.cs | 14 +++++++++- Shoko.Server/API/v3/Models/Shoko/WebUI.cs | 2 +- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Shoko.Server/API/v3/Helpers/FilterFactory.cs b/Shoko.Server/API/v3/Helpers/FilterFactory.cs index 47eb00e76..7340274d3 100644 --- a/Shoko.Server/API/v3/Helpers/FilterFactory.cs +++ b/Shoko.Server/API/v3/Helpers/FilterFactory.cs @@ -164,7 +164,7 @@ public Filter.FilterCondition GetExpressionTree(FilterExpression expression) return result; } - + public FilterExpression GetExpressionTree(Filter.FilterCondition condition) { if (condition is null) return null; @@ -261,7 +261,7 @@ public Filter.SortingCriteria GetSortingCriteria(SortingExpression expression) return result; } - + public SortingExpression GetSortingCriteria(Filter.SortingCriteria criteria) { if (!_sortingTypes.TryGetValue(criteria.Type, out var type)) @@ -273,7 +273,7 @@ public SortingExpression GetSortingCriteria(Filter.SortingCriteria criteria) return result; } - + public Filter.Input.CreateOrUpdateFilterBody GetPostModel(FilterPreset groupFilter) { var result = new Filter.Input.CreateOrUpdateFilterBody @@ -354,27 +354,4 @@ public FilterPreset GetFilterPreset(Filter.Input.CreateOrUpdateFilterBody filter return existing; } - - public Filter GetFirstAiringSeasonGroupFilter(SVR_AniDB_Anime anime) - { - var type = (AnimeType)anime.AnimeType; - if (type != AnimeType.TVSeries && type != AnimeType.Web) - return null; - - var (year, season) = anime.Seasons - .FirstOrDefault(); - if (year == 0) - return null; - - var seasonName = $"{season} {year}"; - var seasonsFilterID = RepoFactory.FilterPreset.GetTopLevel() - .FirstOrDefault(f => f.FilterType == (GroupFilterType.Directory | GroupFilterType.Season))?.FilterPresetID; - if (seasonsFilterID == null) return null; - var firstAirSeason = RepoFactory.FilterPreset.GetByParentID(seasonsFilterID.Value) - .FirstOrDefault(f => f.Name == seasonName); - if (firstAirSeason == null) - return null; - - return GetFilter(firstAirSeason); - } } diff --git a/Shoko.Server/API/v3/Helpers/WebUIFactory.cs b/Shoko.Server/API/v3/Helpers/WebUIFactory.cs index 9255197a7..9d2599f98 100644 --- a/Shoko.Server/API/v3/Helpers/WebUIFactory.cs +++ b/Shoko.Server/API/v3/Helpers/WebUIFactory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Shoko.Models.Enums; using Shoko.Server.API.v3.Models.Common; using Shoko.Server.API.v3.Models.Shoko; using Shoko.Server.Models; @@ -22,11 +23,12 @@ public Models.Shoko.WebUI.WebUISeriesExtra GetWebUISeriesExtra(SVR_AnimeSeries s var animeEpisodes = anime.AniDBEpisodes; var runtimeLength = GuessCorrectRuntimeLength(animeEpisodes); var cast = Series.GetCast(anime.AnimeID, [Role.CreatorRoleType.Studio, Role.CreatorRoleType.Producer]); + var season = GetFirstAiringSeason(anime); var result = new Models.Shoko.WebUI.WebUISeriesExtra { RuntimeLength = runtimeLength, - FirstAirSeason = _filterFactory.GetFirstAiringSeasonGroupFilter(anime), + FirstAirSeason = season, Studios = cast.Where(role => role.RoleName == Role.CreatorRoleType.Studio).Select(role => role.Staff).ToList(), Producers = cast.Where(role => role.RoleName == Role.CreatorRoleType.Producer).Select(role => role.Staff).ToList(), SourceMaterial = Series.GetTags(anime, TagFilter.Filter.Invert | TagFilter.Filter.Source, excludeDescriptions: true).FirstOrDefault()?.Name ?? "Original Work", @@ -34,6 +36,16 @@ public Models.Shoko.WebUI.WebUISeriesExtra GetWebUISeriesExtra(SVR_AnimeSeries s return result; } + private static string GetFirstAiringSeason(SVR_AniDB_Anime anime) + { + var type = (AnimeType)anime.AnimeType; + if (type != AnimeType.TVSeries && type != AnimeType.Web) + return null; + + var (year, season) = anime.Seasons.FirstOrDefault(); + return year == 0 ? null : $"{season} {year}"; + } + private static TimeSpan? GuessCorrectRuntimeLength(IReadOnlyList episodes) { // Return early if empty. diff --git a/Shoko.Server/API/v3/Models/Shoko/WebUI.cs b/Shoko.Server/API/v3/Models/Shoko/WebUI.cs index 8cc41d342..43c9bc01f 100644 --- a/Shoko.Server/API/v3/Models/Shoko/WebUI.cs +++ b/Shoko.Server/API/v3/Models/Shoko/WebUI.cs @@ -127,7 +127,7 @@ public class WebUISeriesExtra /// The first season this show was aired in. /// /// - public Filter? FirstAirSeason { get; set; } + public string? FirstAirSeason { get; set; } /// /// A pre-filtered list of studios for the show.