Repository navigation
Description
Describe the issue
The _include parameters when retrieving XML data from Plex should be configurable. It would allow the user to save resources and speed up the response by only retrieving the XML tags/fields that they need.
Example hardcoded _include parameters for ~plexapi.video.Movie:
https://github.com/pkkid/python-plexapi/blob/163d94d2492e976841f4d7b011cbdef1d849e53e/plexapi/video.py#L289-L291
This is especially useful for the checkFiles=1 parameter since this causes the Plex server to hit the storage to check if a file exists (~plexapi.media.MediaPart.exists) and is accessible (~plexapi.media.MediaPart.accessible) which may timeout if cloud storage is being used for the Plex server.
Code snipppets
Example of an unnecessary "heavy" reload.
from plexapi.server import PlexServer
plex = PlexServer('http://localhost:32400', token='xxxxxxxxxxxxxxxxxxxx')
for movie in plex.library.section("Movies").all():
# This will trigger an automatic reload() of every movie with checkFiles=1
# even though the exists/accessible values are not needed
print(movie.subtitleStreams())Expected behavior
Example of a possible "lighter" reload.
from plexapi.server import PlexServer
plex = PlexServer('http://localhost:32400', token='xxxxxxxxxxxxxxxxxxxx')
for movie in plex.library.section("Movies").all():
# Manual reload() without checkFiles
movie.reload(checkFiles=False)
print(movie.subtitleStreams())Additional context
Some other XML includes that are available but not shown when viewing the XML through Plex.
includeFields=thumbBlurHashadds thethumbBlurHashfield to the XML (used by Plexamp)includeFields=artBlurHashadds theartBlurHashfield to the XML (used by Plexamp)
Reference: BlurHash.
Activity
Hellowlol commentedon Nov 21, 2020
This behavior is intentional. Accessing a attribute that isn’t included should trigger a reload with the most possible info.
There are ways to avoid doing heavy reloads.
JonnyWong16 commentedon Nov 21, 2020
It can still be the default behaviour, but having the includes as customizable parameters is more user friendly.
I am just using
subtitleStreams()as an example because that is something that cannot be retrieved from/library/sections/<sectionID>/all.kwargsthat can return subtitle streams usingall().search()would only work if you want to filter bysubtitleLanguagebecause that is the only available filter built into Plex (Search Improvements #598). Searching for anything else likesubtitleCodecwill not work.blacktwin commentedon Nov 21, 2020
#590 moved the child _include into the parent video class. We could use this single reference to break out params into the known kwargs for reload().
_include is only used to populate _details_keys, so why don't we move these params to reload()
Allow customizing XML includes when reloading
Allow customizing XML includes when reloading
Allow customizing XML includes when reloading
JonnyWong16 commentedon Nov 21, 2020
I don't think we should have all the includes in
reload(). They should remain with the object that it is relevant to. Also,includeFieldscan have a string value mentioned above instead of the typical integer1.Here is my first pass at customizing includes: JonnyWong16@c171aa2.
Hellowlol commentedon Nov 21, 2020
The same can be done today by using str.replace on the details key. I actually thought about that when I did the changes. I think your approach is better.
Open a PR. We also need to change the way we check if the object is full.
JonnyWong16 commentedon Nov 21, 2020
Do we need to change how we check if it is a full object? The object has been loaded from the API path (details key). Unless you want "full" to mean it has all the include parameters.
Hellowlol commentedon Nov 21, 2020
Full should be all params yes. It will only reload on missing attributes anyway.