mirror of
https://github.com/pkkid/python-plexapi
synced 2025-02-16 21:08:27 +00:00
Separate art and poster mixin
This commit is contained in:
parent
5a4d564fd3
commit
68b77b67b8
5 changed files with 45 additions and 41 deletions
|
@ -4,7 +4,7 @@ from urllib.parse import quote_plus
|
|||
from plexapi import library, media, utils
|
||||
from plexapi.base import Playable, PlexPartialObject
|
||||
from plexapi.exceptions import BadRequest
|
||||
from plexapi.mixins import PosterArt
|
||||
from plexapi.mixins import ArtMixin, PosterMixin
|
||||
|
||||
|
||||
class Audio(PlexPartialObject):
|
||||
|
@ -124,7 +124,7 @@ class Audio(PlexPartialObject):
|
|||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Artist(Audio, PosterArt):
|
||||
class Artist(Audio, ArtMixin, PosterMixin):
|
||||
""" Represents a single Artist.
|
||||
|
||||
Attributes:
|
||||
|
@ -227,7 +227,7 @@ class Artist(Audio, PosterArt):
|
|||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Album(Audio, PosterArt):
|
||||
class Album(Audio, ArtMixin, PosterMixin):
|
||||
""" Represents a single Album.
|
||||
|
||||
Attributes:
|
||||
|
|
|
@ -4,7 +4,7 @@ from urllib.parse import quote, quote_plus, unquote, urlencode
|
|||
from plexapi import X_PLEX_CONTAINER_SIZE, log, media, utils
|
||||
from plexapi.base import OPERATORS, PlexObject, PlexPartialObject
|
||||
from plexapi.exceptions import BadRequest, NotFound
|
||||
from plexapi.mixins import PosterArt
|
||||
from plexapi.mixins import ArtMixin, PosterMixin
|
||||
from plexapi.settings import Setting
|
||||
from plexapi.utils import deprecated
|
||||
|
||||
|
@ -1526,7 +1526,7 @@ class FirstCharacter(PlexObject):
|
|||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Collections(PlexPartialObject, PosterArt):
|
||||
class Collections(PlexPartialObject, ArtMixin, PosterMixin):
|
||||
""" Represents a single Collection.
|
||||
|
||||
Attributes:
|
||||
|
|
|
@ -4,35 +4,8 @@ from urllib.parse import quote_plus
|
|||
from plexapi import media
|
||||
|
||||
|
||||
class PosterArt(object):
|
||||
""" Mixin for Plex objects that can have posters and artwork."""
|
||||
|
||||
def posters(self):
|
||||
""" Returns list of available :class:`~plexapi.media.Poster` objects. """
|
||||
return self.fetchItems('/library/metadata/%s/posters' % self.ratingKey, cls=media.Poster)
|
||||
|
||||
def uploadPoster(self, url=None, filepath=None):
|
||||
""" Upload poster from url or filepath and set it as the selected poster.
|
||||
|
||||
Parameters:
|
||||
url (str): The full URL to the image to upload.
|
||||
filepath (str): The full file path the the image to upload.
|
||||
"""
|
||||
if url:
|
||||
key = '/library/metadata/%s/posters?url=%s' % (self.ratingKey, quote_plus(url))
|
||||
self._server.query(key, method=self._server._session.post)
|
||||
elif filepath:
|
||||
key = '/library/metadata/%s/posters?' % self.ratingKey
|
||||
data = open(filepath, 'rb').read()
|
||||
self._server.query(key, method=self._server._session.post, data=data)
|
||||
|
||||
def setPoster(self, poster):
|
||||
""" Set the poster for a Plex object.
|
||||
|
||||
Parameters:
|
||||
poster (:class:`~plexapi.media.Poster`): The poster object to select.
|
||||
"""
|
||||
poster.select()
|
||||
class ArtMixin(object):
|
||||
""" Mixin for Plex objects that can have artwork."""
|
||||
|
||||
def arts(self):
|
||||
""" Returns list of available :class:`~plexapi.media.Art` objects. """
|
||||
|
@ -60,3 +33,34 @@ class PosterArt(object):
|
|||
art (:class:`~plexapi.media.Art`): The art object to select.
|
||||
"""
|
||||
art.select()
|
||||
|
||||
|
||||
class PosterMixin(object):
|
||||
""" Mixin for Plex objects that can have posters."""
|
||||
|
||||
def posters(self):
|
||||
""" Returns list of available :class:`~plexapi.media.Poster` objects. """
|
||||
return self.fetchItems('/library/metadata/%s/posters' % self.ratingKey, cls=media.Poster)
|
||||
|
||||
def uploadPoster(self, url=None, filepath=None):
|
||||
""" Upload poster from url or filepath and set it as the selected poster.
|
||||
|
||||
Parameters:
|
||||
url (str): The full URL to the image to upload.
|
||||
filepath (str): The full file path the the image to upload.
|
||||
"""
|
||||
if url:
|
||||
key = '/library/metadata/%s/posters?url=%s' % (self.ratingKey, quote_plus(url))
|
||||
self._server.query(key, method=self._server._session.post)
|
||||
elif filepath:
|
||||
key = '/library/metadata/%s/posters?' % self.ratingKey
|
||||
data = open(filepath, 'rb').read()
|
||||
self._server.query(key, method=self._server._session.post, data=data)
|
||||
|
||||
def setPoster(self, poster):
|
||||
""" Set the poster for a Plex object.
|
||||
|
||||
Parameters:
|
||||
poster (:class:`~plexapi.media.Poster`): The poster object to select.
|
||||
"""
|
||||
poster.select()
|
||||
|
|
|
@ -5,13 +5,13 @@ from plexapi import utils
|
|||
from plexapi.base import Playable, PlexPartialObject
|
||||
from plexapi.exceptions import BadRequest, NotFound, Unsupported
|
||||
from plexapi.library import LibrarySection
|
||||
from plexapi.mixins import PosterArt
|
||||
from plexapi.mixins import ArtMixin, PosterMixin
|
||||
from plexapi.playqueue import PlayQueue
|
||||
from plexapi.utils import cast, toDatetime
|
||||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Playlist(PlexPartialObject, Playable, PosterArt):
|
||||
class Playlist(PlexPartialObject, Playable, ArtMixin, PosterMixin):
|
||||
""" Represents a single Playlist.
|
||||
|
||||
Attributes:
|
||||
|
|
|
@ -5,7 +5,7 @@ from urllib.parse import quote_plus, urlencode
|
|||
from plexapi import library, media, settings, utils
|
||||
from plexapi.base import Playable, PlexPartialObject
|
||||
from plexapi.exceptions import BadRequest, NotFound
|
||||
from plexapi.mixins import PosterArt
|
||||
from plexapi.mixins import ArtMixin, PosterMixin
|
||||
|
||||
|
||||
class Video(PlexPartialObject):
|
||||
|
@ -260,7 +260,7 @@ class Video(PlexPartialObject):
|
|||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Movie(Video, Playable, PosterArt):
|
||||
class Movie(Video, Playable, ArtMixin, PosterMixin):
|
||||
""" Represents a single Movie.
|
||||
|
||||
Attributes:
|
||||
|
@ -384,7 +384,7 @@ class Movie(Video, Playable, PosterArt):
|
|||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Show(Video, PosterArt):
|
||||
class Show(Video, ArtMixin, PosterMixin):
|
||||
""" Represents a single Show (including all seasons and episodes).
|
||||
|
||||
Attributes:
|
||||
|
@ -582,7 +582,7 @@ class Show(Video, PosterArt):
|
|||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Season(Video, PosterArt):
|
||||
class Season(Video, ArtMixin, PosterMixin):
|
||||
""" Represents a single Show Season (including all episodes).
|
||||
|
||||
Attributes:
|
||||
|
@ -708,7 +708,7 @@ class Season(Video, PosterArt):
|
|||
|
||||
|
||||
@utils.registerPlexObject
|
||||
class Episode(Video, Playable, PosterArt):
|
||||
class Episode(Video, Playable, ArtMixin, PosterMixin):
|
||||
""" Represents a single Shows Episode.
|
||||
|
||||
Attributes:
|
||||
|
|
Loading…
Add table
Reference in a new issue