Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add producers, roles, and hasCommercialMarker to Episode objects #797

Merged
merged 3 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plexapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,12 @@ def __repr__(self):
name = self._clean(self.firstAttr('type'))
start = utils.millisecondToHumanstr(self._clean(self.firstAttr('start')))
end = utils.millisecondToHumanstr(self._clean(self.firstAttr('end')))
return '<%s:%s %s - %s>' % (self.__class__.__name__, name, start, end)
offsets = '%s-%s' % (start, end)
return '<%s>' % ':'.join([self.__class__.__name__, name, offsets])

def _loadData(self, data):
self._data = data
self.id = utils.cast(int, data.attrib.get('id'))
self.type = data.attrib.get('type')
self.start = utils.cast(int, data.attrib.get('startTimeOffset'))
self.end = utils.cast(int, data.attrib.get('endTimeOffset'))
Expand Down
14 changes: 14 additions & 0 deletions plexapi/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,9 @@ class Episode(Video, Playable, ArtMixin, PosterMixin, RatingMixin,
parentThumb (str): URL to season thumbnail image (/library/metadata/<parentRatingKey>/thumb/<thumbid>).
parentTitle (str): Name of the season for the episode.
parentYear (int): Year the season was released.
producers (List<:class:`~plexapi.media.Producer`>): List of producers objects.
rating (float): Episode rating (7.9; 9.8; 8.1).
roles (List<:class:`~plexapi.media.Role`>): List of role objects.
skipParent (bool): True if the show's seasons are set to hidden.
viewOffset (int): View offset in milliseconds.
writers (List<:class:`~plexapi.media.Writer`>): List of writers objects.
Expand Down Expand Up @@ -809,7 +811,9 @@ def _loadData(self, data):
self.parentThumb = data.attrib.get('parentThumb')
self.parentTitle = data.attrib.get('parentTitle')
self.parentYear = utils.cast(int, data.attrib.get('parentYear'))
self.producers = self.findItems(data, media.Producer)
self.rating = utils.cast(float, data.attrib.get('rating'))
self.roles = self.findItems(data, media.Role)
self.skipParent = utils.cast(bool, data.attrib.get('skipParent', '0'))
self.viewOffset = utils.cast(int, data.attrib.get('viewOffset', 0))
self.writers = self.findItems(data, media.Writer)
Expand Down Expand Up @@ -838,6 +842,11 @@ def _prettyfilename(self):
""" Returns a human friendly filename. """
return '%s.%s' % (self.grandparentTitle.replace(' ', '.'), self.seasonEpisode)

@property
def actors(self):
""" Alias to self.roles. """
return self.roles

@property
def locations(self):
""" This does not exist in plex xml response but is added to have a common
Expand Down Expand Up @@ -865,6 +874,11 @@ def seasonEpisode(self):
""" Returns the s00e00 string containing the season and episode numbers. """
return 's%se%s' % (str(self.seasonNumber).zfill(2), str(self.episodeNumber).zfill(2))

@property
def hasCommercialMarker(self):
""" Returns True if the episode has a commercial marker in the xml. """
return any(marker.type == 'commercial' for marker in self.markers)

@property
def hasIntroMarker(self):
""" Returns True if the episode has an intro marker in the xml. """
Expand Down
5 changes: 5 additions & 0 deletions tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,13 @@ def test_video_Episode_attrs(episode):
assert utils.is_thumb(episode.parentThumb)
assert episode.parentTitle == "Season 1"
assert episode.parentYear is None
if episode.producers:
assert episode.producers # Test episode doesn't have producers
assert episode.rating is None
assert utils.is_int(episode.ratingKey)
if episode.roles:
assert "Jason Momoa" in [i.tag for i in episode.roles]
assert episode.actors == episode.roles
assert episode._server._baseurl == utils.SERVER_BASEURL
assert episode.skipParent is False
assert utils.is_string(episode.summary, gte=100)
Expand Down