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