Skip to content

Commit

Permalink
Add option to ignore indirect relations for chronological order
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmohan committed Apr 27, 2024
1 parent 07b76dc commit f1f0d28
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
7 changes: 4 additions & 3 deletions Shokofin/API/Info/ShowInfo.cs
Expand Up @@ -55,7 +55,7 @@ public class ShowInfo
/// <summary>
/// Ended date of the show.
/// </summary>
public DateTime? EndDate =>
public DateTime? EndDate =>
SeasonList.Any(s => s.AniDB.EndDate == null) ? null : SeasonList
.Select(s => s.AniDB.AirDate)
.OrderBy(s => s)
Expand Down Expand Up @@ -190,6 +190,7 @@ public ShowInfo(Group group, List<SeasonInfo> seasonList, ILogger logger, bool u
seasonList = seasonList.OrderBy(s => s?.AniDB?.AirDate ?? DateTime.MaxValue).ToList();
break;
case Ordering.OrderType.Chronological:
case Ordering.OrderType.ChronologicalIgnoreIndirect:
seasonList.Sort(new SeriesInfoRelationComparer());
break;
}
Expand All @@ -201,11 +202,11 @@ public ShowInfo(Group group, List<SeasonInfo> seasonList, ILogger logger, bool u
foundIndex = 0;
break;
case Ordering.OrderType.Default:
case Ordering.OrderType.Chronological: {
case Ordering.OrderType.Chronological:
case Ordering.OrderType.ChronologicalIgnoreIndirect:
int targetId = group.IDs.MainSeries;
foundIndex = seasonList.FindIndex(s => s.Shoko.IDs.Shoko == targetId);
break;
}
}

// Fallback to the first series if we can't get a base point for seasons.
Expand Down
3 changes: 2 additions & 1 deletion Shokofin/Configuration/configPage.html
Expand Up @@ -164,7 +164,8 @@ <h3>Library Settings</h3>
<select is="emby-select" id="SeasonOrdering" name="SeasonOrdering" class="emby-select-withcolor emby-select" disabled>
<option value="Default" selected>Let Shoko decide</option>
<option value="ReleaseDate">Order seasons by release date</option>
<option value="Chronological">Order seasons in chronological order</option>
<option value="Chronological">Order seasons in chronological order (use indirect relations)</option>
<option value="ChronologicalIgnoreIndirect">Order seasons in chronological order (ignore indirect relations)</option>
</select>
<div class="fieldDescription">Determines how to order seasons within each show using the Shoko groups.</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions Shokofin/Utils/Ordering.cs
Expand Up @@ -49,6 +49,11 @@ public enum OrderType
/// Order seasons based on the chronological order of relations.
/// </summary>
Chronological = 2,

/// <summary>
/// Order seasons based on the chronological order of only direct relations.
/// </summary>
ChronologicalIgnoreIndirect = 3,
}

public enum SpecialOrderType {
Expand Down
9 changes: 6 additions & 3 deletions Shokofin/Utils/SeriesInfoRelationComparer.cs
Expand Up @@ -40,9 +40,12 @@ public int Compare(SeasonInfo? a, SeasonInfo? b)
return directRelationComparison;

// Check for indirect relations.
var indirectRelationComparison = CompareIndirectRelations(a, b);
if (indirectRelationComparison != 0)
return indirectRelationComparison;
if (Plugin.Instance.Configuration.SeasonOrdering != Ordering.OrderType.ChronologicalIgnoreIndirect)
{
var indirectRelationComparison = CompareIndirectRelations(a, b);
if (indirectRelationComparison != 0)
return indirectRelationComparison;
}

// Fallback to checking the air dates if they're not indirectly related
// or if they have the same relations.
Expand Down

0 comments on commit f1f0d28

Please sign in to comment.