Skip to content

Commit 2c540f6

Browse files
authored
Add producers, roles, and hasCommercialMarker to Episode objects (#797)
* Add producers and roles to Episode * Add producers and roles to episode test * Add hasCommercialMarker to Episode
1 parent 05f625f commit 2c540f6

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

plexapi/media.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,12 @@ def __repr__(self):
964964
name = self._clean(self.firstAttr('type'))
965965
start = utils.millisecondToHumanstr(self._clean(self.firstAttr('start')))
966966
end = utils.millisecondToHumanstr(self._clean(self.firstAttr('end')))
967-
return '<%s:%s %s - %s>' % (self.__class__.__name__, name, start, end)
967+
offsets = '%s-%s' % (start, end)
968+
return '<%s>' % ':'.join([self.__class__.__name__, name, offsets])
968969

969970
def _loadData(self, data):
970971
self._data = data
972+
self.id = utils.cast(int, data.attrib.get('id'))
971973
self.type = data.attrib.get('type')
972974
self.start = utils.cast(int, data.attrib.get('startTimeOffset'))
973975
self.end = utils.cast(int, data.attrib.get('endTimeOffset'))

plexapi/video.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,9 @@ class Episode(Video, Playable, ArtMixin, PosterMixin, RatingMixin,
767767
parentThumb (str): URL to season thumbnail image (/library/metadata/<parentRatingKey>/thumb/<thumbid>).
768768
parentTitle (str): Name of the season for the episode.
769769
parentYear (int): Year the season was released.
770+
producers (List<:class:`~plexapi.media.Producer`>): List of producers objects.
770771
rating (float): Episode rating (7.9; 9.8; 8.1).
772+
roles (List<:class:`~plexapi.media.Role`>): List of role objects.
771773
skipParent (bool): True if the show's seasons are set to hidden.
772774
viewOffset (int): View offset in milliseconds.
773775
writers (List<:class:`~plexapi.media.Writer`>): List of writers objects.
@@ -809,7 +811,9 @@ def _loadData(self, data):
809811
self.parentThumb = data.attrib.get('parentThumb')
810812
self.parentTitle = data.attrib.get('parentTitle')
811813
self.parentYear = utils.cast(int, data.attrib.get('parentYear'))
814+
self.producers = self.findItems(data, media.Producer)
812815
self.rating = utils.cast(float, data.attrib.get('rating'))
816+
self.roles = self.findItems(data, media.Role)
813817
self.skipParent = utils.cast(bool, data.attrib.get('skipParent', '0'))
814818
self.viewOffset = utils.cast(int, data.attrib.get('viewOffset', 0))
815819
self.writers = self.findItems(data, media.Writer)
@@ -838,6 +842,11 @@ def _prettyfilename(self):
838842
""" Returns a human friendly filename. """
839843
return '%s.%s' % (self.grandparentTitle.replace(' ', '.'), self.seasonEpisode)
840844

845+
@property
846+
def actors(self):
847+
""" Alias to self.roles. """
848+
return self.roles
849+
841850
@property
842851
def locations(self):
843852
""" This does not exist in plex xml response but is added to have a common
@@ -865,6 +874,11 @@ def seasonEpisode(self):
865874
""" Returns the s00e00 string containing the season and episode numbers. """
866875
return 's%se%s' % (str(self.seasonNumber).zfill(2), str(self.episodeNumber).zfill(2))
867876

877+
@property
878+
def hasCommercialMarker(self):
879+
""" Returns True if the episode has a commercial marker in the xml. """
880+
return any(marker.type == 'commercial' for marker in self.markers)
881+
868882
@property
869883
def hasIntroMarker(self):
870884
""" Returns True if the episode has an intro marker in the xml. """

tests/test_video.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,13 @@ def test_video_Episode_attrs(episode):
10161016
assert utils.is_thumb(episode.parentThumb)
10171017
assert episode.parentTitle == "Season 1"
10181018
assert episode.parentYear is None
1019+
if episode.producers:
1020+
assert episode.producers # Test episode doesn't have producers
10191021
assert episode.rating is None
10201022
assert utils.is_int(episode.ratingKey)
1023+
if episode.roles:
1024+
assert "Jason Momoa" in [i.tag for i in episode.roles]
1025+
assert episode.actors == episode.roles
10211026
assert episode._server._baseurl == utils.SERVER_BASEURL
10221027
assert episode.skipParent is False
10231028
assert utils.is_string(episode.summary, gte=100)

0 commit comments

Comments
 (0)