The Free Software Media System - Server Backend & API
Include specials in the calculation for the "Next Up" episode. Fixes #1479
Moshe Schmidt4bbfcaef8357
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.mdindex 1200275d52..bcc27b4dd8 100644--- a/CONTRIBUTORS.md+++ b/CONTRIBUTORS.md@@ -104,6 +104,7 @@- [shemanaev](https://github.com/shemanaev)- [skaro13](https://github.com/skaro13)- [sl1288](https://github.com/sl1288)+ - [Smith00101010](https://github.com/Smith00101010)- [sorinyo2004](https://github.com/sorinyo2004)- [sparky8251](https://github.com/sparky8251)- [spookbits](https://github.com/spookbits)diff --git a/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs b/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.csindex 1f68a9c810..60698e803d 100644--- a/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs+++ b/Emby.Server.Implementations/Sorting/AiredEpisodeOrderComparer.cs@@ -131,11 +131,11 @@ namespace Emby.Server.Implementations.Sortingreturn GetSpecialCompareValue(x).CompareTo(GetSpecialCompareValue(y));}- private static int GetSpecialCompareValue(Episode item)+ private static long GetSpecialCompareValue(Episode item){// First sort by season number// Since there are three sort orders, pad with 9 digits (3 for each, figure 1000 episode buffer should be enough)- var val = (item.AirsAfterSeasonNumber ?? item.AirsBeforeSeasonNumber ?? 0) * 1000000000;+ var val = (item.AirsAfterSeasonNumber ?? item.AirsBeforeSeasonNumber ?? 0) * 1000000000L;// Second sort order is if it airs after the seasonif (item.AirsAfterSeasonNumber.HasValue)diff --git a/Emby.Server.Implementations/TV/TVSeriesManager.cs b/Emby.Server.Implementations/TV/TVSeriesManager.csindex 839b62448b..d111e1a1c6 100644--- a/Emby.Server.Implementations/TV/TVSeriesManager.cs+++ b/Emby.Server.Implementations/TV/TVSeriesManager.cs@@ -2,7 +2,6 @@using System;using System.Collections.Generic;-using System.Globalization;using System.Linq;using Jellyfin.Data.Entities;using Jellyfin.Data.Enums;@@ -11,7 +10,6 @@ using MediaBrowser.Controller.Dto;using MediaBrowser.Controller.Entities;using MediaBrowser.Controller.Library;using MediaBrowser.Controller.TV;-using MediaBrowser.Model.Entities;using MediaBrowser.Model.Querying;using Episode = MediaBrowser.Controller.Entities.TV.Episode;using Series = MediaBrowser.Controller.Entities.TV.Series;@@ -23,12 +21,14 @@ namespace Emby.Server.Implementations.TVprivate readonly IUserManager _userManager;private readonly IUserDataManager _userDataManager;private readonly ILibraryManager _libraryManager;+ private readonly IServerConfigurationManager _configurationManager;- public TVSeriesManager(IUserManager userManager, IUserDataManager userDataManager, ILibraryManager libraryManager)+ public TVSeriesManager(IUserManager userManager, IUserDataManager userDataManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager){_userManager = userManager;_userDataManager = userDataManager;_libraryManager = libraryManager;+ _configurationManager = configurationManager;}public QueryResult<BaseItem> GetNextUp(NextUpQuery request, DtoOptions dtoOptions)@@ -200,13 +200,10 @@ namespace Emby.Server.Implementations.TVParentIndexNumberNotEquals = 0,DtoOptions = new DtoOptions{- Fields = new ItemFields[]- {- ItemFields.SortName- },+ Fields = new[] { ItemFields.SortName },EnableImages = false}- }).FirstOrDefault();+ }).Cast<Episode>().FirstOrDefault();Func<Episode> getEpisode = () =>{@@ -224,6 +221,39 @@ namespace Emby.Server.Implementations.TVDtoOptions = dtoOptions}).Cast<Episode>().FirstOrDefault();+ if (_configurationManager.Configuration.DisplaySpecialsWithinSeasons)+ {+ var consideredEpisodes = _libraryManager.GetItemList(new InternalItemsQuery(user)+ {+ AncestorWithPresentationUniqueKey = null,+ SeriesPresentationUniqueKey = seriesKey,+ ParentIndexNumber = 0,+ IncludeItemTypes = new[] { nameof(Episode) },+ IsPlayed = false,+ IsVirtualItem = false,+ DtoOptions = dtoOptions+ }).Cast<Episode>().Where(episode => episode.AirsBeforeSeasonNumber != null || episode.AirsAfterSeasonNumber != null).ToList();++ if (lastWatchedEpisode != null)+ {+ // Last watched episode is added, because there could be specials that aired before the last watched episode+ consideredEpisodes.Add(lastWatchedEpisode);+ }++ if (nextEpisode != null)+ {+ consideredEpisodes.Add(nextEpisode);+ }++ var sortedConsideredEpisodes = _libraryManager.Sort(consideredEpisodes, user, new[] { (ItemSortBy.AiredEpisodeOrder, SortOrder.Ascending) }).Cast<Episode>();+ if (lastWatchedEpisode != null)+ {+ sortedConsideredEpisodes = sortedConsideredEpisodes.SkipWhile(episode => episode.Id != lastWatchedEpisode.Id).Skip(1);+ }++ nextEpisode = sortedConsideredEpisodes.FirstOrDefault();+ }+if (nextEpisode != null){var userData = _userDataManager.GetUserData(user, nextEpisode);