Skip to content

Commit

Permalink
Updated ProgressCommand to prevent duplicate progress events for same…
Browse files Browse the repository at this point in the history
… item.
  • Loading branch information
arabcoders committed Nov 11, 2023
1 parent e14de10 commit f33e4d3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/Backends/Jellyfin/Action/Progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ private function action(
])
)->withQuery(
http_build_query([
'mediaSourceId' => $logContext['remote']['id'],
'positionTicks' => (string)floor($entity->getPlayProgress() * 1_00_00),
])
);
Expand Down
38 changes: 19 additions & 19 deletions src/Commands/State/ProgressCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

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;
Expand Down Expand Up @@ -90,29 +89,30 @@ protected function process(InputInterface $input, OutputInterface $output): int
return self::SUCCESS;
}

$entities = $items = [];
/** @var array<iState> $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);
$dbItem = $this->db->get($queueItem);
if (null === $dbItem || $dbItem->isWatched() || $queueItem->isWatched()) {
continue;
}

if (!$dbItem->hasPlayProgress()) {
continue;
}
$entities[$dbItem->id] = $dbItem;
$dbItem = $dbItem->apply($queueItem);

if (!$dbItem->hasPlayProgress()) {
continue;
}

if (array_key_exists($dbItem->id, $entities) && $entities[$dbItem->id]->getPlayProgress(
) > $dbItem->getPlayProgress()) {
continue;
}
}

$items = null;
$entities[$dbItem->id] = $dbItem;
}

if (empty($entities)) {
$this->cache->delete('progress');
Expand Down

0 comments on commit f33e4d3

Please sign in to comment.