mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 14:14:19 +00:00
Merge pull request #657 from JonnyWong16/feature/hidden_season
Fix episode parentKey and parentRatingKey when seasons are hidden in Plex
This commit is contained in:
commit
2be946c207
3 changed files with 31 additions and 0 deletions
|
@ -47,6 +47,7 @@ class PlexObject(object):
|
|||
self._data = data
|
||||
self._initpath = initpath or self.key
|
||||
self._parent = weakref.ref(parent) if parent else None
|
||||
self._details_key = None
|
||||
if data is not None:
|
||||
self._loadData(data)
|
||||
self._details_key = self._buildDetailsKey()
|
||||
|
|
|
@ -739,6 +739,7 @@ class Episode(Playable, Video, DirectorMixin, EditWriter):
|
|||
parentThumb (str): URL to season thumbnail image (/library/metadata/<parentRatingKey>/thumb/<thumbid>).
|
||||
parentTitle (str): Name of the season for the episode.
|
||||
rating (float): Episode rating (7.9; 9.8; 8.1).
|
||||
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.
|
||||
year (int): Year episode was released.
|
||||
|
@ -775,10 +776,23 @@ class Episode(Playable, Video, DirectorMixin, EditWriter):
|
|||
self.parentThumb = data.attrib.get('parentThumb')
|
||||
self.parentTitle = data.attrib.get('parentTitle')
|
||||
self.rating = utils.cast(float, data.attrib.get('rating'))
|
||||
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)
|
||||
self.year = utils.cast(int, data.attrib.get('year'))
|
||||
|
||||
# If seasons are hidden, parentKey and parentRatingKey are missing from the XML response.
|
||||
# https://forums.plex.tv/t/parentratingkey-not-in-episode-xml-when-seasons-are-hidden/300553
|
||||
if self.skipParent and not self.parentRatingKey:
|
||||
# Parse the parentRatingKey from the parentThumb
|
||||
if self.parentThumb.startswith('/library/metadata/'):
|
||||
self.parentRatingKey = utils.cast(int, self.parentThumb.split('/')[3])
|
||||
# Get the parentRatingKey from the season's ratingKey
|
||||
if not self.parentRatingKey and self.grandparentRatingKey:
|
||||
self.parentRatingKey = self.show().season(season=self.parentIndex).ratingKey
|
||||
if self.parentRatingKey:
|
||||
self.parentKey = '/library/metadata/%s' % self.parentRatingKey
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s>' % ':'.join([p for p in [
|
||||
self.__class__.__name__,
|
||||
|
|
|
@ -744,6 +744,21 @@ def test_video_Episode_history(episode):
|
|||
episode.markUnwatched()
|
||||
|
||||
|
||||
def test_video_Episode_hidden_season(episode):
|
||||
assert episode.skipParent is False
|
||||
assert episode.parentRatingKey
|
||||
assert episode.parentKey
|
||||
assert episode.seasonNumber
|
||||
show = episode.show()
|
||||
show.editAdvanced(flattenSeasons=1)
|
||||
episode.reload()
|
||||
assert episode.skipParent is True
|
||||
assert episode.parentRatingKey
|
||||
assert episode.parentKey
|
||||
assert episode.seasonNumber
|
||||
show.defaultAdvanced()
|
||||
|
||||
|
||||
# Analyze seems to fail intermittently
|
||||
@pytest.mark.xfail
|
||||
def test_video_Episode_analyze(tvshows):
|
||||
|
@ -770,6 +785,7 @@ def test_video_Episode_attrs(episode):
|
|||
assert episode.rating >= 7.7
|
||||
assert utils.is_int(episode.ratingKey)
|
||||
assert episode._server._baseurl == utils.SERVER_BASEURL
|
||||
assert episode.skipParent is False
|
||||
assert utils.is_string(episode.summary, gte=100)
|
||||
assert utils.is_metadata(episode.thumb, contains="/thumb/")
|
||||
assert episode.title == "Winter Is Coming"
|
||||
|
|
Loading…
Reference in a new issue