Rewatching next up (#7253)

pull/7344/head
SenorSmartyPants 3 years ago committed by GitHub
parent a61b42f7ef
commit bbac59c6d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -140,7 +140,7 @@ namespace Emby.Server.Implementations.TV
var currentUser = user; var currentUser = user;
var allNextUp = seriesKeys var allNextUp = seriesKeys
.Select(i => GetNextUp(i, currentUser, dtoOptions)); .Select(i => GetNextUp(i, currentUser, dtoOptions, request.Rewatching));
// If viewing all next up for all series, remove first episodes // If viewing all next up for all series, remove first episodes
// 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)
@ -186,9 +186,9 @@ namespace Emby.Server.Implementations.TV
/// Gets the next up. /// Gets the next up.
/// </summary> /// </summary>
/// <returns>Task{Episode}.</returns> /// <returns>Task{Episode}.</returns>
private Tuple<DateTime, Func<Episode>> GetNextUp(string seriesKey, User user, DtoOptions dtoOptions) private Tuple<DateTime, Func<Episode>> GetNextUp(string seriesKey, User user, DtoOptions dtoOptions, bool rewatching)
{ {
var lastWatchedEpisode = _libraryManager.GetItemList(new InternalItemsQuery(user) var lastQuery = new InternalItemsQuery(user)
{ {
AncestorWithPresentationUniqueKey = null, AncestorWithPresentationUniqueKey = null,
SeriesPresentationUniqueKey = seriesKey, SeriesPresentationUniqueKey = seriesKey,
@ -202,23 +202,43 @@ namespace Emby.Server.Implementations.TV
Fields = new[] { ItemFields.SortName }, Fields = new[] { ItemFields.SortName },
EnableImages = false EnableImages = false
} }
}).Cast<Episode>().FirstOrDefault(); };
if (rewatching)
{
// find last watched by date played, not by newest episode watched
lastQuery.OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending) };
}
var lastWatchedEpisode = _libraryManager.GetItemList(lastQuery).Cast<Episode>().FirstOrDefault();
Func<Episode> getEpisode = () => Func<Episode> getEpisode = () =>
{ {
var nextEpisode = _libraryManager.GetItemList(new InternalItemsQuery(user) var nextQuery = new InternalItemsQuery(user)
{ {
AncestorWithPresentationUniqueKey = null, AncestorWithPresentationUniqueKey = null,
SeriesPresentationUniqueKey = seriesKey, SeriesPresentationUniqueKey = seriesKey,
IncludeItemTypes = new[] { BaseItemKind.Episode }, IncludeItemTypes = new[] { BaseItemKind.Episode },
OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) }, OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) },
Limit = 1, Limit = 1,
IsPlayed = false, IsPlayed = rewatching,
IsVirtualItem = false, IsVirtualItem = false,
ParentIndexNumberNotEquals = 0, ParentIndexNumberNotEquals = 0,
MinSortName = lastWatchedEpisode?.SortName, MinSortName = lastWatchedEpisode?.SortName,
DtoOptions = dtoOptions DtoOptions = dtoOptions
}).Cast<Episode>().FirstOrDefault(); };
Episode nextEpisode;
if (rewatching)
{
nextQuery.Limit = 2;
// get watched episode after most recently watched
nextEpisode = _libraryManager.GetItemList(nextQuery).Cast<Episode>().ElementAtOrDefault(1);
}
else
{
nextEpisode = _libraryManager.GetItemList(nextQuery).Cast<Episode>().FirstOrDefault();
}
if (_configurationManager.Configuration.DisplaySpecialsWithinSeasons) if (_configurationManager.Configuration.DisplaySpecialsWithinSeasons)
{ {
@ -228,7 +248,7 @@ namespace Emby.Server.Implementations.TV
SeriesPresentationUniqueKey = seriesKey, SeriesPresentationUniqueKey = seriesKey,
ParentIndexNumber = 0, ParentIndexNumber = 0,
IncludeItemTypes = new[] { BaseItemKind.Episode }, IncludeItemTypes = new[] { BaseItemKind.Episode },
IsPlayed = false, IsPlayed = rewatching,
IsVirtualItem = false, IsVirtualItem = false,
DtoOptions = dtoOptions DtoOptions = dtoOptions
}) })

@ -68,6 +68,7 @@ namespace Jellyfin.Api.Controllers
/// <param name="nextUpDateCutoff">Optional. Starting date of shows to show in Next Up section.</param> /// <param name="nextUpDateCutoff">Optional. Starting date of shows to show in Next Up section.</param>
/// <param name="enableTotalRecordCount">Whether to enable the total records count. Defaults to true.</param> /// <param name="enableTotalRecordCount">Whether to enable the total records count. Defaults to true.</param>
/// <param name="disableFirstEpisode">Whether to disable sending the first episode in a series as next up.</param> /// <param name="disableFirstEpisode">Whether to disable sending the first episode in a series as next up.</param>
/// <param name="rewatching">Whether to get a rewatching next up instead of standard next up.</param>
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the next up episodes.</returns> /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the next up episodes.</returns>
[HttpGet("NextUp")] [HttpGet("NextUp")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
@ -84,7 +85,8 @@ namespace Jellyfin.Api.Controllers
[FromQuery] bool? enableUserData, [FromQuery] bool? enableUserData,
[FromQuery] DateTime? nextUpDateCutoff, [FromQuery] DateTime? nextUpDateCutoff,
[FromQuery] bool enableTotalRecordCount = true, [FromQuery] bool enableTotalRecordCount = true,
[FromQuery] bool disableFirstEpisode = false) [FromQuery] bool disableFirstEpisode = false,
[FromQuery] bool rewatching = false)
{ {
var options = new DtoOptions { Fields = fields } var options = new DtoOptions { Fields = fields }
.AddClientFields(Request) .AddClientFields(Request)
@ -100,7 +102,8 @@ namespace Jellyfin.Api.Controllers
UserId = userId ?? Guid.Empty, UserId = userId ?? Guid.Empty,
EnableTotalRecordCount = enableTotalRecordCount, EnableTotalRecordCount = enableTotalRecordCount,
DisableFirstEpisode = disableFirstEpisode, DisableFirstEpisode = disableFirstEpisode,
NextUpDateCutoff = nextUpDateCutoff ?? DateTime.MinValue NextUpDateCutoff = nextUpDateCutoff ?? DateTime.MinValue,
Rewatching = rewatching
}, },
options); options);

@ -14,6 +14,7 @@ namespace MediaBrowser.Model.Querying
EnableTotalRecordCount = true; EnableTotalRecordCount = true;
DisableFirstEpisode = false; DisableFirstEpisode = false;
NextUpDateCutoff = DateTime.MinValue; NextUpDateCutoff = DateTime.MinValue;
Rewatching = false;
} }
/// <summary> /// <summary>
@ -81,5 +82,10 @@ namespace MediaBrowser.Model.Querying
/// Gets or sets a value indicating the oldest date for a show to appear in Next Up. /// Gets or sets a value indicating the oldest date for a show to appear in Next Up.
/// </summary> /// </summary>
public DateTime NextUpDateCutoff { get; set; } public DateTime NextUpDateCutoff { get; set; }
/// <summary>
/// Gets or sets a value indicating whether getting rewatching next up list.
/// </summary>
public bool Rewatching { get; set; }
} }
} }

Loading…
Cancel
Save