Update plexapi to 4.3.1

This commit is contained in:
JonnyWong16 2021-02-03 15:31:34 -08:00
commit 5c63308441
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 21 additions and 14 deletions

View file

@ -15,7 +15,7 @@ CONFIG = PlexConfig(CONFIG_PATH)
# PlexAPI Settings # PlexAPI Settings
PROJECT = 'PlexAPI' PROJECT = 'PlexAPI'
VERSION = '4.3.0' VERSION = '4.3.1'
TIMEOUT = CONFIG.get('plexapi.timeout', 30, int) TIMEOUT = CONFIG.get('plexapi.timeout', 30, int)
X_PLEX_CONTAINER_SIZE = CONFIG.get('plexapi.container_size', 100, int) X_PLEX_CONTAINER_SIZE = CONFIG.get('plexapi.container_size', 100, int)
X_PLEX_ENABLE_FAST_CONNECT = CONFIG.get('plexapi.enable_fast_connect', False, bool) X_PLEX_ENABLE_FAST_CONNECT = CONFIG.get('plexapi.enable_fast_connect', False, bool)

View file

@ -947,31 +947,38 @@ class MyPlexResource(PlexObject):
def connect(self, ssl=None, timeout=None): def connect(self, ssl=None, timeout=None):
""" Returns a new :class:`~plexapi.server.PlexServer` or :class:`~plexapi.client.PlexClient` object. """ Returns a new :class:`~plexapi.server.PlexServer` or :class:`~plexapi.client.PlexClient` object.
Often times there is more than one address specified for a server or client. Often times there is more than one address specified for a server or client.
This function will prioritize local connections before remote and HTTPS before HTTP. This function will prioritize local connections before remote or relay and HTTPS before HTTP.
After trying to connect to all available addresses for this resource and After trying to connect to all available addresses for this resource and
assuming at least one connection was successful, the PlexServer object is built and returned. assuming at least one connection was successful, the PlexServer object is built and returned.
Parameters: Parameters:
ssl (optional): Set True to only connect to HTTPS connections. Set False to ssl (bool, optional): Set True to only connect to HTTPS connections. Set False to
only connect to HTTP connections. Set None (default) to connect to any only connect to HTTP connections. Set None (default) to connect to any
HTTP or HTTPS connection. HTTP or HTTPS connection.
timeout (int, optional): The timeout in seconds to attempt each connection.
Raises: Raises:
:exc:`~plexapi.exceptions.NotFound`: When unable to connect to any addresses for this resource. :exc:`~plexapi.exceptions.NotFound`: When unable to connect to any addresses for this resource.
""" """
# Sort connections from (https, local) to (http, remote) # Keys in the order we want the connections to be sorted
locations = ['local', 'remote', 'relay']
schemes = ['https', 'http']
connections_dict = {location: {scheme: [] for scheme in schemes} for location in locations}
for connection in self.connections:
# Only check non-local connections unless we own the resource # Only check non-local connections unless we own the resource
connections = sorted(self.connections, key=lambda c: c.local, reverse=True) if self.owned or (not self.owned and not connection.local):
owned_or_unowned_non_local = lambda x: self.owned or (not self.owned and not x.local) location = 'relay' if connection.relay else ('local' if connection.local else 'remote')
https = [c.uri for c in connections if owned_or_unowned_non_local(c)] connections_dict[location]['http'].append(connection.httpuri)
http = [c.httpuri for c in connections if owned_or_unowned_non_local(c)] connections_dict[location]['https'].append(connection.uri)
cls = PlexServer if 'server' in self.provides else PlexClient if ssl is True: schemes.remove('http')
# Force ssl, no ssl, or any (default) elif ssl is False: schemes.remove('https')
if ssl is True: connections = https connections = []
elif ssl is False: connections = http for location in locations:
else: connections = https + http for scheme in schemes:
connections.extend(connections_dict[location][scheme])
# Try connecting to all known resource connections in parellel, but # Try connecting to all known resource connections in parellel, but
# only return the first server (in order) that provides a response. # only return the first server (in order) that provides a response.
cls = PlexServer if 'server' in self.provides else PlexClient
listargs = [[cls, url, self.accessToken, timeout] for url in connections] listargs = [[cls, url, self.accessToken, timeout] for url in connections]
log.debug('Testing %s resource connections..', len(listargs)) log.debug('Testing %s resource connections..', len(listargs))
results = utils.threaded(_connect, listargs) results = utils.threaded(_connect, listargs)