plex-sync icon indicating copy to clipboard operation
plex-sync copied to clipboard

Error with multiple user in Plex Home

Open stian89 opened this issue 8 years ago • 23 comments

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 avatar Dec 17 '16 22:12 stian89

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

stian89 avatar Dec 19 '16 17:12 stian89

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.

jacobwgillespie avatar Dec 27 '16 16:12 jacobwgillespie

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 avatar Dec 27 '16 17:12 stian89

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.

stian89 avatar Dec 27 '16 17:12 stian89

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)

jalarab avatar Mar 03 '17 19:03 jalarab

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

caldude321 avatar Apr 10 '17 19:04 caldude321

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)

thanamatos avatar Apr 17 '17 20:04 thanamatos

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

  • In Plex enable debug and verbose logging as well as enable tokens in logs
  • Run the command with a known bad token i.e plex-sync <known_bad_token>@<server_1>/3,rw <some_token>@<server_2>/2,rw

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

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

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.

cfoucher avatar Apr 18 '17 17:04 cfoucher

Thanks. That worked perfectly.

thanamatos avatar Apr 18 '17 19:04 thanamatos

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: <access_token token="THIS_IS_THE_TOKEN_THAT_I_USE_NOW" username="USER" thumb="https://plex.tv/users/63f71808dca5c41d/avatar?c=2017-04-17+09%3A17%3A42+UTC" title="USER" id="10750" owned="0" allow_sync="1" allow_camera_upload="0" allow_channels="1" filter_all="" filter_movies="" filter_music="" filter_photos="" filter_television="" scrobble_types=""> <profile_settings default_audio_language="es" default_subtitle_language="es" auto_select_subtitle="2" auto_select_audio="1"/> <library_section key="1"/> <library_section key="2"/>

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?

jalarab avatar Apr 19 '17 01:04 jalarab

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.

thanamatos avatar Apr 19 '17 01:04 thanamatos

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.

jacobwgillespie avatar Apr 19 '17 02:04 jacobwgillespie

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.

thanamatos avatar Apr 19 '17 02:04 thanamatos

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 avatar Apr 19 '17 03:04 jacobwgillespie

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?

jacobwgillespie avatar Apr 19 '17 04:04 jacobwgillespie

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?

thanamatos avatar Apr 19 '17 04:04 thanamatos

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.

jacobwgillespie avatar Apr 19 '17 04:04 jacobwgillespie

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 [email protected]:

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 avatar Apr 19 '17 14:04 jalarab

@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?

jalarab avatar Apr 19 '17 14:04 jalarab

@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/<cloud_serve_id>/help

cfoucher avatar Apr 20 '17 00:04 cfoucher

It Works, thanks

jalarab avatar Apr 22 '17 14:04 jalarab

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

astrodad avatar Jul 11 '17 14:07 astrodad

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

rjsears avatar Dec 11 '17 19:12 rjsears