Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to fix plex webhook user id. #331

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 2 additions & 12 deletions src/Backends/Plex/Action/GetUsersList.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,9 @@ 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, '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'),
Expand Down
3 changes: 3 additions & 0 deletions src/Libs/Entity/StateEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion src/Libs/Entity/StateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion src/Libs/Initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,15 @@ 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.';
} else {
$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);
}

Expand Down
2 changes: 0 additions & 2 deletions src/Libs/Mappers/Import/DirectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading