Backport pull request #8662 from jellyfin/release-10.8.z
fix: use a combination of ParentIndexNumber and IndexNumber to determine next up episodes Original-merge: 45f3fb1cfc54f4dced7f6e02b7fc433056678634 Merged-by: Joshua M. Boniface <joshua@boniface.me> Backported-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
parent
7725949ead
commit
08d2acba20
|
@ -3524,10 +3524,11 @@ namespace Emby.Server.Implementations.Data
|
||||||
statement?.TryBind("@MinIndexNumber", query.MinIndexNumber.Value);
|
statement?.TryBind("@MinIndexNumber", query.MinIndexNumber.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.MinParentIndexNumber.HasValue)
|
if (query.MinParentAndIndexNumber.HasValue)
|
||||||
{
|
{
|
||||||
whereClauses.Add("ParentIndexNumber>=@MinParentIndexNumber");
|
whereClauses.Add("((ParentIndexNumber=@MinParentAndIndexNumberParent and IndexNumber>=@MinParentAndIndexNumberIndex) or ParentIndexNumber>@MinParentAndIndexNumberParent)");
|
||||||
statement?.TryBind("@MinParentIndexNumber", query.MinParentIndexNumber.Value);
|
statement?.TryBind("@MinParentAndIndexNumberParent", query.MinParentAndIndexNumber.Value.ParentIndexNumber);
|
||||||
|
statement?.TryBind("@MinParentAndIndexNumberIndex", query.MinParentAndIndexNumber.Value.IndexNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.MinDateCreated.HasValue)
|
if (query.MinDateCreated.HasValue)
|
||||||
|
|
|
@ -192,7 +192,6 @@ namespace Emby.Server.Implementations.TV
|
||||||
AncestorWithPresentationUniqueKey = null,
|
AncestorWithPresentationUniqueKey = null,
|
||||||
SeriesPresentationUniqueKey = seriesKey,
|
SeriesPresentationUniqueKey = seriesKey,
|
||||||
IncludeItemTypes = new[] { BaseItemKind.Episode },
|
IncludeItemTypes = new[] { BaseItemKind.Episode },
|
||||||
OrderBy = new[] { (ItemSortBy.ParentIndexNumber, SortOrder.Descending), (ItemSortBy.IndexNumber, SortOrder.Descending) },
|
|
||||||
IsPlayed = true,
|
IsPlayed = true,
|
||||||
Limit = 1,
|
Limit = 1,
|
||||||
ParentIndexNumberNotEquals = 0,
|
ParentIndexNumberNotEquals = 0,
|
||||||
|
@ -203,11 +202,10 @@ namespace Emby.Server.Implementations.TV
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (rewatching)
|
// If rewatching is enabled, sort first by date played and then by season and episode numbers
|
||||||
{
|
lastQuery.OrderBy = rewatching
|
||||||
// find last watched by date played, not by newest episode watched
|
? new[] { (ItemSortBy.DatePlayed, SortOrder.Descending), (ItemSortBy.ParentIndexNumber, SortOrder.Descending), (ItemSortBy.IndexNumber, SortOrder.Descending) }
|
||||||
lastQuery.OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending), (ItemSortBy.ParentIndexNumber, SortOrder.Descending), (ItemSortBy.IndexNumber, SortOrder.Descending) };
|
: new[] { (ItemSortBy.ParentIndexNumber, SortOrder.Descending), (ItemSortBy.IndexNumber, SortOrder.Descending) };
|
||||||
}
|
|
||||||
|
|
||||||
var lastWatchedEpisode = _libraryManager.GetItemList(lastQuery).Cast<Episode>().FirstOrDefault();
|
var lastWatchedEpisode = _libraryManager.GetItemList(lastQuery).Cast<Episode>().FirstOrDefault();
|
||||||
|
|
||||||
|
@ -223,23 +221,19 @@ namespace Emby.Server.Implementations.TV
|
||||||
IsPlayed = rewatching,
|
IsPlayed = rewatching,
|
||||||
IsVirtualItem = false,
|
IsVirtualItem = false,
|
||||||
ParentIndexNumberNotEquals = 0,
|
ParentIndexNumberNotEquals = 0,
|
||||||
DtoOptions = dtoOptions,
|
DtoOptions = dtoOptions
|
||||||
MinIndexNumber = lastWatchedEpisode?.IndexNumberEnd ?? lastWatchedEpisode?.IndexNumber,
|
|
||||||
MinParentIndexNumber = lastWatchedEpisode?.ParentIndexNumber
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Episode nextEpisode;
|
// Locate the next up episode based on the last watched episode's season and episode number
|
||||||
if (rewatching)
|
var lastWatchedParentIndexNumber = lastWatchedEpisode?.ParentIndexNumber;
|
||||||
|
var lastWatchedIndexNumber = lastWatchedEpisode?.IndexNumberEnd ?? lastWatchedEpisode?.IndexNumber;
|
||||||
|
if (lastWatchedParentIndexNumber.HasValue && lastWatchedIndexNumber.HasValue)
|
||||||
{
|
{
|
||||||
nextQuery.Limit = 2;
|
nextQuery.MinParentAndIndexNumber = (lastWatchedParentIndexNumber.Value, lastWatchedIndexNumber.Value + 1);
|
||||||
// get watched episode after most recently watched
|
|
||||||
nextEpisode = _libraryManager.GetItemList(nextQuery).Cast<Episode>().ElementAtOrDefault(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nextEpisode = _libraryManager.GetItemList(nextQuery).Cast<Episode>().FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nextEpisode = _libraryManager.GetItemList(nextQuery).Cast<Episode>().FirstOrDefault();
|
||||||
|
|
||||||
if (_configurationManager.Configuration.DisplaySpecialsWithinSeasons)
|
if (_configurationManager.Configuration.DisplaySpecialsWithinSeasons)
|
||||||
{
|
{
|
||||||
var consideredEpisodes = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
var consideredEpisodes = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
||||||
|
|
|
@ -205,7 +205,15 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
public int? MinIndexNumber { get; set; }
|
public int? MinIndexNumber { get; set; }
|
||||||
|
|
||||||
public int? MinParentIndexNumber { get; set; }
|
/// <summary>
|
||||||
|
/// Gets or sets the minimum ParentIndexNumber and IndexNumber.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// It produces this where clause:
|
||||||
|
/// <para>(ParentIndexNumber = X and IndexNumber >= Y) or ParentIndexNumber > X.
|
||||||
|
/// </para>
|
||||||
|
/// </remarks>
|
||||||
|
public (int ParentIndexNumber, int IndexNumber)? MinParentAndIndexNumber { get; set; }
|
||||||
|
|
||||||
public int? AiredDuringSeason { get; set; }
|
public int? AiredDuringSeason { get; set; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user