Shared Servers not working
Closed this issue · 6 comments
Describe the Bug
When you have a shared server, the plugin doesnt work.
The Error
The error is found in the code. When searching for servers within the account, my own valid token is taken. This is an error as the shared servers have their own access token.
Indicate if you followed all steps in the troubleshooting doc
What data does the sensor display if any?
What displays when visiting the API URL from the troubleshooting guide?
Does the default Home Assistant Plex component work for you?
No
Home Assistant Version
0.97.2
Additional Context
If you follow the steps in the troubleshooting doc are you able to connect to the API? If not, this isn't something that can be fixed and would explain why the HA plex component doesn't work for you as well.
I try to explain.
When you do:
https://plex.tv/api/servers.xml?X-Plex-Token=xxxxxxxxxxxxxgYE <--- My Login Token
I receive:
<?xml version="1.0" encoding="UTF-8"?> <MediaContainer friendlyName="myPlex" identifier="com.plexapp.plugins.myplex" machineIdentifier="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" size="1"> <Server accessToken="xxxxxxxxxxxxxx9jY4" name="xxxxxxxxxxx" address="xxxxxxx" port="32400" version="1.16.3.1402-22929c8a2" scheme="http" host="xxxxxxx" localAddresses="" machineIdentifier="xxxxxxxxxxx" createdAt="1549384857" updatedAt="1565904197" owned="0" synced="0" sourceTitle="xxxxxxx" ownerId="xxxxxxxx" home="0"/> </MediaContainer>
If you see the Tokens are distinct and of course localAddresses is not used because is not at your location.
Regards
Have you tried the host/port option instead of the server_name
option?
@maykar It is being thought that all servers within an account are the property of the person being authenticated, and this is not the case.
A part of the code uses the variable "localAddresses" that returns the xml, when this variable is only reported by Plex when the server is local (You belong) not remote (has been shared with you by someone).
It is also assumed that the access token is the same as the user token when as you can see in the XML example this is not the case.
I'll paste the lines where the problem is:
Line 298
def image_url(url_elements, cert_check, img):
"""Plex can resize images with a long & partially % encoded url."""
from urllib.parse import quote
ssl, host, local, port, token, self_cert, dl_images = url_elements
if not cert_check and not self_cert:
ssl = ''
if dl_images:
host = local
encoded = quote('http{0}://{1}:{2}{3}?X-Plex-Token={4}'.format(ssl,
local,
port,
img,
token),
safe='')
url = ('http{0}://{1}:{2}/photo/:/transcode?width=200&height=200'
'&minSize=1&url={3}&X-Plex-Token={4}').format(ssl, host, port,
encoded, token)
"""Check if image exists"""
if not self_cert:
r = requests.head(url, verify=False)
else:
r = requests.head(url)
if r.status_code == 200:
return url
else:
return False
And using the same token for all the code. You must use "host" or "address" instead for image download, and add a new variable for each server that is a token. If there is no token then use the one provided by the user in its configuration.
I understand. A while back I removed server_name
from the readme as that option created more problems than it solved, with user confusion and plex API changes. It's still in the code to avoid a breaking change for the people who are using it successfully. As such, I don't think I'll expand that feature, it should be considered depreciated.
Are you able to connect to the server using host/port instead of server_name
? The code you are pointing to is only used when using server_name
.
Closing this issue as stale and because the server_name
option is depreciated and this should be possible by using host/port. If you are unable to connect with host/port, please reopen this issue or create a new one.