From 8ee383cd3dad0749919ab57bc82080e30009b227 Mon Sep 17 00:00:00 2001 From: blacktwin Date: Wed, 9 Oct 2019 10:44:51 -0400 Subject: [PATCH 1/7] create poster object in media --- plexapi/media.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plexapi/media.py b/plexapi/media.py index bf8ca2b98..6f1770d7e 100644 --- a/plexapi/media.py +++ b/plexapi/media.py @@ -467,6 +467,23 @@ class Mood(MediaTag): FILTER = 'mood' +@utils.registerPlexObject +class Poster(PlexObject): + """ Represents a Poster. + + Attributes: + TAG (str): 'Poster' + """ + TAG = 'Poster' + + def _loadData(self, data): + self._data = data + self.key = data.attrib.get('key') + self.ratingKey = data.attrib.get('ratingKey') + self.selected = data.attrib.get('selected') + self.thumb = data.attrib.get('thumb') + + @utils.registerPlexObject class Producer(MediaTag): """ Represents a single Producer media tag. From c857feb52c6991a08bd9101252be6159c7092f4a Mon Sep 17 00:00:00 2001 From: blacktwin Date: Wed, 9 Oct 2019 10:45:48 -0400 Subject: [PATCH 2/7] add _posters function and poster attribute to video class docstring updated --- plexapi/video.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plexapi/video.py b/plexapi/video.py index 008ef5c4d..9ebaf7d20 100644 --- a/plexapi/video.py +++ b/plexapi/video.py @@ -24,6 +24,7 @@ class Video(PlexPartialObject): type (str): 'artist', 'album', or 'track'. updatedAt (datatime): Datetime this item was updated. viewCount (int): Count of times this item was accessed. + posters (List<:class:`~plexapi.media.Poster`>): List of poster objects. """ def _loadData(self, data): @@ -42,6 +43,7 @@ def _loadData(self, data): self.type = data.attrib.get('type') self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt')) self.viewCount = utils.cast(int, data.attrib.get('viewCount', 0)) + self.posters = self._posters() @property def isWatched(self): @@ -89,6 +91,14 @@ def _defaultSyncTitle(self): """ Returns str, default title for a new syncItem. """ return self.title + def _posters(self): + """ Returns list of available poster objects. :class:`~plexapi.media.Poster`:""" + items = [] + for elem in self._server.query('%s/posters' % self.key): + items.append(media.Poster(server=self._server, data=elem)) + + return items + def sync(self, videoQuality, client=None, clientId=None, limit=None, unwatched=False, title=None): """ Add current video (movie, tv-show, season or episode) as sync item for specified device. See :func:`plexapi.myplex.MyPlexAccount.sync()` for possible exceptions. From 9416bcbfaf955987b737622c4896fbb0d63acc9b Mon Sep 17 00:00:00 2001 From: blacktwin Date: Wed, 9 Oct 2019 10:48:21 -0400 Subject: [PATCH 3/7] add poster check in test_video_Movie_attrs --- tests/test_video.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_video.py b/tests/test_video.py index 627a8c8e5..8f177bbac 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -101,6 +101,7 @@ def test_video_Movie_attrs(movies): assert [i.tag for i in movie.directors] == ['Nina Paley'] assert movie.duration >= 160000 assert movie.fields == [] + assert movie.posters assert sorted([i.tag for i in movie.genres]) == ['Animation', 'Comedy', 'Fantasy', 'Musical', 'Romance'] assert movie.guid == 'com.plexapp.agents.imdb://tt1172203?lang=en' assert utils.is_metadata(movie._initpath) From 76f77a554e02001367f13104dbe9c3fe89772d93 Mon Sep 17 00:00:00 2001 From: blacktwin Date: Sat, 12 Oct 2019 14:48:02 -0400 Subject: [PATCH 4/7] Comment corrections remove attribute and rename function --- plexapi/video.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plexapi/video.py b/plexapi/video.py index 9ebaf7d20..20ea93598 100644 --- a/plexapi/video.py +++ b/plexapi/video.py @@ -24,7 +24,6 @@ class Video(PlexPartialObject): type (str): 'artist', 'album', or 'track'. updatedAt (datatime): Datetime this item was updated. viewCount (int): Count of times this item was accessed. - posters (List<:class:`~plexapi.media.Poster`>): List of poster objects. """ def _loadData(self, data): @@ -43,7 +42,6 @@ def _loadData(self, data): self.type = data.attrib.get('type') self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt')) self.viewCount = utils.cast(int, data.attrib.get('viewCount', 0)) - self.posters = self._posters() @property def isWatched(self): @@ -91,7 +89,7 @@ def _defaultSyncTitle(self): """ Returns str, default title for a new syncItem. """ return self.title - def _posters(self): + def posters(self): """ Returns list of available poster objects. :class:`~plexapi.media.Poster`:""" items = [] for elem in self._server.query('%s/posters' % self.key): From 9f7127753026b409217663d91631dbfa0cbb7ac6 Mon Sep 17 00:00:00 2001 From: blacktwin Date: Sat, 12 Oct 2019 14:49:18 -0400 Subject: [PATCH 5/7] Comment corrections Test updated for function instead of attribute. --- tests/test_video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_video.py b/tests/test_video.py index 8f177bbac..a838ee817 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -101,7 +101,7 @@ def test_video_Movie_attrs(movies): assert [i.tag for i in movie.directors] == ['Nina Paley'] assert movie.duration >= 160000 assert movie.fields == [] - assert movie.posters + assert movie.posters() assert sorted([i.tag for i in movie.genres]) == ['Animation', 'Comedy', 'Fantasy', 'Musical', 'Romance'] assert movie.guid == 'com.plexapp.agents.imdb://tt1172203?lang=en' assert utils.is_metadata(movie._initpath) From e62dff0a09048eedaf34e97b7b7e75b8d64a7099 Mon Sep 17 00:00:00 2001 From: blacktwin Date: Wed, 6 Nov 2019 09:28:19 -0500 Subject: [PATCH 6/7] Correct Poster TAG --- plexapi/media.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plexapi/media.py b/plexapi/media.py index 6f1770d7e..cf1685aed 100644 --- a/plexapi/media.py +++ b/plexapi/media.py @@ -472,9 +472,9 @@ class Poster(PlexObject): """ Represents a Poster. Attributes: - TAG (str): 'Poster' + TAG (str): 'Photo' """ - TAG = 'Poster' + TAG = 'Photo' def _loadData(self, data): self._data = data From be09f44ae3b467e34a098267e89cb34cb0de91d6 Mon Sep 17 00:00:00 2001 From: blacktwin Date: Wed, 6 Nov 2019 09:28:56 -0500 Subject: [PATCH 7/7] Fix posters function based on PR comment --- plexapi/video.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plexapi/video.py b/plexapi/video.py index 20ea93598..fe0442181 100644 --- a/plexapi/video.py +++ b/plexapi/video.py @@ -91,11 +91,8 @@ def _defaultSyncTitle(self): def posters(self): """ Returns list of available poster objects. :class:`~plexapi.media.Poster`:""" - items = [] - for elem in self._server.query('%s/posters' % self.key): - items.append(media.Poster(server=self._server, data=elem)) - return items + return self.fetchItems('%s/posters' % self.key, cls=media.Poster) def sync(self, videoQuality, client=None, clientId=None, limit=None, unwatched=False, title=None): """ Add current video (movie, tv-show, season or episode) as sync item for specified device.