Skip to content

Commit

Permalink
misc: use shoko preferred title for episode
Browse files Browse the repository at this point in the history
when we want the main title for the series, since there is no main title
for the episode, and we currently do not have any per-entity type
settings.
  • Loading branch information
revam committed Nov 28, 2023
1 parent 84014b6 commit 0d63a2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 72 deletions.
85 changes: 14 additions & 71 deletions Shokofin/Utils/OrderingUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public enum GroupType
/// Group movies based on Shoko's series.
/// </summary>
ShokoSeries = 3,

/// <summary>
/// Group both movies and shows into collections based on shoko's
/// groups.
/// </summary>
ShokoGroupPlus = 4,
}

/// <summary>
Expand Down Expand Up @@ -78,7 +84,7 @@ public enum SpecialOrderType {
AfterSeason = 2,

/// <summary>
/// Use a mix of <see cref="Shokofin.Utils.Ordering.SpecialOrderType.InBetweenSeasonByOtherData" /> and <see cref="Shokofin.Utils.Ordering.SpecialOrderType.InBetweenSeasonByAirDate" />.
/// Use a mix of <see cref="InBetweenSeasonByOtherData" /> and <see cref="InBetweenSeasonByAirDate" />.
/// </summary>
InBetweenSeasonMixed = 3,

Expand All @@ -93,68 +99,6 @@ public enum SpecialOrderType {
InBetweenSeasonByOtherData = 5,
}

/// <summary>
/// Get index number for a movie in a box-set.
/// </summary>
/// <returns>Absolute index.</returns>
public static int GetMovieIndexNumber(ShowInfo group, SeasonInfo series, EpisodeInfo episode)
{
switch (Plugin.Instance.Configuration.BoxSetGrouping) {
default:
case GroupType.Default:
return 1;
case GroupType.ShokoSeries:
return episode.AniDB.EpisodeNumber;
case GroupType.ShokoGroup: {
int offset = 0;
foreach (SeasonInfo s in group.SeasonList) {
var sizes = s.Shoko.Sizes.Total;
if (s != series) {
if (episode.AniDB.Type == EpisodeType.Special) {
var index = series.SpecialsList.FindIndex(e => string.Equals(e.Id, episode.Id));
if (index == -1)
throw new System.IndexOutOfRangeException($"Episode not in the filtered specials list. (Group={group.Id},Series={series.Id},Episode={episode.Id})");
return offset - (index + 1);
}
switch (episode.AniDB.Type) {
case EpisodeType.Normal:
// offset += 0; // it's not needed, so it's just here as a comment instead.
break;
case EpisodeType.Special:
offset += sizes?.Episodes ?? 0;
goto case EpisodeType.Normal;
case EpisodeType.Unknown:
offset += sizes?.Specials ?? 0;
goto case EpisodeType.Special;
// Add them to the bottom of the list if we didn't filter them out properly.
case EpisodeType.Parody:
offset += sizes?.Others ?? 0;
goto case EpisodeType.Unknown;
case EpisodeType.OpeningSong:
offset += sizes?.Parodies ?? 0;
goto case EpisodeType.Parody;
case EpisodeType.Trailer:
offset += sizes?.Credits ?? 0;
goto case EpisodeType.OpeningSong;
default:
offset += sizes?.Trailers ?? 0;
goto case EpisodeType.Trailer;
}
return offset + episode.AniDB.EpisodeNumber;
}
else {
if (episode.AniDB.Type == EpisodeType.Special) {
offset -= series.SpecialsList.Count;
}
offset += (sizes?.Episodes ?? 0) + (sizes?.Parodies ?? 0) + (sizes?.Others ?? 0);
}
}
break;
}
}
return 0;
}

/// <summary>
/// Get index number for an episode in a series.
/// </summary>
Expand All @@ -169,7 +113,7 @@ public static int GetEpisodeNumber(ShowInfo group, SeasonInfo series, EpisodeInf
var index = series.SpecialsList.FindIndex(e => string.Equals(e.Id, episode.Id));
if (index == -1)
throw new System.IndexOutOfRangeException($"Episode not in the filtered specials list. (Series={series.Id},Episode={episode.Id})");
return (index + 1);
return index + 1;
}
return episode.AniDB.EpisodeNumber;
case GroupType.MergeFriendly: {
Expand All @@ -181,14 +125,14 @@ public static int GetEpisodeNumber(ShowInfo group, SeasonInfo series, EpisodeInf
case GroupType.ShokoGroup: {
int offset = 0;
if (episode.AniDB.Type == EpisodeType.Special) {
var seriesIndex = group.SeasonList.FindIndex(s => string.Equals(s.Id, series.Id));
if (seriesIndex == -1)
var seasonIndex = group.SeasonList.FindIndex(s => string.Equals(s.Id, series.Id));
if (seasonIndex == -1)
throw new System.IndexOutOfRangeException($"Series is not part of the provided group. (Group={group.Id},Series={series.Id},Episode={episode.Id})");
var index = series.SpecialsList.FindIndex(e => string.Equals(e.Id, episode.Id));
if (index == -1)
throw new System.IndexOutOfRangeException($"Episode not in the filtered specials list. (Group={group.Id},Series={series.Id},Episode={episode.Id})");
offset = group.SeasonList.GetRange(0, seriesIndex).Aggregate(0, (count, series) => count + series.SpecialsList.Count);
return offset + (index + 1);
offset = group.SeasonList.GetRange(0, seasonIndex).Aggregate(0, (count, series) => count + series.SpecialsList.Count);
return offset + index + 1;
}
var sizes = series.Shoko.Sizes.Total;
switch (episode.AniDB.Type) {
Expand Down Expand Up @@ -332,7 +276,6 @@ public static int GetSeasonNumber(ShowInfo group, SeasonInfo series, EpisodeInfo
if (!group.SeasonNumberBaseDictionary.TryGetValue(series, out var seasonNumber))
throw new System.IndexOutOfRangeException($"Series is not part of the provided group. (Group={group.Id},Series={series.Id})");


var offset = 0;
switch (episode.AniDB.Type) {
default:
Expand All @@ -347,7 +290,7 @@ public static int GetSeasonNumber(ShowInfo group, SeasonInfo series, EpisodeInfo
}
}

return seasonNumber + (seasonNumber < 0 ? -offset : offset);
return seasonNumber + offset;
}
}
}
Expand Down Expand Up @@ -384,7 +327,7 @@ public static int GetSeasonNumber(ShowInfo group, SeasonInfo series, EpisodeInfo
return ExtraType.Clip;
// Music videos
if (title.Contains("music video", System.StringComparison.OrdinalIgnoreCase))
return ExtraType.Clip;
return ExtraType.ThemeVideo;
// Behind the Scenes
if (title.Contains("making of", System.StringComparison.CurrentCultureIgnoreCase))
return ExtraType.BehindTheScenes;
Expand Down
2 changes: 1 addition & 1 deletion Shokofin/Utils/TextUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public static string GetTitle(IEnumerable<Title> seriesTitles, IEnumerable<Title
// Display the main title.
case DisplayLanguageType.Main: {
var getSeriesTitle = () => GetTitleByType(seriesTitles, TitleType.Main) ?? seriesTitle;
var getEpisodeTitle = () => GetTitleByLanguages(episodeTitles, "en", mainTitleLanguage) ?? episodeTitle;
var getEpisodeTitle = () => episodeTitle;
return ConstructTitle(getSeriesTitle, getEpisodeTitle, outputType);
}
}
Expand Down

0 comments on commit 0d63a2f

Please sign in to comment.