mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 14:14:19 +00:00
Factor out artUrl, thumbUrl, bannerUrl to mixins
This commit is contained in:
parent
8915134b6b
commit
c41f89bf9b
5 changed files with 19 additions and 48 deletions
|
@ -67,22 +67,6 @@ class Audio(PlexPartialObject):
|
|||
self.userRating = utils.cast(float, data.attrib.get('userRating', 0))
|
||||
self.viewCount = utils.cast(int, data.attrib.get('viewCount', 0))
|
||||
|
||||
@property
|
||||
def thumbUrl(self):
|
||||
""" Return the first first thumbnail url starting on
|
||||
the most specific thumbnail for that item.
|
||||
"""
|
||||
key = self.firstAttr('thumb', 'parentThumb', 'granparentThumb')
|
||||
return self._server.url(key, includeToken=True) if key else None
|
||||
|
||||
@property
|
||||
def artUrl(self):
|
||||
""" Return the first first art url starting on
|
||||
the most specific art for that item.
|
||||
"""
|
||||
art = self.firstAttr('art', 'grandparentArt')
|
||||
return self._server.url(art, includeToken=True) if art else None
|
||||
|
||||
def url(self, part):
|
||||
""" Returns the full URL for the audio item. Typically used for getting a specific track. """
|
||||
return self._server.url(part, includeToken=True) if part else None
|
||||
|
|
|
@ -1598,16 +1598,6 @@ class Collections(PlexPartialObject, ArtMixin, PosterMixin, LabelMixin):
|
|||
def children(self):
|
||||
return self.fetchItems(self.key)
|
||||
|
||||
@property
|
||||
def thumbUrl(self):
|
||||
""" Return the thumbnail url for the collection."""
|
||||
return self._server.url(self.thumb, includeToken=True) if self.thumb else None
|
||||
|
||||
@property
|
||||
def artUrl(self):
|
||||
""" Return the art url for the collection."""
|
||||
return self._server.url(self.art, includeToken=True) if self.art else None
|
||||
|
||||
def item(self, title):
|
||||
""" Returns the item in the collection that matches the specified title.
|
||||
|
||||
|
|
|
@ -8,6 +8,12 @@ from plexapi.exceptions import NotFound
|
|||
class ArtMixin(object):
|
||||
""" Mixin for Plex objects that can have background artwork."""
|
||||
|
||||
@property
|
||||
def artUrl(self):
|
||||
""" Return the art url for the Plex object."""
|
||||
art = self.firstAttr('art', 'grandparentArt')
|
||||
return self._server.url(art, includeToken=True) if art else None
|
||||
|
||||
def arts(self):
|
||||
""" Returns list of available :class:`~plexapi.media.Art` objects. """
|
||||
return self.fetchItems('/library/metadata/%s/arts' % self.ratingKey, cls=media.Art)
|
||||
|
@ -39,6 +45,12 @@ class ArtMixin(object):
|
|||
class BannerMixin(object):
|
||||
""" Mixin for Plex objects that can have banners."""
|
||||
|
||||
@property
|
||||
def bannerUrl(self):
|
||||
""" Return the banner url for the Plex object."""
|
||||
banner = self.firstAttr('banner')
|
||||
return self._server.url(banner, includeToken=True) if banner else None
|
||||
|
||||
def banners(self):
|
||||
""" Returns list of available :class:`~plexapi.media.Banner` objects. """
|
||||
return self.fetchItems('/library/metadata/%s/banners' % self.ratingKey, cls=media.Banner)
|
||||
|
@ -70,6 +82,12 @@ class BannerMixin(object):
|
|||
class PosterMixin(object):
|
||||
""" Mixin for Plex objects that can have posters."""
|
||||
|
||||
@property
|
||||
def thumbUrl(self):
|
||||
""" Return the thumb url for the Plex object."""
|
||||
thumb = self.firstAttr('thumb', 'parentThumb', 'granparentThumb')
|
||||
return self._server.url(thumb, includeToken=True) if thumb else None
|
||||
|
||||
def posters(self):
|
||||
""" Returns list of available :class:`~plexapi.media.Poster` objects. """
|
||||
return self.fetchItems('/library/metadata/%s/posters' % self.ratingKey, cls=media.Poster)
|
||||
|
|
|
@ -210,7 +210,7 @@ class Photo(PlexPartialObject, Playable, TagMixin):
|
|||
|
||||
@property
|
||||
def thumbUrl(self):
|
||||
"""Return URL for the thumbnail image."""
|
||||
""" Return the thumb url for the photo."""
|
||||
key = self.firstAttr('thumb', 'parentThumb', 'granparentThumb')
|
||||
return self._server.url(key, includeToken=True) if key else None
|
||||
|
||||
|
|
|
@ -66,22 +66,6 @@ class Video(PlexPartialObject):
|
|||
""" Returns True if this video is watched. """
|
||||
return bool(self.viewCount > 0) if self.viewCount else False
|
||||
|
||||
@property
|
||||
def thumbUrl(self):
|
||||
""" Return the first first thumbnail url starting on
|
||||
the most specific thumbnail for that item.
|
||||
"""
|
||||
thumb = self.firstAttr('thumb', 'parentThumb', 'granparentThumb')
|
||||
return self._server.url(thumb, includeToken=True) if thumb else None
|
||||
|
||||
@property
|
||||
def artUrl(self):
|
||||
""" Return the first first art url starting on
|
||||
the most specific art for that item.
|
||||
"""
|
||||
art = self.firstAttr('art', 'grandparentArt')
|
||||
return self._server.url(art, includeToken=True) if art else None
|
||||
|
||||
def url(self, part):
|
||||
""" Returns the full url for something. Typically used for getting a specific image. """
|
||||
return self._server.url(part, includeToken=True) if part else None
|
||||
|
@ -460,11 +444,6 @@ class Show(Video, ArtMixin, BannerMixin, PosterMixin, SplitMergeMixin, UnmatchMa
|
|||
""" Returns True if the show is fully watched. """
|
||||
return bool(self.viewedLeafCount == self.leafCount)
|
||||
|
||||
@property
|
||||
def bannerUrl(self):
|
||||
""" Return the banner url for the show."""
|
||||
return self._server.url(self.banner, includeToken=True) if self.banner else None
|
||||
|
||||
def preferences(self):
|
||||
""" Returns a list of :class:`~plexapi.settings.Preferences` objects. """
|
||||
items = []
|
||||
|
|
Loading…
Reference in a new issue