mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-06 06:12:52 +01:00
Surface the played version for resume
This commit is contained in:
@@ -1,29 +1,29 @@
|
||||
using System;
|
||||
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.
|
||||
/// The user data of the most recently played alternate version that should drive the completion state of 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)
|
||||
public record VersionResumeData(UserItemData UserData)
|
||||
{
|
||||
/// <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.
|
||||
/// Merges the most recently played version's completion state into the supplied user data dto.
|
||||
/// Only completion (played) propagates to the primary; the in-progress resume position stays on
|
||||
/// the version that owns it, which is surfaced directly (e.g. in resume queries) so that playback
|
||||
/// always targets the correct version rather than resuming the primary at another version's offset.
|
||||
/// </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;
|
||||
dto.Played = dto.Played || UserData.Played;
|
||||
|
||||
if (RunTimeTicks > 0 && UserData.PlaybackPositionTicks > 0)
|
||||
if ((UserData.LastPlayedDate ?? DateTime.MinValue) > (dto.LastPlayedDate ?? DateTime.MinValue))
|
||||
{
|
||||
dto.PlayedPercentage = 100.0 * UserData.PlaybackPositionTicks / RunTimeTicks.Value;
|
||||
dto.LastPlayedDate = UserData.LastPlayedDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user