From f33e4d3dd99dc63d407a16d7a59876f1a58b0c32 Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Sat, 11 Nov 2023 17:12:47 +0300 Subject: [PATCH] Updated ProgressCommand to prevent duplicate progress events for same item. --- README.md | 2 +- src/Backends/Jellyfin/Action/Progress.php | 1 - src/Commands/State/ProgressCommand.php | 40 +++++++++++------------ 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 6e36a21d..c78461c5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ out of the box, this tool support `Jellyfin`, `Plex` and `Emby` media servers. We added new feature `watch progress tracking` YAY which works exclusively via webhooks at the moment to keep tracking of your play progress. As this feature is quite **EXPERIMENTAL** we have separate command and task for it `state:progress` will send back progress to your backends. -However, Sadly this feature is not working at the moment with `Jellyfin` due to API bug. Once `Jellyfin` fixes the bug it will start working automatically +However, Sadly this feature is not working at the moment with `Jellyfin` due to API bug [#10567](https://github.com/jellyfin/jellyfin/issues/10567) . Once `Jellyfin` fixes the bug it will start working automatically as the codebase already has the required code in place. However, the feature works well with both `Plex` and `Emby`. We would like to support this feature via standard `import` & `export` routine, but sadly that proven to be quite difficult due to the early design of the tool. diff --git a/src/Backends/Jellyfin/Action/Progress.php b/src/Backends/Jellyfin/Action/Progress.php index bd938ffe..d534f32a 100644 --- a/src/Backends/Jellyfin/Action/Progress.php +++ b/src/Backends/Jellyfin/Action/Progress.php @@ -120,7 +120,6 @@ class Progress ]) )->withQuery( http_build_query([ - 'mediaSourceId' => $logContext['remote']['id'], 'positionTicks' => (string)floor($entity->getPlayProgress() * 1_00_00), ]) ); diff --git a/src/Commands/State/ProgressCommand.php b/src/Commands/State/ProgressCommand.php index ac3b6ee0..0b865e09 100644 --- a/src/Commands/State/ProgressCommand.php +++ b/src/Commands/State/ProgressCommand.php @@ -6,7 +6,6 @@ namespace App\Commands\State; use App\Command; use App\Libs\Config; -use App\Libs\Container; use App\Libs\Database\DatabaseInterface as iDB; use App\Libs\Entity\StateInterface as iState; use App\Libs\Options; @@ -90,29 +89,30 @@ class ProgressCommand extends Command return self::SUCCESS; } - $entities = $items = []; + /** @var array $entities */ + $entities = []; - foreach ($this->cache->get('progress', []) as $item) { - /** @var iState $item */ - $items[] = Container::get(iState::class)::fromArray($item->getAll()); - } + foreach ($this->cache->get('progress', []) as $queueItem) { + assert($queueItem instanceof iState); - if (!empty($items)) { - foreach ($items as $queueItem) { - $dbItem = $this->db->get($queueItem); - if ($dbItem->isWatched()) { - continue; - } - $dbItem = $dbItem->apply($queueItem); - - if (!$dbItem->hasPlayProgress()) { - continue; - } - $entities[$dbItem->id] = $dbItem; + $dbItem = $this->db->get($queueItem); + if (null === $dbItem || $dbItem->isWatched() || $queueItem->isWatched()) { + continue; } - } - $items = null; + $dbItem = $dbItem->apply($queueItem); + + if (!$dbItem->hasPlayProgress()) { + continue; + } + + if (array_key_exists($dbItem->id, $entities) && $entities[$dbItem->id]->getPlayProgress( + ) > $dbItem->getPlayProgress()) { + continue; + } + + $entities[$dbItem->id] = $dbItem; + } if (empty($entities)) { $this->cache->delete('progress');