Hellowlol / bw_plex

binge watching for plex
MIT License
368 stars 23 forks source link

Cannot control client (Mi Box 3) #121

Closed 0rsa closed 4 years ago

0rsa commented 4 years ago

Log file:

2020-03-01 10:23:25,673 :: bw_plex :: DEBUG :: plex.py:1200 :: We found the start of the credits.
2020-03-01 10:23:25,674 :: bw_plex :: INFO :: plex.py:931 :: Called client_action with 2594.9700000000003 43:14 20 stop
2020-03-01 10:23:25,677 :: bw_plex :: INFO :: plex.py:967 :: sessionkey 20 media_sessionkey 20
2020-03-01 10:23:25,678 :: bw_plex :: INFO :: plex.py:971 :: client Mi Box 2590.154
2020-03-01 10:23:25,678 :: bw_plex :: INFO :: plex.py:998 :: Checking if we cant find the correct client
2020-03-01 10:23:25,678 :: bw_plex :: INFO :: plex.py:1000 :: h4xmf1fmg3d8o9xt0522siwp 666d965c48771ed3-com-plexapp-android
2020-03-01 10:23:25,678 :: bw_plex :: INFO :: plex.py:1000 :: 4c9c845bbd76e0da-com-plexapp-android 666d965c48771ed3-com-plexapp-android
2020-03-01 10:23:25,678 :: bw_plex :: DEBUG :: plex.py:1009 :: We couldnt match the client. Trying a hail marry.
2020-03-01 10:23:25,678 :: bw_plex :: DEBUG :: plex.py:1022 :: Client hasnt a _baseurl or is a browser, enabling proxyThroughServer
2020-03-01 10:23:25,683 :: bw_plex :: INFO :: plex.py:946 :: Failed to reach the client directly, trying via server.
2020-03-01 10:23:25,688 :: bw_plex :: ERROR :: plex.py:89 :: There was an exception in client_action
Traceback (most recent call last):
  File "/home/flo/bw_plex/src/bw-plex/bw_plex/plex.py", line 941, in inner
    return func()
  File "/usr/local/lib/python3.7/dist-packages/plexapi/client.py", line 393, in stop
    self.sendCommand('playback/stop', type=mtype)
  File "/usr/local/lib/python3.7/dist-packages/plexapi/client.py", line 204, in sendCommand
    return query(key, headers=headers)
  File "/usr/local/lib/python3.7/dist-packages/plexapi/server.py", line 381, in query
    raise BadRequest('(%s) %s; %s %s' % (response.status_code, codename, response.url, errtext))
plexapi.exceptions.BadRequest: (500) internal_server_error; http://192.168.100.110:32400/player/playback/stop?commandID=1&type=video <?xml version='1.0' encoding='utf-8'?> <Response code="2000" status="FrameworkException: Unable to find player with identifier 666d965c48771ed3-com-plexapp-android">   <Traceback>Traceback (most recent call last):   File "/usr/lib/plexmediaserver/Resources/Plug-ins-5d395aa9d/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/runtime.py", line 843, in handle_request     result = f(**d)   File "/usr/lib/plexmediaserver/Resources/Plug-ins-5d395aa9d/System.bundle/Contents/Code/playerservice.py", line 50, in process_remote_command     raise FrameworkException('Unable to find player with identifier %s' % identifier) FrameworkException: Unable to find player with identifier 666d965c48771ed3-com-plexapp-android </Traceback> </Response>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/flo/bw_plex/src/bw-plex/bw_plex/plex.py", line 84, in inner
    return func(*args)
  File "/home/flo/bw_plex/src/bw-plex/bw_plex/plex.py", line 1060, in client_action
    proxy_on_fail(correct_client.stop)()
  File "/home/flo/bw_plex/src/bw-plex/bw_plex/plex.py", line 948, in inner
    return func()
  File "/usr/local/lib/python3.7/dist-packages/plexapi/client.py", line 393, in stop
    self.sendCommand('playback/stop', type=mtype)
  File "/usr/local/lib/python3.7/dist-packages/plexapi/client.py", line 204, in sendCommand
    return query(key, headers=headers)
  File "/usr/local/lib/python3.7/dist-packages/plexapi/server.py", line 381, in query
    raise BadRequest('(%s) %s; %s %s' % (response.status_code, codename, response.url, errtext))
plexapi.exceptions.BadRequest: (500) internal_server_error; http://192.168.100.110:32400/player/playback/stop?commandID=2&type=video <?xml version='1.0' encoding='utf-8'?> <Response code="2000" status="FrameworkException: Unable to find player with identifier 666d965c48771ed3-com-plexapp-android">   <Traceback>Traceback (most recent call last):   File "/usr/lib/plexmediaserver/Resources/Plug-ins-5d395aa9d/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/runtime.py", line 843, in handle_request     result = f(**d)   File "/usr/lib/plexmediaserver/Resources/Plug-ins-5d395aa9d/System.bundle/Contents/Code/playerservice.py", line 50, in process_remote_command     raise FrameworkException('Unable to find player with identifier %s' % identifier) FrameworkException: Unable to find player with identifier 666d965c48771ed3-com-plexapp-android </Traceback> </Response>

Thank you

0rsa commented 4 years ago

Plex version: 1.18.8.2468

Hellowlol commented 4 years ago

The client support is flaky sometimes. I dont think i can fix this as the server can’t find the client

0rsa commented 4 years ago

Maybe there is a clue here: https://github.com/phillipj/node-plex-control/issues/32 Thread owner is talking about X-Plex-Target-Client-Identifier which is passed in parameter URL.

Hellowlol commented 4 years ago

We pass that in the headers. (As the docs state we should do)

0rsa commented 4 years ago

Ok, thank you :( It's sad, your great software does the hardest work and it just fails stopping Plex playback. Did you have a clean example of query sent with headers / body / url parameters? I'd like to ask plex support to know why it doesn't work with some clients.

Hellowlol commented 4 years ago

Maybe some client require it in the url params as well. I dont know. I dont have the headers we send or the url. You should be able to find the url in the log as for the headers

As the code for the header we use after

def reset_base_headers():
    """ Convenience function returns a dict of all base X-Plex-* headers for session requests. """
    import plexapi
    return {
        'X-Plex-Platform': plexapi.X_PLEX_PLATFORM,
        'X-Plex-Platform-Version': plexapi.X_PLEX_PLATFORM_VERSION,
        'X-Plex-Provides': plexapi.X_PLEX_PROVIDES,
        'X-Plex-Product': plexapi.X_PLEX_PRODUCT,
        'X-Plex-Version': plexapi.X_PLEX_VERSION,
        'X-Plex-Device': plexapi.X_PLEX_DEVICE,
        'X-Plex-Device-Name': plexapi.X_PLEX_DEVICE_NAME,
        'X-Plex-Client-Identifier': plexapi.X_PLEX_IDENTIFIER,
        'X-Plex-Sync-Version': '2',
    }

The X-Plex-Target-Client-Identifier is handled here: https://github.com/pkkid/python-plexapi/blob/master/plexapi/client.py#L185-L204