aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcvium <clausvium@gmail.com>2022-10-31 23:08:42 -0400
committerJoshua M. Boniface <joshua@boniface.me>2022-10-31 23:08:42 -0400
commit08d2acba20a7b0461ae84d778d777a5046cbf717 (patch)
treef35192007564d03bb8a89da7d215d9740bae7f65
parent7725949eada288205f901aac42bad49b3c6cb1d6 (diff)
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>
-rw-r--r--Emby.Server.Implementations/Data/SqliteItemRepository.cs7
-rw-r--r--Emby.Server.Implementations/TV/TVSeriesManager.cs30
-rw-r--r--MediaBrowser.Controller/Entities/InternalItemsQuery.cs10
3 files changed, 25 insertions, 22 deletions
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
index 0ebcd4c0b..371111dff 100644
--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
@@ -3524,10 +3524,11 @@ namespace Emby.Server.Implementations.Data
statement?.TryBind("@MinIndexNumber", query.MinIndexNumber.Value);
}
- if (query.MinParentIndexNumber.HasValue)
+ if (query.MinParentAndIndexNumber.HasValue)
{
- whereClauses.Add("ParentIndexNumber>=@MinParentIndexNumber");
- statement?.TryBind("@MinParentIndexNumber", query.MinParentIndexNumber.Value);
+ whereClauses.Add("((ParentIndexNumber=@MinParentAndIndexNumberParent and IndexNumber>=@MinParentAndIndexNumberIndex) or ParentIndexNumber>@MinParentAndIndexNumberParent)");
+ statement?.TryBind("@MinParentAndIndexNumberParent", query.MinParentAndIndexNumber.Value.ParentIndexNumber);
+ statement?.TryBind("@MinParentAndIndexNumberIndex", query.MinParentAndIndexNumber.Value.IndexNumber);
}
if (query.MinDateCreated.HasValue)
diff --git a/Emby.Server.Implementations/TV/TVSeriesManager.cs b/Emby.Server.Implementations/TV/TVSeriesManager.cs
index be57d9c68..5c9b9df15 100644
--- a/Emby.Server.Implementations/TV/TVSeriesManager.cs
+++ b/Emby.Server.Implementations/TV/TVSeriesManager.cs
@@ -192,7 +192,6 @@ namespace Emby.Server.Implementations.TV
AncestorWithPresentationUniqueKey = null,
SeriesPresentationUniqueKey = seriesKey,
IncludeItemTypes = new[] { BaseItemKind.Episode },
- OrderBy = new[] { (ItemSortBy.ParentIndexNumber, SortOrder.Descending), (ItemSortBy.IndexNumber, SortOrder.Descending) },
IsPlayed = true,
Limit = 1,
ParentIndexNumberNotEquals = 0,
@@ -203,11 +202,10 @@ namespace Emby.Server.Implementations.TV
}
};
- if (rewatching)
- {
- // find last watched by date played, not by newest episode watched
- lastQuery.OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending), (ItemSortBy.ParentIndexNumber, SortOrder.Descending), (ItemSortBy.IndexNumber, SortOrder.Descending) };
- }
+ // If rewatching is enabled, sort first by date played and then by season and episode numbers
+ lastQuery.OrderBy = rewatching
+ ? 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();
@@ -223,23 +221,19 @@ namespace Emby.Server.Implementations.TV
IsPlayed = rewatching,
IsVirtualItem = false,
ParentIndexNumberNotEquals = 0,
- DtoOptions = dtoOptions,
- MinIndexNumber = lastWatchedEpisode?.IndexNumberEnd ?? lastWatchedEpisode?.IndexNumber,
- MinParentIndexNumber = lastWatchedEpisode?.ParentIndexNumber
+ DtoOptions = dtoOptions
};
- Episode nextEpisode;
- if (rewatching)
- {
- nextQuery.Limit = 2;
- // get watched episode after most recently watched
- nextEpisode = _libraryManager.GetItemList(nextQuery).Cast<Episode>().ElementAtOrDefault(1);
- }
- else
+ // Locate the next up episode based on the last watched episode's season and episode number
+ var lastWatchedParentIndexNumber = lastWatchedEpisode?.ParentIndexNumber;
+ var lastWatchedIndexNumber = lastWatchedEpisode?.IndexNumberEnd ?? lastWatchedEpisode?.IndexNumber;
+ if (lastWatchedParentIndexNumber.HasValue && lastWatchedIndexNumber.HasValue)
{
- nextEpisode = _libraryManager.GetItemList(nextQuery).Cast<Episode>().FirstOrDefault();
+ nextQuery.MinParentAndIndexNumber = (lastWatchedParentIndexNumber.Value, lastWatchedIndexNumber.Value + 1);
}
+ var nextEpisode = _libraryManager.GetItemList(nextQuery).Cast<Episode>().FirstOrDefault();
+
if (_configurationManager.Configuration.DisplaySpecialsWithinSeasons)
{
var consideredEpisodes = _libraryManager.GetItemList(new InternalItemsQuery(user)
diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs
index 9ae21bb59..1bf528538 100644
--- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs
+++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs
@@ -205,7 +205,15 @@ namespace MediaBrowser.Controller.Entities
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; }