update next up queries
This commit is contained in:
parent
f275d7f3d2
commit
1acebd9922
|
@ -121,17 +121,15 @@ namespace Emby.Server.Implementations.TV
|
||||||
|
|
||||||
var allNextUp = series
|
var allNextUp = series
|
||||||
.Select(i => GetNextUp(i, currentUser))
|
.Select(i => GetNextUp(i, currentUser))
|
||||||
.Where(i => i.Item1 != null)
|
|
||||||
// Include if an episode was found, and either the series is not unwatched or the specific series was requested
|
// Include if an episode was found, and either the series is not unwatched or the specific series was requested
|
||||||
.OrderByDescending(i => i.Item2)
|
.OrderByDescending(i => i.Item1)
|
||||||
.ThenByDescending(i => i.Item1.PremiereDate ?? DateTime.MinValue)
|
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// If viewing all next up for all series, remove first episodes
|
// If viewing all next up for all series, remove first episodes
|
||||||
if (string.IsNullOrWhiteSpace(request.SeriesId))
|
if (string.IsNullOrWhiteSpace(request.SeriesId))
|
||||||
{
|
{
|
||||||
var withoutFirstEpisode = allNextUp
|
var withoutFirstEpisode = allNextUp
|
||||||
.Where(i => !i.Item3)
|
.Where(i => i.Item1 != DateTime.MinValue)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// But if that returns empty, keep those first episodes (avoid completely empty view)
|
// But if that returns empty, keep those first episodes (avoid completely empty view)
|
||||||
|
@ -142,7 +140,8 @@ namespace Emby.Server.Implementations.TV
|
||||||
}
|
}
|
||||||
|
|
||||||
return allNextUp
|
return allNextUp
|
||||||
.Select(i => i.Item1)
|
.Select(i => i.Item2())
|
||||||
|
.Where(i => i != null)
|
||||||
.Take(request.Limit ?? int.MaxValue);
|
.Take(request.Limit ?? int.MaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +156,7 @@ namespace Emby.Server.Implementations.TV
|
||||||
/// <param name="series">The series.</param>
|
/// <param name="series">The series.</param>
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
/// <returns>Task{Episode}.</returns>
|
/// <returns>Task{Episode}.</returns>
|
||||||
private Tuple<Episode, DateTime, bool> GetNextUp(Series series, User user)
|
private Tuple<DateTime, Func<Episode>> GetNextUp(Series series, User user)
|
||||||
{
|
{
|
||||||
var lastWatchedEpisode = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
var lastWatchedEpisode = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
||||||
{
|
{
|
||||||
|
@ -171,31 +170,34 @@ namespace Emby.Server.Implementations.TV
|
||||||
|
|
||||||
}).FirstOrDefault();
|
}).FirstOrDefault();
|
||||||
|
|
||||||
var firstUnwatchedEpisode = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
Func<Episode> getEpisode = () =>
|
||||||
{
|
{
|
||||||
AncestorWithPresentationUniqueKey = GetUniqueSeriesKey(series),
|
return _libraryManager.GetItemList(new InternalItemsQuery(user)
|
||||||
IncludeItemTypes = new[] { typeof(Episode).Name },
|
{
|
||||||
SortBy = new[] { ItemSortBy.SortName },
|
AncestorWithPresentationUniqueKey = GetUniqueSeriesKey(series),
|
||||||
SortOrder = SortOrder.Ascending,
|
IncludeItemTypes = new[] { typeof(Episode).Name },
|
||||||
Limit = 1,
|
SortBy = new[] { ItemSortBy.SortName },
|
||||||
IsPlayed = false,
|
SortOrder = SortOrder.Ascending,
|
||||||
IsVirtualItem = false,
|
Limit = 1,
|
||||||
ParentIndexNumberNotEquals = 0,
|
IsPlayed = false,
|
||||||
MinSortName = lastWatchedEpisode == null ? null : lastWatchedEpisode.SortName
|
IsVirtualItem = false,
|
||||||
|
ParentIndexNumberNotEquals = 0,
|
||||||
|
MinSortName = lastWatchedEpisode == null ? null : lastWatchedEpisode.SortName
|
||||||
|
|
||||||
}).Cast<Episode>().FirstOrDefault();
|
}).Cast<Episode>().FirstOrDefault();
|
||||||
|
};
|
||||||
|
|
||||||
if (lastWatchedEpisode != null && firstUnwatchedEpisode != null)
|
if (lastWatchedEpisode != null)
|
||||||
{
|
{
|
||||||
var userData = _userDataManager.GetUserData(user, lastWatchedEpisode);
|
var userData = _userDataManager.GetUserData(user, lastWatchedEpisode);
|
||||||
|
|
||||||
var lastWatchedDate = userData.LastPlayedDate ?? DateTime.MinValue.AddDays(1);
|
var lastWatchedDate = userData.LastPlayedDate ?? DateTime.MinValue.AddDays(1);
|
||||||
|
|
||||||
return new Tuple<Episode, DateTime, bool>(firstUnwatchedEpisode, lastWatchedDate, false);
|
return new Tuple<DateTime, Func<Episode>>(lastWatchedDate, getEpisode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the first episode
|
// Return the first episode
|
||||||
return new Tuple<Episode, DateTime, bool>(firstUnwatchedEpisode, DateTime.MinValue, true);
|
return new Tuple<DateTime, Func<Episode>>(DateTime.MinValue, getEpisode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private QueryResult<BaseItem> GetResult(IEnumerable<BaseItem> items, int? totalRecordLimit, NextUpQuery query)
|
private QueryResult<BaseItem> GetResult(IEnumerable<BaseItem> items, int? totalRecordLimit, NextUpQuery query)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user