make next up smarter using watched history from deleted items
This commit is contained in:
parent
7ea2bdcf16
commit
aa83cb75fd
|
@ -192,18 +192,6 @@ namespace MediaBrowser.Api
|
|||
/// <param name="request">The request.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetNextUpEpisodes request)
|
||||
{
|
||||
var result = GetNextUpEpisodeItemsResult(request);
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the next up episodes.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>Task{ItemsResult}.</returns>
|
||||
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<Episode> GetNextUpEpisodes(GetNextUpEpisodes request)
|
||||
|
@ -274,14 +264,12 @@ namespace MediaBrowser.Api
|
|||
/// <returns>Task{Episode}.</returns>
|
||||
private Tuple<Episode, DateTime> GetNextUp(Series series, User user, GetNextUpEpisodes request)
|
||||
{
|
||||
var allEpisodes = series.GetRecursiveChildren(user)
|
||||
.OfType<Episode>()
|
||||
.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<Episode, DateTime>(null, lastWatchedDate);
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<Episode> FilterItems(GetNextUpEpisodes request, IEnumerable<Episode> items)
|
||||
{
|
||||
// Make this configurable when needed
|
||||
items = items.Where(i => i.LocationType != LocationType.Virtual);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private IEnumerable<Series> FilterSeries(GetNextUpEpisodes request, IEnumerable<Series> 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)
|
||||
|
|
|
@ -221,6 +221,13 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
/// <param name="user">The user.</param>
|
||||
/// <returns>IEnumerable{Episode}.</returns>
|
||||
public IEnumerable<Episode> GetEpisodes(User user)
|
||||
{
|
||||
var config = user.Configuration;
|
||||
|
||||
return GetEpisodes(user, config.DisplayMissingEpisodes, config.DisplayUnairedEpisodes);
|
||||
}
|
||||
|
||||
public IEnumerable<Episode> 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<Episode>();
|
||||
|
||||
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<Episode>();
|
||||
|
|
|
@ -128,23 +128,28 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
}
|
||||
|
||||
public IEnumerable<Season> GetSeasons(User user)
|
||||
{
|
||||
var config = user.Configuration;
|
||||
|
||||
return GetSeasons(user, config.DisplayMissingEpisodes, config.DisplayUnairedEpisodes);
|
||||
}
|
||||
|
||||
public IEnumerable<Season> GetSeasons(User user, bool includeMissingSeasons, bool includeVirtualUnaired)
|
||||
{
|
||||
var seasons = base.GetChildren(user, true)
|
||||
.OfType<Season>();
|
||||
|
||||
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<Season>();
|
||||
.Cast<Season>();
|
||||
}
|
||||
|
||||
public IEnumerable<Episode> GetEpisodes(User user, int seasonNumber)
|
||||
{
|
||||
var config = user.Configuration;
|
||||
|
||||
return GetEpisodes(user, seasonNumber, config.DisplayMissingEpisodes, config.DisplayUnairedEpisodes);
|
||||
}
|
||||
|
||||
public IEnumerable<Episode> GetEpisodes(User user, int seasonNumber, bool includeMissingEpisodes, bool includeVirtualUnairedEpisodes)
|
||||
{
|
||||
var episodes = GetRecursiveChildren(user)
|
||||
.OfType<Episode>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user