mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
Add helper object to retrieve PlexObject (#1369)
This commit is contained in:
parent
7802b79d30
commit
0601aaa40e
2 changed files with 14 additions and 1 deletions
|
@ -95,7 +95,7 @@ class PlexObject:
|
|||
ehash = f"{ehash}.session"
|
||||
elif initpath.startswith('/status/sessions/history'):
|
||||
ehash = f"{ehash}.history"
|
||||
ecls = utils.PLEXOBJECTS.get(ehash, utils.PLEXOBJECTS.get(elem.tag))
|
||||
ecls = utils.getPlexObject(ehash, default=elem.tag)
|
||||
# log.debug('Building %s as %s', elem.tag, ecls.__name__)
|
||||
if ecls is not None:
|
||||
return ecls(self._server, elem, initpath, parent=self)
|
||||
|
|
|
@ -136,6 +136,19 @@ def registerPlexObject(cls):
|
|||
return cls
|
||||
|
||||
|
||||
def getPlexObject(ehash, default):
|
||||
""" Return the PlexObject class for the specified ehash. This recursively looks up the class
|
||||
with the highest specificity, falling back to the default class if not found.
|
||||
"""
|
||||
cls = PLEXOBJECTS.get(ehash)
|
||||
if cls is not None:
|
||||
return cls
|
||||
if '.' in ehash:
|
||||
ehash = ehash.rsplit('.', 1)[0]
|
||||
return getPlexObject(ehash, default=default)
|
||||
return PLEXOBJECTS.get(default)
|
||||
|
||||
|
||||
def cast(func, value):
|
||||
""" Cast the specified value to the specified type (returned by func). Currently this
|
||||
only support str, int, float, bool. Should be extended if needed.
|
||||
|
|
Loading…
Reference in a new issue