-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial support for multi-user play state sync. this feature st…
…ill in alpha stage.
- Loading branch information
1 parent
aeb3a3a
commit 97896ad
Showing
16 changed files
with
1,262 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Backends\Emby\Action; | ||
|
||
class UpdateState extends \App\Backends\Jellyfin\Action\UpdateState | ||
{ | ||
protected string $action = 'emby.UpdateState'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Backends\Jellyfin\Action; | ||
|
||
use App\Backends\Common\CommonTrait; | ||
use App\Backends\Common\Context; | ||
use App\Backends\Common\Response; | ||
use App\Backends\Jellyfin\JellyfinClient; | ||
use App\Libs\Entity\StateInterface as iState; | ||
use App\Libs\Extends\Date; | ||
use App\Libs\QueueRequests; | ||
use Psr\Log\LoggerInterface as iLogger; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface as iHttp; | ||
|
||
class UpdateState | ||
{ | ||
use CommonTrait; | ||
|
||
protected string $action = 'jellyfin.updateState'; | ||
|
||
public function __construct(protected iHttp $http, protected iLogger $logger) | ||
{ | ||
} | ||
|
||
/** | ||
* Get Backend unique identifier. | ||
* | ||
* @param Context $context Context instance. | ||
* @param array<iState> $entities State instance. | ||
* @param QueueRequests $queue QueueRequests instance. | ||
* @param array $opts optional options. | ||
* | ||
* @return Response | ||
*/ | ||
public function __invoke(Context $context, array $entities, QueueRequests $queue, array $opts = []): Response | ||
{ | ||
return $this->tryResponse( | ||
context: $context, | ||
fn: function () use ($context, $entities, $opts, $queue) { | ||
foreach ($entities as $entity) { | ||
$meta = $entity->getMetadata($context->backendName); | ||
if (count($meta) < 1) { | ||
continue; | ||
} | ||
|
||
if ($entity->isWatched() === (bool)ag($meta, iState::COLUMN_WATCHED)) { | ||
continue; | ||
} | ||
|
||
if (null === ($itemId = ag($meta, iState::COLUMN_ID))) { | ||
continue; | ||
} | ||
|
||
$url = $context->backendUrl->withPath( | ||
r('/Users/{user_id}/PlayedItems/{item_id}', [ | ||
'user_id' => $context->backendUser, | ||
'item_id' => $itemId, | ||
]) | ||
); | ||
|
||
if ($context->clientName === JellyfinClient::CLIENT_NAME) { | ||
$url = $url->withQuery( | ||
http_build_query([ | ||
'DatePlayed' => makeDate($entity->updated)->format(Date::ATOM) | ||
]) | ||
); | ||
} | ||
|
||
$queue->add( | ||
$this->http->request( | ||
method: $entity->isWatched() ? 'POST' : 'DELETE', | ||
url: (string)$url, | ||
options: $context->backendHeaders + [ | ||
'user_data' => [ | ||
'context' => [ | ||
'backend' => $context->backendName, | ||
'play_state' => $entity->isWatched() ? 'played' : 'unplayed', | ||
'item' => [ | ||
'id' => $itemId, | ||
'title' => $entity->getName(), | ||
'type' => $entity->type == iState::TYPE_EPISODE ? 'episode' : 'movie', | ||
'state' => $entity->isWatched() ? 'played' : 'unplayed', | ||
], | ||
'url' => (string)$url, | ||
] | ||
], | ||
] | ||
) | ||
); | ||
} | ||
|
||
return new Response(status: true); | ||
}, | ||
action: $this->action | ||
); | ||
} | ||
} |
Oops, something went wrong.