Merge pull request #362 from ArabCoders/dev

Updated ProgressCommand to prevent duplicate events for same item.
This commit is contained in:
Abdulmohsen
2023-11-11 17:19:18 +03:00
committed by GitHub
3 changed files with 21 additions and 22 deletions

View File

@@ -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.

View File

@@ -120,7 +120,6 @@ class Progress
])
)->withQuery(
http_build_query([
'mediaSourceId' => $logContext['remote']['id'],
'positionTicks' => (string)floor($entity->getPlayProgress() * 1_00_00),
])
);

View File

@@ -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<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);
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');