Set correct server instance for playlist items (#1463)

This commit is contained in:
JonnyWong16 2024-11-16 13:58:16 -08:00 committed by GitHub
parent 4a8f7483c2
commit 99205d3b86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 3 deletions

View file

@ -17,7 +17,7 @@ PlexObjectT = TypeVar("PlexObjectT", bound='PlexObject')
MediaContainerT = TypeVar("MediaContainerT", bound="MediaContainer") MediaContainerT = TypeVar("MediaContainerT", bound="MediaContainer")
USER_DONT_RELOAD_FOR_KEYS = set() USER_DONT_RELOAD_FOR_KEYS = set()
_DONT_RELOAD_FOR_KEYS = {'key'} _DONT_RELOAD_FOR_KEYS = {'key', 'sourceURI'}
OPERATORS = { OPERATORS = {
'exact': lambda v, q: v == q, 'exact': lambda v, q: v == q,
'iexact': lambda v, q: v.lower() == q.lower(), 'iexact': lambda v, q: v.lower() == q.lower(),

View file

@ -283,10 +283,10 @@ class MyPlexAccount(PlexObject):
""" Returns the :class:`~plexapi.myplex.MyPlexResource` that matches the name specified. """ Returns the :class:`~plexapi.myplex.MyPlexResource` that matches the name specified.
Parameters: Parameters:
name (str): Name to match against. name (str): Name or machine identifier to match against.
""" """
for resource in self.resources(): for resource in self.resources():
if resource.name.lower() == name.lower(): if resource.name.lower() == name.lower() or resource.clientIdentifier == name:
return resource return resource
raise NotFound(f'Unable to find resource {name}') raise NotFound(f'Unable to find resource {name}')

View file

@ -190,6 +190,20 @@ class Playlist(
if self._items is None: if self._items is None:
key = f'{self.key}/items' key = f'{self.key}/items'
items = self.fetchItems(key) items = self.fetchItems(key)
# Cache server connections to avoid reconnecting for each item
_servers = {}
for item in items:
if item.sourceURI:
serverID = item.sourceURI.split('/')[2]
if serverID not in _servers:
try:
_servers[serverID] = self._server.myPlexAccount().resource(serverID).connect()
except NotFound:
# Override the server connection with None if the server is not found
_servers[serverID] = None
item._server = _servers[serverID]
self._items = items self._items = items
return self._items return self._items