Skip to content

Commit

Permalink
Partially revert "misc: use shoko preferred title for episode"
Browse files Browse the repository at this point in the history
This partially reverts commit 0d63a2f.
  • Loading branch information
revam committed Nov 28, 2023
1 parent 0d63a2f commit 78763ac
Showing 1 changed file with 71 additions and 14 deletions.
85 changes: 71 additions & 14 deletions Shokofin/Utils/OrderingUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ 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 @@ -84,7 +78,7 @@ public enum SpecialOrderType {
AfterSeason = 2,

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

Expand All @@ -99,6 +93,68 @@ 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 @@ -113,7 +169,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 @@ -125,14 +181,14 @@ public static int GetEpisodeNumber(ShowInfo group, SeasonInfo series, EpisodeInf
case GroupType.ShokoGroup: {
int offset = 0;
if (episode.AniDB.Type == EpisodeType.Special) {
var seasonIndex = group.SeasonList.FindIndex(s => string.Equals(s.Id, series.Id));
if (seasonIndex == -1)
var seriesIndex = group.SeasonList.FindIndex(s => string.Equals(s.Id, series.Id));
if (seriesIndex == -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, seasonIndex).Aggregate(0, (count, series) => count + series.SpecialsList.Count);
return offset + index + 1;
offset = group.SeasonList.GetRange(0, seriesIndex).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 @@ -276,6 +332,7 @@ 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 @@ -290,7 +347,7 @@ public static int GetSeasonNumber(ShowInfo group, SeasonInfo series, EpisodeInfo
}
}

return seasonNumber + offset;
return seasonNumber + (seasonNumber < 0 ? -offset : offset);
}
}
}
Expand Down Expand Up @@ -327,7 +384,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.ThemeVideo;
return ExtraType.Clip;
// Behind the Scenes
if (title.Contains("making of", System.StringComparison.CurrentCultureIgnoreCase))
return ExtraType.BehindTheScenes;
Expand Down

0 comments on commit 78763ac

Please sign in to comment.