Skip to content

Commit 6d600fe

Browse files
author
Touchstone64
committed
Implement the key-building mixin for all parent/child retrieval methods
1 parent ba913e5 commit 6d600fe

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

plexapi/video.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def season(self, title=None, season=None):
710710
Raises:
711711
:exc:`~plexapi.exceptions.BadRequest`: If title or season parameter is missing.
712712
"""
713-
key = f'{self.key}/children?excludeAllLeaves=1&includeGuids=1'
713+
key = self._buildRelationKey(f'{self.key}/children)', excludeAllLeaves=1)
714714
if title is not None and not isinstance(title, int):
715715
return self.fetchItem(key, Season, title__iexact=title)
716716
elif season is not None or isinstance(title, int):
@@ -723,7 +723,7 @@ def season(self, title=None, season=None):
723723

724724
def seasons(self, **kwargs):
725725
""" Returns a list of :class:`~plexapi.video.Season` objects in the show. """
726-
key = f'{self.key}/children?excludeAllLeaves=1&includeGuids=1'
726+
key = self._buildRelationKey(f'{self.key}/children', excludeAllLeaves=1)
727727
return self.fetchItems(key, Season, container_size=self.childCount, **kwargs)
728728

729729
def episode(self, title=None, season=None, episode=None):
@@ -737,7 +737,7 @@ def episode(self, title=None, season=None, episode=None):
737737
Raises:
738738
:exc:`~plexapi.exceptions.BadRequest`: If title or season and episode parameters are missing.
739739
"""
740-
key = f'{self.key}/allLeaves?includeGuids=1'
740+
key = self._buildRelationKey(f'{self.key}/allLeaves')
741741
if title is not None:
742742
return self.fetchItem(key, Episode, title__iexact=title)
743743
elif season is not None and episode is not None:
@@ -746,7 +746,7 @@ def episode(self, title=None, season=None, episode=None):
746746

747747
def episodes(self, **kwargs):
748748
""" Returns a list of :class:`~plexapi.video.Episode` objects in the show. """
749-
key = f'{self.key}/allLeaves?includeGuids=1'
749+
key = self._buildRelationKey(f'{self.key}/allLeaves')
750750
return self.fetchItems(key, Episode, **kwargs)
751751

752752
def get(self, title=None, season=None, episode=None):
@@ -906,7 +906,7 @@ def episode(self, title=None, episode=None):
906906
Raises:
907907
:exc:`~plexapi.exceptions.BadRequest`: If title or episode parameter is missing.
908908
"""
909-
key = f'{self.key}/children?includeGuids=1'
909+
key = self._buildRelationKey(f'{self.key}/children')
910910
if title is not None and not isinstance(title, int):
911911
return self.fetchItem(key, Episode, title__iexact=title)
912912
elif episode is not None or isinstance(title, int):
@@ -919,7 +919,7 @@ def episode(self, title=None, episode=None):
919919

920920
def episodes(self, **kwargs):
921921
""" Returns a list of :class:`~plexapi.video.Episode` objects in the season. """
922-
key = f'{self.key}/children'
922+
key = self._buildRelationKey(f'{self.key}/children')
923923
return self.fetchItems(key, Episode, **kwargs)
924924

925925
def get(self, title=None, episode=None):
@@ -928,7 +928,7 @@ def get(self, title=None, episode=None):
928928

929929
def show(self):
930930
""" Return the season's :class:`~plexapi.video.Show`. """
931-
return self.fetchItem(self.parentKey)
931+
return self.fetchItem(self._buildRelationKey(self.parentKey))
932932

933933
def watched(self):
934934
""" Returns list of watched :class:`~plexapi.video.Episode` objects. """
@@ -1136,7 +1136,12 @@ def parentThumb(self):
11361136
def _season(self):
11371137
""" Returns the :class:`~plexapi.video.Season` object by querying for the show's children. """
11381138
if self.grandparentKey and self.parentIndex is not None:
1139-
return self.fetchItem(f'{self.grandparentKey}/children?excludeAllLeaves=1&index={self.parentIndex}')
1139+
key = f'{self.grandparentKey}/children'
1140+
params = {
1141+
'excludeAllLeaves': 1,
1142+
'index': self.parentIndex
1143+
}
1144+
return self.fetchItem(self._buildRelationKey(key, params))
11401145
return None
11411146

11421147
def __repr__(self):
@@ -1213,11 +1218,11 @@ def hasPreviewThumbnails(self):
12131218

12141219
def season(self):
12151220
"""" Return the episode's :class:`~plexapi.video.Season`. """
1216-
return self.fetchItem(self.parentKey)
1221+
return self.fetchItem(self._buildRelationKey(self.parentKey))
12171222

12181223
def show(self):
12191224
"""" Return the episode's :class:`~plexapi.video.Show`. """
1220-
return self.fetchItem(self.grandparentKey)
1225+
return self.fetchItem(self._buildRelationKey(self.grandparentKey))
12211226

12221227
def _defaultSyncTitle(self):
12231228
""" Returns str, default title for a new syncItem. """

0 commit comments

Comments
 (0)