luigi311 / JellyPlex-Watched

Sync watched between jellyfin and plex locally
GNU General Public License v3.0
392 stars 19 forks source link

[BUG] Error updating watched for #91

Closed tscibilia closed 1 year ago

tscibilia commented 1 year ago

Describe the bug I'm experiencing an issue with the script (running on my Ubuntu 22.04 VM where I host both plex and jellyfin right now). I've only whitelisted my own username and most tv shows and anime seems to work but none of my movies watched status is synced and I'm getting the following error.

Logs

Plex: Generating watched for tscibilia in library Anime
Plex: Generating watched for tscibilia in library Movies
Plex: Generating watched for tscibilia in library TV Shows
Jellyfin: Generating watched for tscibilia in library Anime
...
Marked Sailor Moon Season 1 Episode 36 Usagi's Confusion: Is Tuxedo Mask Evil? as watched for tscibilia in Anime for Jellyfin
Marked Sailor Moon Season 1 Episode 37 Let's Become a Princess: Usagi's Bizarre Training as watched for tscibilia in Anime for Jellyfin
Marked Sailor Moon Season 1 Episode 38 The Snow, the Mountains, Friendship and Monsters as watched for tscibilia in Anime for Jellyfin
[ERROR]: Jellyfin: Query get /Users/d41fe7314bad48f4aad689213aaf3ffd/Items?SortBy=SortName&SortOrder=Ascending&Recursive=True&ParentId=767bffe4f11c93ef34b805451a696a4e&isPlayed=false&Fields=ItemCounts,ProviderIds,Path&IncludeItemTypes=Series
Results None

[ERROR]: Jellyfin: Query get /Users/d41fe7314bad48f4aad689213aaf3ffd/Items?SortBy=SortName&SortOrder=Ascending&Recursive=True&ParentId=f137a2dd21bbc1b99aa5c0f6bf02a805&isPlayed=false&Fields=ItemCounts,ProviderIds,MediaSources&IncludeItemTypes=Movie
Results None

[ERROR]: Jellyfin: Error updating watched for tscibilia in library TV Shows, 
[ERROR]: Traceback (most recent call last):
  File "/home/plex/JellyPlex-Watched/src/jellyfin.py", line 94, in query
    async with session.get(
  File "/home/plex/JellyPlex-Watched/venv/lib/python3.10/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
  File "/home/plex/JellyPlex-Watched/venv/lib/python3.10/site-packages/aiohttp/client.py", line 560, in _request
    await resp.start(conn)
  File "/home/plex/JellyPlex-Watched/venv/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 894, in start
    with self._timer:
  File "/home/plex/JellyPlex-Watched/venv/lib/python3.10/site-packages/aiohttp/helpers.py", line 721, in __exit__
    raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/plex/JellyPlex-Watched/src/jellyfin.py", line 632, in update_user_watched
    jellyfin_search = await self.query(
  File "/home/plex/JellyPlex-Watched/src/jellyfin.py", line 124, in query
    raise Exception(e)
Exception

[ERROR]: Jellyfin: Error updating watched for tscibilia in library Movies, 
[ERROR]: Traceback (most recent call last):
  File "/home/plex/JellyPlex-Watched/src/jellyfin.py", line 94, in query
    async with session.get(
  File "/home/plex/JellyPlex-Watched/venv/lib/python3.10/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
  File "/home/plex/JellyPlex-Watched/venv/lib/python3.10/site-packages/aiohttp/client.py", line 560, in _request
    await resp.start(conn)
  File "/home/plex/JellyPlex-Watched/venv/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 894, in start
    with self._timer:
  File "/home/plex/JellyPlex-Watched/venv/lib/python3.10/site-packages/aiohttp/helpers.py", line 721, in __exit__
    raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/plex/JellyPlex-Watched/src/jellyfin.py", line 548, in update_user_watched
    jellyfin_search = await self.query(
  File "/home/plex/JellyPlex-Watched/src/jellyfin.py", line 124, in query
    raise Exception(e)
Exception

Marked Sailor Moon Season 1 Episode 39 Paired with a Monster: Mako, the Ice Skating Queen as watched for tscibilia in Anime for Jellyfin
Marked Sailor Moon Season 1 Episode 40 The Legendary Lake Yokai: The Bond of Usagi's Family as watched for tscibilia in Anime for Jellyfin
...
Average time: 960.8917050190503
Looping in 3600.0

Type:

Additional context I didn't include the entire log, please let me know if you need additional information.

Kyon147 commented 1 year ago

I've had the same issue, it seems to be the &IncludeItemTypes= request param at the end does not work with certain other filters. When that is removed the query is successful.

In my case it is because &IncludeItemTypes=Series also tries to filter on isPlayed and I assume that field does not exist at the Series level, so it errors out. Removing

This does not work

?SortBy=SortName&SortOrder=Ascending&Recursive=True&ParentId=XXXXXXXXXXXXXX&isPlayed=false&Fields=ItemCounts,ProviderIds,Path&IncludeItemTypes=Series

But this does

?SortBy=SortName&SortOrder=Ascending&Recursive=True&ParentId=XXXXXXXXXXXXXX&Fields=ItemCounts,ProviderIds,Path&IncludeItemTypes=Series

tscibilia commented 1 year ago

Holy crap, thx. That worked!

For my future reference or anyone else looking at this issue. I changed line 635 of /src/jellyfin.py from + "&isPlayed=false&Fields=ItemCounts,ProviderIds,Path&IncludeItemTypes=Series", to this + "&Fields=ItemCounts,ProviderIds,Path&IncludeItemTypes=Series",

luigi311 commented 1 year ago

Interesting since this was working before for other users. Can you guys keep trying it for a while and let me know if its working as expecting on your sides. If so i can go ahead and get this implemented. @Kyon147 you can also submit a PR for this if you want, if not i can go ahead and just make the change myself.

Kyon147 commented 1 year ago

Hey @luigi311 sure thing. I'll keep an eye on it for my server and make sure there's not any weirdness.

It was working for me on an older version of Jellyfin, but I recently updated to their latest and then that is when I noticed this error. So it could be a new bug introduced on their side.

I've not had a proper look at your codebase but do you use any played data at the Series level? If not, then it might be safe to leave it omitted from the query string.

Happy to make a PR ready though, either way.

luigi311 commented 1 year ago

After some testing it looks like it doesnt cause any issues, feel free to submit the PR to dev so i can merge it in and move it up with some other fixes

luigi311 commented 1 year ago

This is now included since it seems to be working just fine without that IsPlaying filter for me. You should no longer have this issue with the new latest build