Allow exclude parameters in reload kwargs (#1378)

* Allow exclude parameters in reload

* Add test for reload kwargs
This commit is contained in:
JonnyWong16 2024-03-16 15:18:14 -07:00 committed by GitHub
parent b494e8e2f1
commit 642ba8ba12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 6 deletions

View file

@ -116,14 +116,22 @@ class PlexObject:
or disable each parameter individually by setting it to False or 0.
"""
details_key = self.key
params = {}
if details_key and hasattr(self, '_INCLUDES'):
includes = {}
for k, v in self._INCLUDES.items():
value = kwargs.get(k, v)
value = kwargs.pop(k, v)
if value not in [False, 0, '0']:
includes[k] = 1 if value is True else value
if includes:
details_key += '?' + urlencode(sorted(includes.items()))
params[k] = 1 if value is True else value
if details_key and hasattr(self, '_EXCLUDES'):
for k, v in self._EXCLUDES.items():
value = kwargs.pop(k, None)
if value is not None:
params[k] = 1 if value is True else value
if params:
details_key += '?' + urlencode(sorted(params.items()))
return details_key
def _isChildOf(self, **kwargs):
@ -498,7 +506,14 @@ class PlexPartialObject(PlexObject):
'includeRelated': 1,
'includeRelatedCount': 1,
'includeReviews': 1,
'includeStations': 1
'includeStations': 1,
}
_EXCLUDES = {
'excludeElements': (
'Media,Genre,Country,Guid,Rating,Collection,Director,Writer,Role,Producer,Similar,Style,Mood,Format'
),
'excludeFields': 'summary,tagline',
'skipRefresh': 1,
}
def __eq__(self, other):

View file

@ -339,6 +339,14 @@ def test_video_Movie_isFullObject_and_reload(plex):
assert len(movie_via_section_search.roles) >= 3
def test_video_Movie_reload_kwargs(movie):
assert len(movie.media)
assert movie.summary is not None
movie.reload(includeFields=False, **movie._EXCLUDES)
assert movie.__dict__.get('media') == []
assert movie.__dict__.get('summary') is None
def test_video_movie_watched(movie):
movie.markUnplayed()
movie.markPlayed()