arabcoders / watchstate

Self-hosted service to sync your plex, jellyfin and emby play state. without relying on 3rd-party external services.
MIT License
478 stars 9 forks source link

Plex scrobble updates the DB but export says no update #189

Closed karan closed 2 years ago

karan commented 2 years ago

Great tool with some learning curve!

I set up Plex -> Jellyfin sync. Plex send a webhook to ws which updates the DB:

[2022-07-06T18:27:20.073745-07:00] webhook.NOTICE: [plex] marked [Frasier (1999) - 07x002] as [Played]. {"request":{"id":"$ID","ip":"$IP","agent":"PlexMediaServer/1.26.2.5797-5bd057d2b","uri":"/?apikey=$API_KEY"},"id":$ID,"item":{"type":"episode"},"attributes":{"backend":{"id":"$BACKEND","name":"$NAME","client":"PlexMediaServer","version":"1.26.2.5797-5bd057d2b"},"user":{"id":1,"name":"$USERNAME"},"item":{"id":"34273","type":"episode"},"webhook":{"event":"media.scrobble"}}} []

And I've verified this in the DB:

┌───────┬─────────┬─────────────────────────────────────────────────┬────────────┬─────────────────────────┬────────┬────────────────┐
│ id    │ Type    │ Title                                           │ Via (Last) │ Date                    │ Played │ Via (Event)    │
├───────┼─────────┼─────────────────────────────────────────────────┼────────────┼─────────────────────────┼────────┼────────────────┤
│ 3655  │ Episode │ Frasier (1999) - 07x002                         │ plex       │ 2022-07-06 18:27:20 PDT │ Yes    │ media.scrobble │

But then when I try to export the change to jellyfin, it doesn't work:

$ docker exec -ti watchstate console state:export -v --servers-filter 'jellyfin'
[2022-07-06T18:28:50-07:00] NOTICE: DATABASE: Loading changed items since [2022-07-06 18:07:32 PDT].
[2022-07-06T18:28:50-07:00] NOTICE: SYSTEM: Using push mode for [0] backends and export mode for [0] backends.
[2022-07-06T18:28:50-07:00] NOTICE: SYSTEM: No play state changes detected.

So 2 things:

  1. Why does it not work when there's clearly been an update in the DB?
  2. It would be nice to export the state as soon as webhook is called instead of waiting for the cronjob to run.
arabcoders commented 2 years ago

Hi,

looking at the logs i assume you probably don't have export enabled, run the same command with -vvv it will give you more information. There are the possibility the items already has been synced or has the same play state. you could do console db:list --id 3655 --output yaml to see the metadata related to all backends.

As for why we don't sync as soon as possible if you happen to have webhooks enabled you could run the push command every 1m instead if 10m, i simply set the default to 10m as it cover wide range of episodes runtime length. Check out the environment section in FAQ.md and set the WS_CRON_PUSH_AT to whatever value you like :-)

If you do have export enabled. then report back and we could dig further.

karan commented 2 years ago

I do have export enabled on the jellyfin backend:

┌──────────┬────────────────────────────────────────────────┐
│ Backend  │ Filter: None                                   │
├──────────┼────────────────────────────────────────────────┤
│ jellyfin │ name: jellyfin                                 │
│          │ type: jellyfin                                 │
│          │ url: 'https://$DOMAIN/'             │
│          │ token: $TOKEN        │
│          │ uuid: $UUID         │
│          │ user: $USER         │
│          │ import:                                        │
│          │   enabled: true                                │
│          │ export:                                        │
│          │   enabled: true                                │
│          │   lastSync: 1657169526                         │

Export is disabled on the plex backend though since I do not want to export to plex (only FROM plex to jellyfin).

But, I understand now that push is different from export. I had export enabled but not push. I set WS_CRON_PUSH=true in my docker container and now it does attempt to push but still fails:

--------------------------
Task: push (Started: Wed, 22:10:00 PDT)
Command: console state:push -vvv
Exit Code: 0 (Ended: Wed, 22:10:00 PDT)
--------------------------

[2022-07-06T22:10:00-07:00] INFO: Export to this backend is disabled by user choice.
[2022-07-06T22:10:00-07:00] WARNING: Ignoring [Frasier (1999) - 07x002] for [jellyfin]. No metadata was found.
[2022-07-06T22:10:00-07:00] NOTICE: SYSTEM: No play state changes detected.

I'm not sure why it's complaining about export being disabled - it's clearly enabled. Any thoughts?

arabcoders commented 2 years ago

INFO: Export to this backend is disabled by user choice. this relates to plex i forgot to put the backend name in the text if context is disabled.

As you can see from the log [2022-07-06T22:10:00-07:00] WARNING: Ignoring [Frasier (1999) - 07x002] for [jellyfin]. No metadata was found did you import your jellyfin metadata?

run the following console db:list --id 3655 --output yaml if there is no metadata related to jellyfin then it might mean the show is not matched in jellyfin. go to jellyfin and edit the show metadata and checkout the external ids section.

Or you can do

console backend:library:list jellyfin 

get the library id which contains the show then run

console backend:library:unmatched jellyfin library_id

it should give you list of unmatched items.

If everything checks out then I'm going to need import trace log to determine why they are not being matched.

karan commented 2 years ago

INFO: Export to this backend is disabled by user choice. this relates to plex i forgot to put the backend name in the text if context is disabled.

Ah ok so just a red-herring then? Ok to ignore this log.

As you can see from the log [2022-07-06T22:10:00-07:00] WARNING: Ignoring [Frasier (1999) - 07x002] for [jellyfin]. No metadata was found did you import your jellyfin metadata?

run the following console db:list --id 3655 --output yaml if there is no metadata related to jellyfin then it might mean the show is not matched in jellyfin. go to jellyfin and edit the show metadata and checkout the external ids section.

Didn't know I had to do that. Okay so I imported from jellyfin and now I see metadata for both backends in console db:list --id 3655 --output yaml.

I do see that the metadata doesn't match - plex doesn't have any guids (which is what I'm assuming ws uses to match?):

https://gist.github.com/karan/d1e5519c0069b7b92d4f78f5d1802947

Or you can do

console backend:library:list jellyfin 

get the library id which contains the show then run

console backend:library:unmatched jellyfin library_id

it should give you list of unmatched items.

I've ensured there's no unmatched and no mismatched items in my libraries.

If everything checks out then I'm going to need import trace log to determine why they are not being matched.

Happy to provide any logs if you let me know what steps to follow.

arabcoders commented 2 years ago

The meta seems fine now, for episodes parent guid is enough for syncing. now that you have imported your jellyfin metadata try exporting it should hopefully work 😄

karan commented 2 years ago

Aha that worked. Tested with the following steps:

Now that it works, this tool is quite amazing!

Thanks for the help.

arabcoders commented 2 years ago

Glad it worked for you.