Skip to content

Commit

Permalink
Store items play progress in metadata for further use later.
Browse files Browse the repository at this point in the history
  • Loading branch information
arabcoders committed Nov 9, 2023
1 parent 6a8e7e2 commit 9f8804c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Backends/Jellyfin/JellyfinActionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/Backends/Plex/PlexActionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Libs/Entity/StateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 9f8804c

Please sign in to comment.