jacobwgillespie / plex-sync

:clapper: Command line utility for synchronizing Plex Media Server watched / seen status between multiple servers
https://www.npmjs.com/package/plex-sync
Other
303 stars 36 forks source link

Error with multiple user in Plex Home #27

Open stian89 opened 7 years ago

stian89 commented 7 years ago

Hi! I am running two Plex servers in my home network. Both on Windows 10 PCs.

For my admin user, the Plex-sync command works fine with all the different sections. For my 3 other users, I have problems.

I use this for all 4 users: plex-sync TOKEN@IP1/section TOKEN/@IP2/section

When I run it for my 3 other users, I get this error: TypeError: Cannot read property 'Video' of undefined at C:\Users\PC\AppData\Roaming\npm\node_modules\plex-sync\lib\plex.js:78:40 at process._tickCallback (internal/process/next_tick.js:103:7)

I looked at all the other issues here, and found one with the same error.

If I try to open this URL: http://SERVER_HOST/library/sections/SECTION_NUMBER/allLeaves?X-Plex-Token=PLEX_TOKEN with any of the 4 tokens (even with the one that syncs OK) and both IP's, I get an error.

I have tried running all the commands in a batch file with a "call-command" to get them all to run one after another. I ran it a copule of times. This resulted in one of the 3 "broken" users to get ONE show synced, while the others remained untouched.

Any suggestions? :)

stian89 commented 7 years ago

Finally got the allLeaves url to work. On my token , it makes an xml file. For the other tokens, I get 401 unauthorized.

jacobwgillespie commented 7 years ago

So, you're getting a 401 unauthorized with the combination of library ID and Plex Home user token? Did you share that particular library with your Plex Home user? And if so, what kind of Plex Home account is it (existing Plex user, managed user, etc.)?

I am able to sync with my test Plex Home user (managed user) so I think we should be able to figure this out.

I did just release v0.6.0 that now uses pagination to read the items in the library which might fix your issue, but I would suspect that something else is going on here.

stian89 commented 7 years ago

Thanks for the respons! Yeah, any library ID combined with the other users' tokens result in 401 unauthorized. My own token works fine.

All three accounts that I am trying to sync, have their own Plex.tv account (not managed). I got their tokens by logging in with their user and using the bookmarklet. :)

All three accounts do have access to all libraries. I'll try the new version. :)

stian89 commented 7 years ago

After updating to 0.6.0 i get the following error (highligts of the error I get):

TypeError: Cannot read property '$' of undefined at _callee2$ (location/plex.js:110:57) at _trycatch (location\runtime.js:6...) at Generatorfunctionprototype.invoke and prototype..

My account still works.

jalarab commented 7 years ago

same problem here. All my users have their own plex.tv account, I have their tokens but I receive the same error message: TypeError: Cannot read property '$' of undefined at _callee2$ (C:\Users\lenovo\AppData\Roaming\npm\node_modules\plex-sync\lib\plex.js:110:57) at tryCatch (C:\Users\lenovo\AppData\Roaming\npm\node_modules\plex-sync\node_modules\regenerator-runtime\runtime.js:64:40) at Generator.invoke [as _invoke] (C:\Users\lenovo\AppData\Roaming\npm\node_modules\plex-sync\node_modules\regenerator-runtime\runtime.js:355:22) at Generator.prototype.(anonymous function) [as next] (C:\Users\lenovo\AppData\Roaming\npm\node_modules\plex-sync\node_modules\regenerator-runtime\runtime.js:116:21) at step (C:\Users\lenovo\AppData\Roaming\npm\node_modules\plex-sync\node_modules\babel-runtime\helpers\asyncToGenerator.js:17:30) at C:\Users\lenovo\AppData\Roaming\npm\node_modules\plex-sync\node_modules\babel-runtime\helpers\asyncToGenerator.js:28:13 at process._tickCallback (internal/process/next_tick.js:103:7)

caldude321 commented 7 years ago

FYI, I'm getting this with Managed Accounts. Works on the primary account; havent tried non-primary plex account. Version that was downloaded today.

thanamatos commented 7 years ago

Getting the same thing downloaded today. Ubuntu 16.04 LTS. Primary account works. Plex.tv account errors out. TypeError: Cannot read property '$' of undefined at _callee2$ (/usr/lib/node_modules/plex-sync/lib/plex.js:107:57) at tryCatch (/usr/lib/node_modules/plex-sync/node_modules/regenerator-runtime/runtime.js:64:40) at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/lib/node_modules/plex-sync/node_modules/regenerator-runtime/runtime.js:299:22) at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/lib/node_modules/plex-sync/node_modules/regenerator-runtime/runtime.js:116:21) at step (/usr/lib/node_modules/plex-sync/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30) at /usr/lib/node_modules/plex-sync/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13 at process._tickCallback (internal/process/next_tick.js:109:7)

cfoucher commented 7 years ago

I was running into the same issue, but fixed it by doing the following:

Grep the Plex Media Server.log file on for the something like "tail -f Plex\ Media\ Server.log | grep "

You should then see something like this in the output: https://plex.tv/servers//access_tokens.xml?auth_token=&includeProfiles=1&includeProviders=1&unknownToken=

Navigating to that url in a browser will list the tokens for each plex.tv account connected to your server. Repeating this above for each server you are trying to sync with will get you the proper auth_tokens. You then just need to match up each users tokens for each server.

thanamatos commented 7 years ago

Thanks. That worked perfectly.

jalarab commented 7 years ago

it doesn't work for me. I tried to follow your instructions but I should did something wrong, because I still receiving the same error message.

When I navigate to the url, I can see something like this for each user:

but this error appears TypeError: Cannot read property '$' of undefined at _callee2$ (/usr/lib/node_modules/plex-sync/lib/plex.js:107:57) at tryCatch (/usr/lib/node_modules/plex-sync/node_modules/regenerator-runtime/runtime.js:64:40) at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/lib/node_modules/plex-sync/node_modules/regenerator-runtime/runtime.js:299:22) at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/lib/node_modules/plex-sync/node_modules/regenerator-runtime/runtime.js:116:21) at step (/usr/lib/node_modules/plex-sync/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30) at /usr/lib/node_modules/plex-sync/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13 at process._tickCallback (internal/process/next_tick.js:109:7) @cfoucher can you help me? what i been doing wrong?
thanamatos commented 7 years ago

What I didn't know was that each user on each server has a different token. You will need to pull up that xml file that lists all your users and their tokens from each of your servers you are trying to sync. you can then build the plex-sync command for each user once you get the two tokens each user has. Just make sure you match the IP with the user token you got from that server in the sync command because if you swap the tokens between the servers its the same as using a bad tokens. Hopefully that doesn't confuse you more.

jacobwgillespie commented 7 years ago

Ooooh, there's an endpoint that retrieves the access tokens of multiple users? That would make this a lot more user-friendly. Let me take a look and see if I can get a more automated way of fetching those tokens to work, as that might clear up a lot of smaller issues that people are running into.

thanamatos commented 7 years ago

That would be awesome. You would just need to be able to grab all the xml's from the servers and parse them. Then match the username from each to match up the tokens. The only thing is that people would need to enable the option to store the tokens in their log file which is off by default.

jacobwgillespie commented 7 years ago

I think I can actually call the Plex API directly, just like the Plex servers are doing - I just determined that the "some long ID number" is the machine identifier from the Plex server response, so I'm going to see if I can add PIN authentication to the plex-sync CLI then you should just be able to do plex-sync login and it will authenticate and grab all the tokens. Hopefully. We'll see if that's possible.

jacobwgillespie commented 7 years ago

It works! I'm able to enumerate all the users who have access to the system, from managed users, Plex Home users, to friends who have share access as well as retrieve all their access tokens for all the different servers they have access to. Additionally login works with a pin, so plex-sync can give you a 4-digit pin to enter into https://plex.tv/pin and it can automatically figure out all the rest.

Do any of you in this thread have any opinions on configuration files (like TOML files)? Any experience with them? For the next version of plex-sync that incorporates the above improvements, I think it will have officially outgrown its command-line syntax in terms of features, and probably will have to work based on configuration files. But I'm not sure how familiar people are with something like TOML, or if that would even be the right choice (it's hopefully simpler for people to understand / edit since there's no indentation required).

But I'm envisioning you could create a configuration file that defined your servers, then you could run sync commands on them.

The new flow would be, first login:

$ plex-sync login
Please visit https://plex.tv/pin in your browser and enter the pin A4C7, then press ENTER. [enter]
You have successfully logged in!

Then you would create a config file named plex-sync.toml or something:

# Define two servers

[server.home]
host = "127.0.0.1"

[server.cloud]
plexcloud = "true" # plex-sync can automatically detect your Plex Cloud server

# Sync movies library between two servers

[sync.movies]
progress = true
[sync.movies.home]
server = "home"
library = 4
read = true
write = true
[sync.movies.cloud]
server = "cloud"
library = 2
read = true
write = true

# Sync songs between two servers and different users (you and a Plex home user)

[sync.songs]
progress = true
[sync.songs.home]
server = "home"
user = "me" # the default
library = 1
read = true
write = true
[sync.songs.cloud]
server = "cloud"
user = "home:other-user-name"
library = 3
read = true
write = true

# Sync with rules, to create two individual TV libraries for two users and a common 
# "shared" library that marks watched only when both people watch the same episode:

[sync.tv]
[sync.tv.mine]
server = "home"
user = "me"
library = 1
read = true
write = false
[sync.tv.theirs]
server = "home"
user = "home:other-user-name"
library = 1
read = true
write = false
[sync.tv.common]
server = "home"
user = "home:common-account"
library = 1
read = false
write = true
minOtherServers = 2

# A complementing sync that marks two libraries as watched when the 
# common library is watched:

[sync.tv_common]
[sync.tv_common.mine]
server = "home"
user = "me"
library = 1
read = false
write = true
[sync.tv_common.theirs]
server = "home"
user = "home:other-user-name"
library = 1
read = false
write = true
[sync.tv_common.common]
server = "home"
user = "home:common-account"
library = 1
read = true
write = false

# Syncing multiple libraries by ID (1 and 2, 5 and 1, 6 and 6):

[sync.multiple]
[sync.multiple.mine]
server = "home"
library = [1, 5, 6]
read = true
write = true
[sync.multiple.theirs]
server = "cloud"
library = [2, 1, 6]
read = true
write = true

Then executing those syncs would be as simple as:

$ plex-sync sync multiple
$ plex-sync sync tv tv_common
$ plex-sync sync songs
$ plex-sync sync movies

Thoughts? Does that seem useful, or do you all have any other ideas?

thanamatos commented 7 years ago

That looks pretty straight forward to me. This way looks like it give you a lot of flexibility in how accounts are synced. Can I assume for a given library if you don't have a user defined that it would loop through all users and sync between the servers? Would it be possible to have it perform a question and response for simple scenarios if a toml file doesn't currently exist and for more complex scenarios the file can be edited manually?

jacobwgillespie commented 7 years ago

Yeah, my thought was not to have any automated syncing (since that would make it super easy to accidentally overwrite something), but perhaps just running plex-sync sync would give some kind of interactive question thing like you mention that would show you a list of users, a list of servers, and a list of libraries and let you configure and run a sync interactively. Then at the end it would show you what the config file syntax would look like so you could copy-paste to save the sync settings for later.

jalarab commented 7 years ago

But how can I do it for the cloud server? I can see the log but just for the local server. I am using the TOKEN extracted from the xml page for both servers, local and cloud, that is the problem?

2017-04-18 20:51 GMT-05:00 thanamatos notifications@github.com:

What I didn't know was that each user on each server has a different token. You will need to pull up that xml file that lists all your users and their tokens from each of your servers you are trying to sync. you can then build the plex-sync command for each user once you get the two tokens each user has. Just make sure you match the IP with the user token you got from that server in the sync command because if you swap the tokens between the servers its the same as using a bad tokens. Hopefully that doesn't confuse you more.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jacobwgillespie/plex-sync/issues/27#issuecomment-295039101, or mute the thread https://github.com/notifications/unsubscribe-auth/AQ8b8tP0w0xPTIBvvf_SDnt33GNwFFrFks5rxWidgaJpZM4LQABu .

jalarab commented 7 years ago

@jacobwgillespie. But how can I do it for the cloud server? I can see the PMS log but just for the local server. I am using the TOKEN extracted from the xml page for both servers, local and cloud, that is the problem?

cfoucher commented 7 years ago

@jacobwgillespie You need to do the same thing with the plex cloud server. You can view the Plex Cloud server logs by downloading them from the "Help" section of the Plex Cloud server settings page => http://app.plex.tv/web/app#!/settings/server//help

jalarab commented 7 years ago

It Works, thanks

astrodad commented 7 years ago

Any progress on the plex-sync login method that enumerates the tokens for you? See: https://github.com/jacobwgillespie/plex-sync/issues/27#issuecomment-295077996

rjsears commented 6 years ago

I also have many home users, any progress on the plex-sync login method??