luigi311 / JellyPlex-Watched

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

Config not finding User ID 1 #37

Closed tppickles closed 1 year ago

tppickles commented 1 year ago

I have 3 users in both plex and Jellyfin.

Names/ID numbers in the logs have been changed for privacy.

GET https://plexurl/accounts returns this in PostMan:

<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="16" identifier="com.plexapp.system.accounts">
    <Account id="0" key="/accounts/0" name="" defaultAudioLanguage="en" autoSelectAudio="1" defaultSubtitleLanguage="en" subtitleMode="1" thumb="" />
<Account id="1" key="/accounts/1" name="YYY1" defaultAudioLanguage="en" autoSelectAudio="1" defaultSubtitleLanguage="en" subtitleMode="0" thumb="" />
<Account id="1234" key="/accounts/1234" name="XXX1" defaultAudioLanguage="en" autoSelectAudio="1" defaultSubtitleLanguage="en" subtitleMode="1" thumb="" />
<Account id="2345" key="/accounts/2345" name="ZZZ" defaultAudioLanguage="en" autoSelectAudio="1" defaultSubtitleLanguage="en" subtitleMode="1" thumb="" />

Linked users with an ID other than 1 are being returned and found according to the logs.

LOG:

[INFO]: User list that exist on both servers {'XXX1': 'XXX2', 'ZZZ`: 'ZZZ', 'YYY1': 'YYY2'}
[INFO]: Filtered user list {'XXX': 'amber', 'XXX1': 'XXX2', 'YYY1': 'YYY2'}
[INFO]: Server 1 users: [<MyPlexUser:1234:XXX1>, <MyPlexUser:2345:YYY1>]`
...
`[ERROR]: Plex: Failed to update watched, Error: 'str' object has no attribute 'get_token'
[ERROR]: 'str' object has no attribute 'get_token'
[ERROR]: Traceback (most recent call last):
  File "/app/src/plex.py", line 401, in update_watched
    self.plex._baseurl, user.get_token(self.plex.machineIdentifier)
                        ^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get_token'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/app/src/main.py", line 396, in main
    main_loop()
  File "/app/src/main.py", line 373, in main_loop
    update_server_watched(
  File "/app/src/main.py", line 256, in update_server_watched
    server_connection[1].update_watched(
  File "/app/src/plex.py", line 451, in update_watched
    raise Exception(e)
Exception: 'str' object has no attribute 'get_token'
Retrying in 3600.0
luigi311 commented 1 year ago

Its bizarre that your user object is a str, i dont have anything that comes up with that so its hard for me to test on my side. I did add in a check if the user type is a str and attempt to get the plex class object instead for it. I added this in dev can you give it a try?

tppickles commented 1 year ago

I gave the dev version a try but still getting an error in the logs for the admin user: I did add the other two users to the blacklist so it doesn't attempt to sync those for now. What's strange is i gave luigi311/JellyPlex-Watched a try and the sync does work for my user but having three configs and running containers seems like its overkill.

Log:

[INFO]: Dryrun: True
[INFO]: User Mapping: {'ZZZ1': 'ZZZ2', 'XXX1': 'XXX2'}
[INFO]: Library Mapping: {'TV': 'TV Shows', 'Movies': 'Movies'}
[INFO]: Creating (black/white)lists
[INFO]: Blacklist Library: []
[INFO]: Whitelist Library: []
[INFO]: Blacklist Library Type: []
[INFO]: Whitelist Library Type: []
[INFO]: Blacklist Users: ['ZZZ', 'YYY1', 'YYY2']
[INFO]: Whitelist Users: []
[INFO]: Creating server connections
[INFO]: Creating users list
This is a test build
Server 1: plex <src.plex.Plex object at 0x7f69303a6010>
Server 2: jellyfin <src.jellyfin.Jellyfin object at 0x7f692f3628d0>
[INFO]: User list that exist on both servers {'XXX1': 'XXX2', 'YYY': 'YYY', 'ZZZ1': 'ZZZ2'}
[INFO]: Filtered user list {'ZZZ1': 'ZZZ2'}
[ERROR]: No users found for server 1, users found {'XXX1': 'XXX2', 'YYY': 'YYY', 'ZZZ1': 'ZZZ2'} filtered users {'ZZZ1': 'ZZZ2'}
[ERROR]: Traceback (most recent call last):
  File "/app/src/main.py", line 396, in main
    main_loop()
  File "/app/src/main.py", line 326, in main_loop
    server_1_users, server_2_users = setup_users(
                                     ^^^^^^^^^^^^
  File "/app/src/main.py", line 115, in setup_users
    raise Exception(
Exception: No users found for server 1, users found {'XXX1': 'XXX2', 'YYY': 'YYY', 'ZZZ1': 'ZZZ1'} filtered users {'ZZZ1': 'ZZZ2'}
luigi311 commented 1 year ago

Thats weird that its not finding users for you since the filtered users list is populated. I added server users to the output so you can see why is happening. Since you are censoring the usernames (and you should) you will need to see whats happening for it not to find it. Im going to assume it has to do with casings. If thats the case then im doing a rewrite right now so that users thing is more modular and adding in unit tests so i will be testing it with multiple casings to make sure its working correctly

As for the multiple methods its all just based on what people need and are able to use. On my nas i run everything through a docker container since i cant install anything on the host os, you are more than welcome to run it natively by just calling the main.py through a terminal.

mjmeli commented 1 year ago

I had a similar issue here and I tracked it down to the whitelist users. I had to make sure to add the users to that list. I'm not sure if that's your problem but I do notice your whitelist user list is empty.

tppickles commented 1 year ago

Adding the users to the whitelist did not work at first.

I tried a few tweaks and found out that Account Name from the API != account name as returned using the python script.

For whatever reason my account appears as "FIRSTNAME LASTNAME" and using this to link with my Jellyfin account does allow the syncs to run without error.