Skip to content

Commit

Permalink
Merge pull request #10200 from thornbill/next-up-continue
Browse files Browse the repository at this point in the history
Add option to include resumable items in next up requests
  • Loading branch information
cvium committed Sep 11, 2023
2 parents a35a74c + 9c64f94 commit ec1149e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
20 changes: 10 additions & 10 deletions Emby.Server.Implementations/TV/TVSeriesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ public QueryResult<BaseItem> GetNextUp(NextUpQuery request, BaseItem[] parentsFo

private IEnumerable<Episode> GetNextUpEpisodes(NextUpQuery request, User user, IReadOnlyList<string> seriesKeys, DtoOptions dtoOptions)
{
var allNextUp = seriesKeys.Select(i => GetNextUp(i, user, dtoOptions, false));
var allNextUp = seriesKeys.Select(i => GetNextUp(i, user, dtoOptions, request.EnableResumable, false));

if (request.EnableRewatching)
{
allNextUp = allNextUp.Concat(
seriesKeys.Select(i => GetNextUp(i, user, dtoOptions, true)))
.OrderByDescending(i => i.LastWatchedDate);
allNextUp = allNextUp
.Concat(seriesKeys.Select(i => GetNextUp(i, user, dtoOptions, false, true)))
.OrderByDescending(i => i.LastWatchedDate);
}

// If viewing all next up for all series, remove first episodes
Expand Down Expand Up @@ -183,7 +183,7 @@ private static string GetUniqueSeriesKey(Series series)
/// Gets the next up.
/// </summary>
/// <returns>Task{Episode}.</returns>
private (DateTime LastWatchedDate, Func<Episode?> GetEpisodeFunction) GetNextUp(string seriesKey, User user, DtoOptions dtoOptions, bool rewatching)
private (DateTime LastWatchedDate, Func<Episode?> GetEpisodeFunction) GetNextUp(string seriesKey, User user, DtoOptions dtoOptions, bool includeResumable, bool includePlayed)
{
var lastQuery = new InternalItemsQuery(user)
{
Expand All @@ -200,8 +200,8 @@ private static string GetUniqueSeriesKey(Series series)
}
};

// If rewatching is enabled, sort first by date played and then by season and episode numbers
lastQuery.OrderBy = rewatching
// If including played results, sort first by date played and then by season and episode numbers
lastQuery.OrderBy = includePlayed
? new[] { (ItemSortBy.DatePlayed, SortOrder.Descending), (ItemSortBy.ParentIndexNumber, SortOrder.Descending), (ItemSortBy.IndexNumber, SortOrder.Descending) }
: new[] { (ItemSortBy.ParentIndexNumber, SortOrder.Descending), (ItemSortBy.IndexNumber, SortOrder.Descending) };

Expand All @@ -216,7 +216,7 @@ private static string GetUniqueSeriesKey(Series series)
IncludeItemTypes = new[] { BaseItemKind.Episode },
OrderBy = new[] { (ItemSortBy.ParentIndexNumber, SortOrder.Ascending), (ItemSortBy.IndexNumber, SortOrder.Ascending) },
Limit = 1,
IsPlayed = rewatching,
IsPlayed = includePlayed,
IsVirtualItem = false,
ParentIndexNumberNotEquals = 0,
DtoOptions = dtoOptions
Expand All @@ -240,7 +240,7 @@ private static string GetUniqueSeriesKey(Series series)
SeriesPresentationUniqueKey = seriesKey,
ParentIndexNumber = 0,
IncludeItemTypes = new[] { BaseItemKind.Episode },
IsPlayed = rewatching,
IsPlayed = includePlayed,
IsVirtualItem = false,
DtoOptions = dtoOptions
})
Expand Down Expand Up @@ -269,7 +269,7 @@ private static string GetUniqueSeriesKey(Series series)
nextEpisode = sortedConsideredEpisodes.FirstOrDefault();
}

if (nextEpisode is not null)
if (nextEpisode is not null && !includeResumable)
{
var userData = _userDataManager.GetUserData(user, nextEpisode);

Expand Down
5 changes: 4 additions & 1 deletion Jellyfin.Api/Controllers/TvShowsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public class TvShowsController : BaseJellyfinApiController
/// <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="disableFirstEpisode">Whether to disable sending the first episode in a series as next up.</param>
/// <param name="enableRewatching">Whether to include watched episode in next up results.</param>
/// <param name="enableResumable">Whether to include resumable episodes in next up results.</param>
/// <param name="enableRewatching">Whether to include watched episodes in next up results.</param>
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the next up episodes.</returns>
[HttpGet("NextUp")]
[ProducesResponseType(StatusCodes.Status200OK)]
Expand All @@ -86,6 +87,7 @@ public class TvShowsController : BaseJellyfinApiController
[FromQuery] DateTime? nextUpDateCutoff,
[FromQuery] bool enableTotalRecordCount = true,
[FromQuery] bool disableFirstEpisode = false,
[FromQuery] bool enableResumable = true,
[FromQuery] bool enableRewatching = false)
{
userId = RequestHelpers.GetUserId(User, userId);
Expand All @@ -104,6 +106,7 @@ public class TvShowsController : BaseJellyfinApiController
EnableTotalRecordCount = enableTotalRecordCount,
DisableFirstEpisode = disableFirstEpisode,
NextUpDateCutoff = nextUpDateCutoff ?? DateTime.MinValue,
EnableResumable = enableResumable,
EnableRewatching = enableRewatching
},
options);
Expand Down
6 changes: 6 additions & 0 deletions MediaBrowser.Model/Querying/NextUpQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public NextUpQuery()
EnableTotalRecordCount = true;
DisableFirstEpisode = false;
NextUpDateCutoff = DateTime.MinValue;
EnableResumable = false;
EnableRewatching = false;
}

Expand Down Expand Up @@ -83,6 +84,11 @@ public NextUpQuery()
/// </summary>
public DateTime NextUpDateCutoff { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to include resumable episodes as next up.
/// </summary>
public bool EnableResumable { get; set; }

/// <summary>
/// Gets or sets a value indicating whether getting rewatching next up list.
/// </summary>
Expand Down

0 comments on commit ec1149e

Please sign in to comment.