From 9f8804c1543335d8c6cdfae233c75a52bad5d180 Mon Sep 17 00:00:00 2001 From: abdulmohsen Date: Fri, 10 Nov 2023 01:10:39 +0300 Subject: [PATCH] Store items play progress in metadata for further use later. --- src/Backends/Jellyfin/JellyfinActionTrait.php | 7 +++++++ src/Backends/Plex/PlexActionTrait.php | 6 ++++++ src/Libs/Entity/StateInterface.php | 1 + 3 files changed, 14 insertions(+) diff --git a/src/Backends/Jellyfin/JellyfinActionTrait.php b/src/Backends/Jellyfin/JellyfinActionTrait.php index 9fd8c026..d176faa9 100644 --- a/src/Backends/Jellyfin/JellyfinActionTrait.php +++ b/src/Backends/Jellyfin/JellyfinActionTrait.php @@ -149,6 +149,13 @@ protected function createEntity(Context $context, iGuid $guid, array $item, arra if (true === $isPlayed) { $metadata[iState::COLUMN_META_DATA_PLAYED_AT] = (string)makeDate($date)->getTimestamp(); + $metadata[iState::COLUMN_META_DATA_PROGRESS] = "0"; + } + + if (false === $isPlayed && null !== ($progress = ag($item, 'UserData.PlaybackPositionTicks', null))) { + $metadata[iState::COLUMN_META_DATA_PROGRESS] = (string)floor( + $progress / 1_00_00 + ); // -- Convert to milliseconds. } unset($metadata, $metadataExtra); diff --git a/src/Backends/Plex/PlexActionTrait.php b/src/Backends/Plex/PlexActionTrait.php index fdfd2588..095e5bb1 100644 --- a/src/Backends/Plex/PlexActionTrait.php +++ b/src/Backends/Plex/PlexActionTrait.php @@ -165,6 +165,12 @@ protected function createEntity(Context $context, iGuid $guid, array $item, arra if (true === $isPlayed) { $metadata[iState::COLUMN_META_DATA_PLAYED_AT] = (string)$date; + $metadata[iState::COLUMN_META_DATA_PROGRESS] = "0"; + } + + if (false === $isPlayed && null !== ($progress = ag($item, 'viewOffset', null))) { + // -- Plex reports play progress in milliseconds already no need to convert. + $metadata[iState::COLUMN_META_DATA_PROGRESS] = (string)$progress; } unset($metadata, $metadataExtra); diff --git a/src/Libs/Entity/StateInterface.php b/src/Libs/Entity/StateInterface.php index 8bfa617e..41ef2cfc 100644 --- a/src/Libs/Entity/StateInterface.php +++ b/src/Libs/Entity/StateInterface.php @@ -38,6 +38,7 @@ interface StateInterface extends LoggerAwareInterface public const COLUMN_META_PATH = 'path'; public const COLUMN_META_DATA_ADDED_AT = 'added_at'; public const COLUMN_META_DATA_PLAYED_AT = 'played_at'; + public const COLUMN_META_DATA_PROGRESS = 'progress'; public const COLUMN_META_DATA_EXTRA = 'extra'; public const COLUMN_META_DATA_EXTRA_TITLE = 'title'; public const COLUMN_META_DATA_EXTRA_DATE = 'date';