Skip to content

Commit

Permalink
Add logo resources
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyWong16 committed Sep 1, 2024
1 parent 98beefe commit 4110583
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
5 changes: 5 additions & 0 deletions plexapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,11 @@ class Art(BaseResource):
TAG = 'Photo'


class Logo(BaseResource):
""" Represents a single Logo object. """
TAG = 'Photo'


class Poster(BaseResource):
""" Represents a single Poster object. """
TAG = 'Photo'
Expand Down
62 changes: 62 additions & 0 deletions plexapi/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,63 @@ def setArt(self, art):
return self


class LogoUrlMixin:
""" Mixin for Plex objects that can have a logo url. """

@property
def logoUrl(self):
""" Return the logo url for the Plex object. """
image = next((i for i in self.images if i.type == 'clearLogo'), None)
return self._server.url(image.url, includeToken=True) if image else None


class LogoLockMixin:
""" Mixin for Plex objects that can have a locked logo. """

def lockLogo(self):
""" Lock the logo for a Plex object. """
raise NotImplementedError('Logo cannot be locked through the API.')

def unlockLogo(self):
""" Unlock the logo for a Plex object. """
raise NotImplementedError('Logo cannot be unlocked through the API.')


class LogoMixin(LogoUrlMixin, LogoLockMixin):
""" Mixin for Plex objects that can have logos. """

def logos(self):
""" Returns list of available :class:`~plexapi.media.Logo` objects. """
return self.fetchItems(f'/library/metadata/{self.ratingKey}/clearLogos', cls=media.Logo)

def uploadLogo(self, url=None, filepath=None):
""" Upload a logo from a url or filepath.
Parameters:
url (str): The full URL to the image to upload.
filepath (str): The full file path the the image to upload or file-like object.
"""
if url:
key = f'/library/metadata/{self.ratingKey}/clearLogos?url={quote_plus(url)}'
self._server.query(key, method=self._server._session.post)
elif filepath:
key = f'/library/metadata/{self.ratingKey}/clearLogos'
data = openOrRead(filepath)
self._server.query(key, method=self._server._session.post, data=data)
return self

def setLogo(self, logo):
""" Set the logo for a Plex object.
Raises:
:exc:`~plexapi.exceptions.NotImplementedError`: Logo cannot be set through the API.
"""
raise NotImplementedError(
'Logo cannot be set through the API. '
'Re-upload the logo using "uploadLogo" to set it.'
)


class PosterUrlMixin:
""" Mixin for Plex objects that can have a poster url. """

Expand Down Expand Up @@ -513,6 +570,11 @@ def uploadTheme(self, url=None, filepath=None, timeout=None):
return self

def setTheme(self, theme):
""" Set the theme for a Plex object.
Raises:
:exc:`~plexapi.exceptions.NotImplementedError`: Themes cannot be set through the API.
"""
raise NotImplementedError(
'Themes cannot be set through the API. '
'Re-upload the theme using "uploadTheme" to set it.'
Expand Down
2 changes: 2 additions & 0 deletions plexapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
'theme': 317,
'studio': 318,
'network': 319,
'showOrdering': 322,
'clearLogo': 323,
'place': 400,
}
REVERSETAGTYPES = {v: k for k, v in TAGTYPES.items()}
Expand Down
6 changes: 3 additions & 3 deletions plexapi/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from plexapi.exceptions import BadRequest
from plexapi.mixins import (
AdvancedSettingsMixin, SplitMergeMixin, UnmatchMatchMixin, ExtrasMixin, HubsMixin, PlayedUnplayedMixin, RatingMixin,
ArtUrlMixin, ArtMixin, PosterUrlMixin, PosterMixin, ThemeUrlMixin, ThemeMixin,
ArtUrlMixin, ArtMixin, LogoMixin, PosterUrlMixin, PosterMixin, ThemeUrlMixin, ThemeMixin,
MovieEditMixins, ShowEditMixins, SeasonEditMixins, EpisodeEditMixins,
WatchlistMixin
)
Expand Down Expand Up @@ -334,7 +334,7 @@ def sync(self, videoQuality, client=None, clientId=None, limit=None, unwatched=F
class Movie(
Video, Playable,
AdvancedSettingsMixin, SplitMergeMixin, UnmatchMatchMixin, ExtrasMixin, HubsMixin, RatingMixin,
ArtMixin, PosterMixin, ThemeMixin,
ArtMixin, LogoMixin, PosterMixin, ThemeMixin,
MovieEditMixins,
WatchlistMixin
):
Expand Down Expand Up @@ -491,7 +491,7 @@ def metadataDirectory(self):
class Show(
Video,
AdvancedSettingsMixin, SplitMergeMixin, UnmatchMatchMixin, ExtrasMixin, HubsMixin, RatingMixin,
ArtMixin, PosterMixin, ThemeMixin,
ArtMixin, LogoMixin, PosterMixin, ThemeMixin,
ShowEditMixins,
WatchlistMixin
):
Expand Down

0 comments on commit 4110583

Please sign in to comment.