mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-22 11:43:13 +00:00
Choose Closest Thumbnail for Audio Tracks #102
This commit is contained in:
parent
85ea65b8a4
commit
12406082ec
4 changed files with 20 additions and 33 deletions
|
@ -44,8 +44,8 @@ class Audio(PlexPartialObject):
|
|||
@property
|
||||
def thumbUrl(self):
|
||||
""" Return url to for the thumbnail image. """
|
||||
if self.thumb:
|
||||
return self._server.url(self.thumb)
|
||||
key = self.firstAttr('thumb', 'parentThumb', 'granparentThumb')
|
||||
return self._server.url(key) if key else None
|
||||
|
||||
|
||||
@utils.registerPlexObject
|
||||
|
@ -272,12 +272,6 @@ class Track(Audio, Playable):
|
|||
""" Returns a filename for use in download. """
|
||||
return '%s - %s %s' % (self.grandparentTitle, self.parentTitle, self.title)
|
||||
|
||||
@property
|
||||
def thumbUrl(self):
|
||||
""" Return url to for the thumbnail image. """
|
||||
if self.parentThumb:
|
||||
return self._server.url(self.parentThumb)
|
||||
|
||||
def album(self):
|
||||
""" Return this track's :class:`~plexapi.audio.Album`. """
|
||||
return self.fetchItem(self.parentKey)
|
||||
|
|
|
@ -44,17 +44,21 @@ class PlexObject(object):
|
|||
self._loadData(data)
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s>' % ':'.join([p for p in [
|
||||
self.__class__.__name__,
|
||||
utils.firstAttr(self, '_baseurl', 'key', 'id', 'playQueueID', 'uri'),
|
||||
utils.firstAttr(self, 'title', 'name', 'username', 'product', 'tag')
|
||||
] if p])
|
||||
uid = self._clean(self.firstAttr('_baseurl', 'key', 'id', 'playQueueID', 'uri'))
|
||||
name = self._clean(self.firstAttr('title', 'name', 'username', 'product', 'tag'))
|
||||
return '<%s>' % ':'.join([p for p in [self.__class__.__name__, uid, name] if p])
|
||||
|
||||
def __setattr__(self, attr, value):
|
||||
# dont overwrite an attr with None unless its a private variable
|
||||
if value is not None or attr.startswith('_') or attr not in self.__dict__:
|
||||
self.__dict__[attr] = value
|
||||
|
||||
def _clean(self, value):
|
||||
""" Clean attr value for display in __repr__. """
|
||||
if value:
|
||||
value = value.replace('/library/metadata/', '').replace('/children', '')
|
||||
return value.replace(' ', '-')[:20]
|
||||
|
||||
def _buildItem(self, elem, cls=None, initpath=None):
|
||||
""" Factory function to build objects based on registered PLEXOBJECTS. """
|
||||
# cls is specified, build the object and return
|
||||
|
@ -157,6 +161,13 @@ class PlexObject(object):
|
|||
items.append(item)
|
||||
return items
|
||||
|
||||
def firstAttr(self, *attrs):
|
||||
""" Return the first attribute in attrs that is not None. """
|
||||
for attr in attrs:
|
||||
value = self.__dict__.get(attr)
|
||||
if value is not None:
|
||||
return value
|
||||
|
||||
def listAttrs(self, data, attr, **kwargs):
|
||||
results = []
|
||||
for elem in data:
|
||||
|
|
|
@ -66,18 +66,6 @@ def cast(func, value):
|
|||
return value
|
||||
|
||||
|
||||
def firstAttr(elem, *attrs):
|
||||
""" Return the first attribute in attrs that is not None. """
|
||||
for attr in attrs:
|
||||
value = elem.__dict__.get(attr)
|
||||
if value is not None:
|
||||
value = str(value).replace(' ','-')
|
||||
if attr == 'key':
|
||||
value = value.replace('/library/metadata/','')
|
||||
value = value.replace('/children','')
|
||||
return value[:20]
|
||||
|
||||
|
||||
def getattributeOrNone(obj, self, attr):
|
||||
""" Returns result from __getattribute__ or None if not found. """
|
||||
try:
|
||||
|
|
|
@ -49,8 +49,8 @@ class Video(PlexPartialObject):
|
|||
@property
|
||||
def thumbUrl(self):
|
||||
""" Return url to for the thumbnail image. """
|
||||
if self.thumb:
|
||||
return self._server.url(self.thumb)
|
||||
thumb = self.firstAttr('thumb', 'parentThumb', 'granparentThumb')
|
||||
return self._server.url(thumb) if thumb else None
|
||||
|
||||
def markWatched(self):
|
||||
""" Mark video as watched. """
|
||||
|
@ -494,12 +494,6 @@ class Episode(Video, Playable):
|
|||
self._seasonNumber = self.parentIndex if self.parentIndex else self.season().seasonNumber
|
||||
return utils.cast(int, self._seasonNumber)
|
||||
|
||||
@property
|
||||
def thumbUrl(self):
|
||||
""" Return url to for the thumbnail image. """
|
||||
if self.grandparentThumb:
|
||||
return self._server.url(self.grandparentThumb)
|
||||
|
||||
def season(self):
|
||||
"""" Return this episodes :func:`~plexapi.video.Season`.. """
|
||||
return self.fetchItem(self.parentKey)
|
||||
|
|
Loading…
Reference in a new issue