Skip to content

Commit

Permalink
Fix FirstAirSeason in webui controller
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmohan committed Aug 22, 2024
1 parent b95b879 commit fca8220
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
29 changes: 3 additions & 26 deletions Shoko.Server/API/v3/Helpers/FilterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public Filter.FilterCondition GetExpressionTree(FilterExpression expression)

return result;
}

public FilterExpression<T> GetExpressionTree<T>(Filter.FilterCondition condition)
{
if (condition is null) return null;
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
14 changes: 13 additions & 1 deletion Shoko.Server/API/v3/Helpers/WebUIFactory.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,18 +23,29 @@ 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",
};
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<SVR_AniDB_Episode> episodes)
{
// Return early if empty.
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/API/v3/Models/Shoko/WebUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class WebUISeriesExtra
/// The first season this show was aired in.
/// </summary>
/// <value></value>
public Filter? FirstAirSeason { get; set; }
public string? FirstAirSeason { get; set; }

/// <summary>
/// A pre-filtered list of studios for the show.
Expand Down

0 comments on commit fca8220

Please sign in to comment.