Skip to content

Commit b4bc23c

Browse files
committed
Add support for Square Art
1 parent e8451cc commit b4bc23c

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

plexapi/media.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,11 @@ class Poster(BaseResource):
11161116
TAG = 'Photo'
11171117

11181118

1119+
class SquareArt(BaseResource):
1120+
""" Represents a single Square Art object. """
1121+
TAG = 'Photo'
1122+
1123+
11191124
class Theme(BaseResource):
11201125
""" Represents a single Theme object. """
11211126
TAG = 'Track'

plexapi/mixins.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,67 @@ def setPoster(self, poster):
520520
return self
521521

522522

523+
class SquareArtUrlMixin:
524+
""" Mixin for Plex objects that can have a square art url. """
525+
526+
@property
527+
def squareArtUrl(self):
528+
""" Return the square art url for the Plex object. """
529+
image = next((i for i in self.images if i.type == 'squareArt'), None)
530+
return self._server.url(image.url, includeToken=True) if image else None
531+
532+
533+
class SquareArtLockMixin:
534+
""" Mixin for Plex objects that can have a locked square art. """
535+
536+
def lockSquareArt(self):
537+
""" Lock the square art for a Plex object. """
538+
return self._edit(**{'squareArt.locked': 1})
539+
540+
def unlockSquareArt(self):
541+
""" Unlock the square art for a Plex object. """
542+
return self._edit(**{'squareArt.locked': 0})
543+
544+
545+
class SquareArtMixin(SquareArtUrlMixin, SquareArtLockMixin):
546+
""" Mixin for Plex objects that can have square art. """
547+
548+
def squareArts(self):
549+
""" Returns list of available :class:`~plexapi.media.SquareArt` objects. """
550+
return self.fetchItems(f'/library/metadata/{self.ratingKey}/squareArts', cls=media.SquareArt)
551+
552+
def uploadSquareArt(self, url=None, filepath=None):
553+
""" Upload a square art from a url or filepath.
554+
555+
Parameters:
556+
url (str): The full URL to the image to upload.
557+
filepath (str): The full file path the the image to upload or file-like object.
558+
"""
559+
if url:
560+
key = f'/library/metadata/{self.ratingKey}/squareArts?url={quote_plus(url)}'
561+
self._server.query(key, method=self._server._session.post)
562+
elif filepath:
563+
key = f'/library/metadata/{self.ratingKey}/squareArts'
564+
data = openOrRead(filepath)
565+
self._server.query(key, method=self._server._session.post, data=data)
566+
return self
567+
568+
def setSquareArt(self, squareArt):
569+
""" Set the square art for a Plex object.
570+
571+
Parameters:
572+
squareArt (:class:`~plexapi.media.SquareArt`): The square art object to select.
573+
"""
574+
squareArt.select()
575+
return self
576+
577+
def deleteSquareArt(self):
578+
""" Delete the square art from a Plex object. """
579+
key = f'/library/metadata/{self.ratingKey}/squareArt'
580+
self._server.query(key, method=self._server._session.delete)
581+
return self
582+
583+
523584
class ThemeUrlMixin:
524585
""" Mixin for Plex objects that can have a theme url. """
525586

plexapi/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
'network': 319,
9393
'showOrdering': 322,
9494
'clearLogo': 323,
95+
'squareArt': 325,
9596
'place': 400,
9697
}
9798
REVERSETAGTYPES = {v: k for k, v in TAGTYPES.items()}

plexapi/video.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from plexapi.exceptions import BadRequest
99
from plexapi.mixins import (
1010
AdvancedSettingsMixin, SplitMergeMixin, UnmatchMatchMixin, ExtrasMixin, HubsMixin, PlayedUnplayedMixin, RatingMixin,
11-
ArtUrlMixin, ArtMixin, LogoMixin, PosterUrlMixin, PosterMixin, ThemeUrlMixin, ThemeMixin,
11+
ArtUrlMixin, ArtMixin, LogoMixin, PosterUrlMixin, PosterMixin, SquareArtMixin, ThemeUrlMixin, ThemeMixin,
1212
MovieEditMixins, ShowEditMixins, SeasonEditMixins, EpisodeEditMixins,
1313
WatchlistMixin
1414
)
@@ -338,7 +338,7 @@ def sync(self, videoQuality, client=None, clientId=None, limit=None, unwatched=F
338338
class Movie(
339339
Video, Playable,
340340
AdvancedSettingsMixin, SplitMergeMixin, UnmatchMatchMixin, ExtrasMixin, HubsMixin, RatingMixin,
341-
ArtMixin, LogoMixin, PosterMixin, ThemeMixin,
341+
ArtMixin, LogoMixin, PosterMixin, SquareArtMixin, ThemeMixin,
342342
MovieEditMixins,
343343
WatchlistMixin
344344
):
@@ -545,7 +545,7 @@ def metadataDirectory(self):
545545
class Show(
546546
Video,
547547
AdvancedSettingsMixin, SplitMergeMixin, UnmatchMatchMixin, ExtrasMixin, HubsMixin, RatingMixin,
548-
ArtMixin, LogoMixin, PosterMixin, ThemeMixin,
548+
ArtMixin, LogoMixin, PosterMixin, SquareArtMixin, ThemeMixin,
549549
ShowEditMixins,
550550
WatchlistMixin
551551
):
@@ -792,7 +792,7 @@ def metadataDirectory(self):
792792
class Season(
793793
Video,
794794
AdvancedSettingsMixin, ExtrasMixin, RatingMixin,
795-
ArtMixin, LogoMixin, PosterMixin, ThemeUrlMixin,
795+
ArtMixin, LogoMixin, PosterMixin, SquareArtMixin, ThemeUrlMixin,
796796
SeasonEditMixins
797797
):
798798
""" Represents a single Season.
@@ -974,7 +974,7 @@ def metadataDirectory(self):
974974
class Episode(
975975
Video, Playable,
976976
ExtrasMixin, RatingMixin,
977-
ArtMixin, LogoMixin, PosterMixin, ThemeUrlMixin,
977+
ArtMixin, LogoMixin, PosterMixin, SquareArtMixin, ThemeUrlMixin,
978978
EpisodeEditMixins
979979
):
980980
""" Represents a single Episode.

0 commit comments

Comments
 (0)