Coalesce alternate-version progress onto primary in resume filter

This commit is contained in:
Shadowghost
2026-06-09 23:23:03 +02:00
parent fe1d8d8840
commit 0874a26131
10 changed files with 525 additions and 8 deletions

View File

@@ -62,6 +62,24 @@ namespace MediaBrowser.Controller.Library
/// <returns>A dictionary mapping item IDs to their user data.</returns>
Dictionary<Guid, UserItemData> GetUserDataBatch(IReadOnlyList<BaseItem> items, User user);
/// <summary>
/// Gets the user data that should drive resume for a multi-version item: the data of the most
/// recently played alternate version (including the item itself) that has a resume point.
/// </summary>
/// <param name="user">The user.</param>
/// <param name="item">The item.</param>
/// <returns>The resume version's data, or <c>null</c> when the item has no versions or none has a resume point.</returns>
VersionResumeData? GetResumeUserData(User user, BaseItem item);
/// <summary>
/// Gets the resume-driving user data for multiple items in a single batch operation.
/// See <see cref="GetResumeUserData(User, BaseItem)"/>.
/// </summary>
/// <param name="items">The items to get resume data for.</param>
/// <param name="user">The user.</param>
/// <returns>A dictionary mapping item ids to their resume version's data; items without one are omitted.</returns>
IReadOnlyDictionary<Guid, VersionResumeData> GetResumeUserDataBatch(IReadOnlyList<BaseItem> items, User user);
/// <summary>
/// Gets the user data dto.
/// </summary>

View File

@@ -0,0 +1,30 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Dto;
namespace MediaBrowser.Controller.Library
{
/// <summary>
/// The user data of the alternate version that should drive resume for a multi-version item.
/// </summary>
/// <param name="UserData">The resume version's user data.</param>
/// <param name="RunTimeTicks">The resume version's runtime, used for the progress percentage.</param>
public record VersionResumeData(UserItemData UserData, long? RunTimeTicks)
{
/// <summary>
/// Applies the resume version's playback state to the supplied user data dto, so that an item
/// whose most recent progress lives on an alternate version still reports that progress.
/// </summary>
/// <param name="dto">The user data dto to update.</param>
public void ApplyTo(UserItemDataDto dto)
{
dto.PlaybackPositionTicks = UserData.PlaybackPositionTicks;
dto.Played = UserData.Played;
dto.LastPlayedDate = UserData.LastPlayedDate;
if (RunTimeTicks > 0 && UserData.PlaybackPositionTicks > 0)
{
dto.PlayedPercentage = 100.0 * UserData.PlaybackPositionTicks / RunTimeTicks.Value;
}
}
}
}