diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs
index 11cd72cf40..9521f82cce 100644
--- a/MediaBrowser.Api/TvShowsService.cs
+++ b/MediaBrowser.Api/TvShowsService.cs
@@ -192,18 +192,6 @@ namespace MediaBrowser.Api
/// The request.
/// System.Object.
public object Get(GetNextUpEpisodes request)
- {
- var result = GetNextUpEpisodeItemsResult(request);
-
- return ToOptimizedResult(result);
- }
-
- ///
- /// Gets the next up episodes.
- ///
- /// The request.
- /// Task{ItemsResult}.
- private ItemsResult GetNextUpEpisodeItemsResult(GetNextUpEpisodes request)
{
var user = _userManager.GetUserById(request.UserId);
@@ -216,11 +204,13 @@ namespace MediaBrowser.Api
var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray();
- return new ItemsResult
+ var result = new ItemsResult
{
TotalRecordCount = itemsList.Count,
Items = returnItems
};
+
+ return ToOptimizedResult(result);
}
public IEnumerable GetNextUpEpisodes(GetNextUpEpisodes request)
@@ -274,14 +264,12 @@ namespace MediaBrowser.Api
/// Task{Episode}.
private Tuple GetNextUp(Series series, User user, GetNextUpEpisodes request)
{
- var allEpisodes = series.GetRecursiveChildren(user)
- .OfType()
- .OrderByDescending(i => i.PremiereDate ?? DateTime.MinValue)
- .ThenByDescending(i => i.IndexNumber ?? 0)
+ // Get them in display order, then reverse
+ var allEpisodes = series.GetSeasons(user, true, true)
+ .SelectMany(i => i.GetEpisodes(user, true, true))
+ .Reverse()
.ToList();
- allEpisodes = FilterItems(request, allEpisodes).ToList();
-
Episode lastWatched = null;
var lastWatchedDate = DateTime.MinValue;
Episode nextUp = null;
@@ -303,7 +291,10 @@ namespace MediaBrowser.Api
}
else
{
- nextUp = episode;
+ if (episode.LocationType != LocationType.Virtual)
+ {
+ nextUp = episode;
+ }
}
}
@@ -315,15 +306,6 @@ namespace MediaBrowser.Api
return new Tuple(null, lastWatchedDate);
}
-
- private IEnumerable FilterItems(GetNextUpEpisodes request, IEnumerable items)
- {
- // Make this configurable when needed
- items = items.Where(i => i.LocationType != LocationType.Virtual);
-
- return items;
- }
-
private IEnumerable FilterSeries(GetNextUpEpisodes request, IEnumerable items)
{
if (!string.IsNullOrWhiteSpace(request.SeriesId))
@@ -369,6 +351,7 @@ namespace MediaBrowser.Api
{
throw new ResourceNotFoundException("No series exists with Id " + request.Id);
}
+
var seasons = series.GetSeasons(user);
if (request.IsSpecialSeason.HasValue)
diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs
index a53bb53f1e..5727b316bb 100644
--- a/MediaBrowser.Controller/Entities/TV/Season.cs
+++ b/MediaBrowser.Controller/Entities/TV/Season.cs
@@ -221,6 +221,13 @@ namespace MediaBrowser.Controller.Entities.TV
/// The user.
/// IEnumerable{Episode}.
public IEnumerable GetEpisodes(User user)
+ {
+ var config = user.Configuration;
+
+ return GetEpisodes(user, config.DisplayMissingEpisodes, config.DisplayUnairedEpisodes);
+ }
+
+ public IEnumerable GetEpisodes(User user, bool includeMissingEpisodes, bool includeVirtualUnairedEpisodes)
{
if (IndexNumber.HasValue)
{
@@ -228,13 +235,22 @@ namespace MediaBrowser.Controller.Entities.TV
if (series != null)
{
- return series.GetEpisodes(user, IndexNumber.Value);
+ return series.GetEpisodes(user, IndexNumber.Value, includeMissingEpisodes, includeVirtualUnairedEpisodes);
}
}
var episodes = GetRecursiveChildren(user)
.OfType();
+ if (!includeMissingEpisodes)
+ {
+ episodes = episodes.Where(i => !i.IsMissingEpisode);
+ }
+ if (!includeVirtualUnairedEpisodes)
+ {
+ episodes = episodes.Where(i => !i.IsVirtualUnaired);
+ }
+
return LibraryManager
.Sort(episodes, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending)
.Cast();
diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs
index c48b44d91f..1565de4f8d 100644
--- a/MediaBrowser.Controller/Entities/TV/Series.cs
+++ b/MediaBrowser.Controller/Entities/TV/Series.cs
@@ -128,23 +128,28 @@ namespace MediaBrowser.Controller.Entities.TV
}
public IEnumerable GetSeasons(User user)
+ {
+ var config = user.Configuration;
+
+ return GetSeasons(user, config.DisplayMissingEpisodes, config.DisplayUnairedEpisodes);
+ }
+
+ public IEnumerable GetSeasons(User user, bool includeMissingSeasons, bool includeVirtualUnaired)
{
var seasons = base.GetChildren(user, true)
.OfType();
- var config = user.Configuration;
-
- if (!config.DisplayMissingEpisodes && !config.DisplayUnairedEpisodes)
+ if (!includeMissingSeasons && !includeVirtualUnaired)
{
seasons = seasons.Where(i => !i.IsMissingOrVirtualUnaired);
}
else
{
- if (!config.DisplayMissingEpisodes)
+ if (!includeMissingSeasons)
{
seasons = seasons.Where(i => !i.IsMissingSeason);
}
- if (!config.DisplayUnairedEpisodes)
+ if (!includeVirtualUnaired)
{
seasons = seasons.Where(i => !i.IsVirtualUnaired);
}
@@ -152,23 +157,28 @@ namespace MediaBrowser.Controller.Entities.TV
return LibraryManager
.Sort(seasons, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending)
- .Cast();
+ .Cast();
}
public IEnumerable GetEpisodes(User user, int seasonNumber)
+ {
+ var config = user.Configuration;
+
+ return GetEpisodes(user, seasonNumber, config.DisplayMissingEpisodes, config.DisplayUnairedEpisodes);
+ }
+
+ public IEnumerable GetEpisodes(User user, int seasonNumber, bool includeMissingEpisodes, bool includeVirtualUnairedEpisodes)
{
var episodes = GetRecursiveChildren(user)
.OfType();
episodes = FilterEpisodesBySeason(episodes, seasonNumber, DisplaySpecialsWithSeasons);
- var config = user.Configuration;
-
- if (!config.DisplayMissingEpisodes)
+ if (!includeMissingEpisodes)
{
episodes = episodes.Where(i => !i.IsMissingEpisode);
}
- if (!config.DisplayUnairedEpisodes)
+ if (!includeVirtualUnairedEpisodes)
{
episodes = episodes.Where(i => !i.IsVirtualUnaired);
}