Skip to content

Allow exclude parameters in reload kwargs #1378

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

Merged
merged 2 commits into from
Mar 16, 2024
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
27 changes: 21 additions & 6 deletions plexapi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,22 @@ def _buildDetailsKey(self, **kwargs):
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):
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down