Skip to content

Commit

Permalink
Set correct server instance for playlist items
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyWong16 committed Sep 9, 2024
1 parent 23ffc01 commit cfb5eff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plexapi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
MediaContainerT = TypeVar("MediaContainerT", bound="MediaContainer")

USER_DONT_RELOAD_FOR_KEYS = set()
_DONT_RELOAD_FOR_KEYS = {'key'}
_DONT_RELOAD_FOR_KEYS = {'key', 'sourceURI'}
OPERATORS = {
'exact': lambda v, q: v == q,
'iexact': lambda v, q: v.lower() == q.lower(),
Expand Down
4 changes: 2 additions & 2 deletions plexapi/myplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ def resource(self, name):
""" Returns the :class:`~plexapi.myplex.MyPlexResource` that matches the name specified.
Parameters:
name (str): Name to match against.
name (str): Name or machine identifier to match against.
"""
for resource in self.resources():
if resource.name.lower() == name.lower():
if resource.name.lower() == name.lower() or resource.clientIdentifier == name:
return resource
raise NotFound(f'Unable to find resource {name}')

Expand Down
14 changes: 14 additions & 0 deletions plexapi/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ def items(self):
if self._items is None:
key = f'{self.key}/items'
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
return self._items

Expand Down

0 comments on commit cfb5eff

Please sign in to comment.