From 4e8f8225d0bc6cc38a5ce2313869151e63f83126 Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Mon, 28 Aug 2023 20:02:30 +0300 Subject: [PATCH 1/2] Update to fix plex webhook user id. --- FAQ.md | 2 +- README.md | 17 +++++++++++++++++ src/Backends/Plex/Action/GetUsersList.php | 2 +- src/Libs/Entity/StateEntity.php | 3 +++ src/Libs/Entity/StateInterface.php | 4 +++- src/Libs/Initializer.php | 3 ++- src/Libs/Mappers/Import/DirectMapper.php | 2 -- 7 files changed, 27 insertions(+), 6 deletions(-) diff --git a/FAQ.md b/FAQ.md index a6bbc056..3cdd73e6 100644 --- a/FAQ.md +++ b/FAQ.md @@ -445,7 +445,7 @@ Those are some Webhook limitations we discovered for the following media backend * Plex does not send webhooks events for "marked as played/unplayed". * Sometimes does not send events if you add more than one item at time. -* If you have multi-user setup, Plex will still report the admin account user id as `1`. +* If you have multi-user setup, Plex will still report the admin account user id as `1`. `(Fixed Recently)` * When you mark items as unwatched, Plex reset the date on the object. #### Emby diff --git a/README.md b/README.md index 893f5c3d..e6b4f15b 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,23 @@ out of the box, this tool support `Jellyfin`, `Plex` and `Emby` media servers. ---- +### Breaking change in plex webhook handling. + +If you happen to have enabled plex webhooks and had `limit webhook requests to the selected user`, plex in recent +versions managed to fix bug in old versions where they report the admin account user id as `1` regardless of whether you +have single or multi-user setup. We have a fix in place `(2023-08-28)` to update the user id to the actual user id from +plex.tv. However, Sadly this step is manual you have to rerun the `config:manage` command and re-select your user to +update the value. To fix this please run the command + +```bash +$ docker exec -ti watchstate config:manage [BACKEND_NAME] +``` + +And select your actual user which you want to process the webhooks events from. once that fixed you won't be missing +events from webhooks. + +---- + # Install create your `docker-compose.yaml` with the following content: diff --git a/src/Backends/Plex/Action/GetUsersList.php b/src/Backends/Plex/Action/GetUsersList.php index 932dd88f..2c8b5e3e 100644 --- a/src/Backends/Plex/Action/GetUsersList.php +++ b/src/Backends/Plex/Action/GetUsersList.php @@ -106,7 +106,7 @@ private function getUsers(Context $context, array $opts = []): Response foreach ($users as $user) { $data = [ - 'id' => ag($user, 'admin') && $adminsCount <= 1 ? 1 : ag($user, 'id'), + 'id' => ag($user, 'id'), 'uuid' => ag($user, 'uuid'), 'name' => ag($user, ['friendlyName', 'username', 'title', 'email'], '??'), 'admin' => (bool)ag($user, 'admin'), diff --git a/src/Libs/Entity/StateEntity.php b/src/Libs/Entity/StateEntity.php index 96e2eb3c..15f6bdac 100644 --- a/src/Libs/Entity/StateEntity.php +++ b/src/Libs/Entity/StateEntity.php @@ -6,10 +6,13 @@ use App\Libs\Entity\StateInterface as iState; use App\Libs\Guid; +use Psr\Log\LoggerAwareTrait; use RuntimeException; final class StateEntity implements iState { + use LoggerAwareTrait; + private array $data = []; private bool $tainted = false; diff --git a/src/Libs/Entity/StateInterface.php b/src/Libs/Entity/StateInterface.php index 70d3d9a5..6a9999b4 100644 --- a/src/Libs/Entity/StateInterface.php +++ b/src/Libs/Entity/StateInterface.php @@ -4,7 +4,9 @@ namespace App\Libs\Entity; -interface StateInterface +use Psr\Log\LoggerAwareInterface; + +interface StateInterface extends LoggerAwareInterface { public const TYPE_MOVIE = 'movie'; public const TYPE_EPISODE = 'episode'; diff --git a/src/Libs/Initializer.php b/src/Libs/Initializer.php index 639e7ea5..dc19e16e 100644 --- a/src/Libs/Initializer.php +++ b/src/Libs/Initializer.php @@ -292,6 +292,7 @@ private function defaultHttpServer(iRequest $realRequest): ResponseInterface if (empty($backend) || null === $class) { if (false === $validUser) { + $loglevel = Logger::DEBUG; $message = 'token is valid, User matching failed.'; } elseif (false === $validUUid) { $message = 'token and user are valid. Backend unique id matching failed.'; @@ -299,7 +300,7 @@ private function defaultHttpServer(iRequest $realRequest): ResponseInterface $message = 'Invalid token was given.'; } - $this->write($request, Logger::ERROR, $message, ['messages' => $log]); + $this->write($request, $loglevel ?? Logger::ERROR, $message, ['messages' => $log]); return new Response(401); } diff --git a/src/Libs/Mappers/Import/DirectMapper.php b/src/Libs/Mappers/Import/DirectMapper.php index f0285989..a7efa84f 100644 --- a/src/Libs/Mappers/Import/DirectMapper.php +++ b/src/Libs/Mappers/Import/DirectMapper.php @@ -401,8 +401,6 @@ public function add(iState $entity, array $opts = []): self ) ); - $this->logger->warning('entering', ['keys' => $keys]); - if (true === (clone $cloned)->apply(entity: $entity, fields: $keys)->isChanged(fields: $keys)) { try { $local = $local->apply( From 7a2cfd396d3896f5c7c684a53deb9e98614474da Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Mon, 28 Aug 2023 20:05:47 +0300 Subject: [PATCH 2/2] Removed dead code. --- src/Backends/Plex/Action/GetUsersList.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/Backends/Plex/Action/GetUsersList.php b/src/Backends/Plex/Action/GetUsersList.php index 2c8b5e3e..e7a54837 100644 --- a/src/Backends/Plex/Action/GetUsersList.php +++ b/src/Backends/Plex/Action/GetUsersList.php @@ -94,17 +94,7 @@ private function getUsers(Context $context, array $opts = []): Response $list = []; - $adminsCount = 0; - - $users = ag($json, 'users', []); - - foreach ($users as $user) { - if (true === (bool)ag($user, 'admin')) { - $adminsCount++; - } - } - - foreach ($users as $user) { + foreach (ag($json, 'users', []) as $user) { $data = [ 'id' => ag($user, 'id'), 'uuid' => ag($user, 'uuid'),