-
Notifications
You must be signed in to change notification settings - Fork 201
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
having trouble with searching using filter! #595
Comments
What did you expect to see by appending |
I expect to see the inverse search i.e.
this is what i expect to see whereas with most of the filters it just returns all movies instead of the inverse i.e.
In LibrarySection.search is says "**kwargs (dict) – Any of the available filters for the current library section. Partial string matches allowed. Multiple matches OR together. Negative filtering also possible, just add an exclamation mark to the end of filter name, e.g. resolution!=1x1." |
print(len(plex.library.section('Movies').all()))
print(len(plex.library.section('Movies').search(**{'studio': 'Pixar'})))
print(len(plex.library.section('Movies').search(**{'studio!': 'Pixar'})))
1163
10
1153 PlexAPI version 4.1.2 |
yes studio and year work correctly but all the other i tested do not |
try it with an actor, country, writer, director, or genre |
also i just tried network and network! for tv libraries and neither filter worked they both just returned my entire library no matter what i set their values too |
Can you edit this area, to this: def _cleanSearchFilter(self, category, value, libtype=None):
# check a few things before we begin
categories = [x.key for x in self.filterFields()]
booleanFilters = [x.key for x in self.filterFields() if x.type == 'boolean']
if category.endswith('!'):
if category[:-1] not in categories:
raise BadRequest('Unknown filter category: %s' % category[:-1])
category = category[:-1] # <--- add this line
elif category not in categories:
raise BadRequest('Unknown filter category: %s' % category)
if category in booleanFilters:
return '1' if value else '0'
if not isinstance(value, (list, tuple)):
value = [value] Then run your tests again. Let me know. |
when i use
but not when i use network also on the LibrarySection.search it does say that network is a valid tv filter and studio is not for tv. In fact, it says studio is for music even though I've confirmed it works for movies ill try and update the code and get back to you shortly |
my api version is 4.1.2 and I'm not sure how to test your change i edited the library.py file that was in pythons library but I don't think the change was actually being used since non of my prints were working either |
With edit: print(len(plex.library.section('Movies').all()))
def test(filters):
print(str(filters) + ": " + str(len(plex.library.section('Movies').search(**filters))))
test({'actor': 'Will Smith'})
test({'actor!': 'Will Smith'})
test({'country': 'USA'})
test({'country!': 'USA'})
test({'director': 'Steven Spielberg'})
test({'director!': 'Steven Spielberg'})
test({'genre': 'Romance'})
test({'genre!': 'Romance'})
test({'genre': 'Comedy'})
test({'genre!': 'Comedy'})
test({'studio': 'Pixar'})
test({'studio!': 'Pixar'})
test({'year': '1990'})
test({'year!': '1990'})
test({'writer': 'Quentin Tarantino'})
test({'writer!': 'Quentin Tarantino'}) Output
Without edit:
|
That's awesome looks like it's working! did you get a chance to look at network/studio search for tv libraries it was broke not only inversely but the normal one as far as I can tell. |
Network should not be a valid filter. You can see for yourself when filtering in the webUI. Pull out your browser Inspect tool and look at the network tab for the API call. There was a somewhat recent change to this project. The filters are no longer hard coded and instead pull from Plex. If Also, check out #402 |
I'm using 4.1.2 to be honest I'm not sure how to use your git version over what I installed with pip install I'm very new to python even if I'm not new to programming but it looks like you fixed the network problem before I even brought it up. I have to wait till the next release that I can pull with pip install but I'm glad these issues seemed to have been fixed. Do you have an idea of when the next release would be or is there any place i can check to see whne the next one is coming? |
You can try one of these. |
so I finally got this all working and yes adding print(len(plex.library.section('Movies').all()))
def test(filters):
print(str(filters) + ": " + str(len(plex.library.section('Movies').search(**filters))))
test({'show.genre': 'Romance'})
test({'show.genre!': 'Romance'})
test({'show.genre': 'Comedy'})
test({'show.genre!': 'Comedy'}) Output
|
|
my bad i ran it using my TV library when i was copy pasting into here i copied your code from earlier and forgot to change that to TV Shows lol but yea no problem im glad to help improve this where i can. If you need me to test any more just let me know |
Ok same area as before: def _cleanSearchFilter(self, category, value, libtype=None):
# check a few things before we begin
categories = [x.key for x in self.filterFields()]
booleanFilters = [x.key for x in self.filterFields() if x.type == 'boolean']
if category.endswith('!'):
if category[:-1] not in categories:
raise BadRequest('Unknown filter category: %s' % category[:-1])
category = category[:-1] # <--- add this line
elif category not in categories:
raise BadRequest('Unknown filter category: %s' % category)
if category in booleanFilters:
return '1' if value else '0'
if not isinstance(value, (list, tuple)):
value = [value]
# convert list of values to list of keys or ids
result = set()
category = category.split('.')[1] if '.' in category else category # <--- add this line
choices = self.listChoices(category, libtype)
lookup = {c.title.lower(): unquote(unquote(c.key)) for c in choices}
allowed = set(c.key for c in choices)
for item in value: .... def test(filters):
print(str(filters) + ": " + str(len(plex.library.section('TV Shows').search(**filters))))
test({'show.genre': 'Romance'})
test({'show.genre!': 'Romance'})
test({'show.genre': 'Comedy'})
test({'show.genre!': 'Comedy'}) output with edit:
I knew this seems familiar #392. Might be able to close two issues at once since the other issue was in regards to the |
yea that change fixed it for me and i didn't realize you could could use operators while fetching Items that going to be very useful to me in the future |
I've been using the fix here for a while but I just installed the new Beta version of Plex with the new TV Agent and it seems to have completely broken filters. The filterFields method under the class LibrarySection no longer returns any filters. The PlexAPI endpoint If I need to make a new issue I'm happy to. What the normal branch returns <?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="19" allowSync="0" art="/:/resources/movie-fanart.jpg" content="secondary" identifier="com.plexapp.plugins.library" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1614092584" thumb="/:/resources/movie.png" title1="Movies" viewGroup="secondary" viewMode="65592">
<Meta>
<Type key="/library/sections/18/all?type=1" type="movie" title="Movies" active="0">
<Filter filter="genre" filterType="string" key="/library/sections/18/genre" title="Genre" type="filter" />
<Filter filter="year" filterType="integer" key="/library/sections/18/year" title="Year" type="filter" />
<Filter filter="decade" filterType="integer" key="/library/sections/18/decade" title="Decade" type="filter" />
<Filter filter="contentRating" filterType="string" key="/library/sections/18/contentRating" title="Content Rating" type="filter" />
<Filter filter="collection" filterType="string" key="/library/sections/18/collection" title="Collection" type="filter" />
<Filter filter="director" filterType="string" key="/library/sections/18/director" title="Director" type="filter" />
<Filter filter="actor" filterType="string" key="/library/sections/18/actor" title="Actor" type="filter" />
<Filter filter="writer" filterType="string" key="/library/sections/18/writer" title="Writer" type="filter" />
<Filter filter="producer" filterType="string" key="/library/sections/18/producer" title="Producer" type="filter" />
<Filter filter="country" filterType="string" key="/library/sections/18/country" title="Country" type="filter" />
<Filter filter="studio" filterType="string" key="/library/sections/18/studio" title="Studio" type="filter" />
<Filter filter="resolution" filterType="string" key="/library/sections/18/resolution" title="Resolution" type="filter" />
<Filter filter="hdr" filterType="boolean" key="/library/sections/18/hdr" title="HDR" type="filter" />
<Filter filter="unwatched" filterType="boolean" key="/library/sections/18/unwatched" title="Unplayed" type="filter" />
<Filter filter="inProgress" filterType="boolean" key="/library/sections/18/inProgress" title="In Progress" type="filter" />
<Filter filter="unmatched" filterType="boolean" key="/library/sections/18/unmatched" title="Unmatched" type="filter" />
<Filter filter="audioLanguage" filterType="string" key="/library/sections/18/audioLanguage" title="Audio Language" type="filter" />
<Filter filter="subtitleLanguage" filterType="string" key="/library/sections/18/subtitleLanguage" title="Subtitle Language" type="filter" />
<Filter filter="label" filterType="string" key="/library/sections/18/label" title="Labels" type="filter" />
<Sort default="asc" defaultDirection="asc" descKey="titleSort:desc" firstCharacterKey="/library/sections/18/firstCharacter" key="titleSort" title="Title" />
<Sort defaultDirection="desc" descKey="originallyAvailableAt:desc" key="originallyAvailableAt" title="Release Date" />
<Sort defaultDirection="desc" descKey="rating:desc" key="rating" title="Critic Rating" />
<Sort defaultDirection="desc" descKey="audienceRating:desc" key="audienceRating" title="Audience Rating" />
<Sort defaultDirection="desc" descKey="duration:desc" key="duration" title="Duration" />
<Sort defaultDirection="desc" descKey="addedAt:desc" key="addedAt" title="Date Added" />
<Sort defaultDirection="desc" descKey="lastViewedAt:desc" key="lastViewedAt" title="Date Viewed" />
<Sort defaultDirection="asc" descKey="mediaHeight:desc" key="mediaHeight" title="Resolution" />
<Field key="title" title="Title" type="string" />
<Field key="studio" title="Studio" type="string" />
<Field key="userRating" subType="rating" title="Rating" type="integer" />
<Field key="contentRating" title="Content Rating" type="tag" />
<Field key="year" subType="year" title="Year" type="integer" />
<Field key="decade" subType="decade" title="Decade" type="integer" />
<Field key="originallyAvailableAt" title="Release Date" type="date" />
<Field key="duration" subType="duration" title="Duration" type="integer" />
<Field key="unmatched" title="Unmatched" type="boolean" />
<Field key="duplicate" title="Duplicate" type="boolean" />
<Field key="genre" title="Genre" type="tag" />
<Field key="collection" title="Collection" type="tag" />
<Field key="director" title="Director" type="tag" />
<Field key="writer" title="Writer" type="tag" />
<Field key="producer" title="Producer" type="tag" />
<Field key="actor" title="Actor" type="tag" />
<Field key="country" title="Country" type="tag" />
<Field key="addedAt" title="Date Added" type="date" />
<Field key="viewCount" title="Plays" type="integer" />
<Field key="lastViewedAt" title="Last Played" type="date" />
<Field key="unwatched" title="Unplayed" type="boolean" />
<Field key="resolution" title="Resolution" type="resolution" />
<Field key="hdr" subType="hdr" title="HDR" type="boolean" />
<Field key="mediaSize" subType="fileSize" title="File Size" type="integer" />
<Field key="mediaBitrate" subType="bitrate" title="Bitrate" type="integer" />
<Field key="subtitleLanguage" title="Subtitle Language" type="subtitleLanguage" />
<Field key="audioLanguage" title="Audio Language" type="audioLanguage" />
<Field key="inProgress" title="In Progress" type="boolean" />
<Field key="trash" title="Trash" type="boolean" />
<Field key="label" title="Label" type="tag" />
</Type>
<Type key="/library/sections/18/folder" type="folder" title="Folders" active="0">
</Type>
<FieldType type="tag">
<Operator key="=" title="is" />
<Operator key="!=" title="is not" />
</FieldType>
<FieldType type="integer">
<Operator key="=" title="is" />
<Operator key="!=" title="is not" />
<Operator key=">>=" title="is greater than" />
<Operator key="<<=" title="is less than" />
</FieldType>
<FieldType type="string">
<Operator key="=" title="contains" />
<Operator key="!=" title="does not contain" />
<Operator key="==" title="is" />
<Operator key="!==" title="is not" />
<Operator key="<=" title="begins with" />
<Operator key=">=" title="ends with" />
</FieldType>
<FieldType type="boolean">
<Operator key="=" title="is true" />
<Operator key="!=" title="is false" />
</FieldType>
<FieldType type="date">
<Operator key="<<=" title="is before" />
<Operator key=">>=" title="is after" />
</FieldType>
<FieldType type="subtitleLanguage">
<Operator key="=" title="is" />
<Operator key="!=" title="is not" />
</FieldType>
<FieldType type="audioLanguage">
<Operator key="=" title="is" />
<Operator key="!=" title="is not" />
</FieldType>
<FieldType type="resolution">
<Operator key="=" title="is" />
</FieldType>
</Meta>
<Directory filter="genre" filterType="string" key="/library/sections/18/genre" title="Genre" type="filter" />
<Directory filter="year" filterType="integer" key="/library/sections/18/year" title="Year" type="filter" />
<Directory filter="decade" filterType="integer" key="/library/sections/18/decade" title="Decade" type="filter" />
<Directory filter="contentRating" filterType="string" key="/library/sections/18/contentRating" title="Content Rating" type="filter" />
<Directory filter="collection" filterType="string" key="/library/sections/18/collection" title="Collection" type="filter" />
<Directory filter="director" filterType="string" key="/library/sections/18/director" title="Director" type="filter" />
<Directory filter="actor" filterType="string" key="/library/sections/18/actor" title="Actor" type="filter" />
<Directory filter="writer" filterType="string" key="/library/sections/18/writer" title="Writer" type="filter" />
<Directory filter="producer" filterType="string" key="/library/sections/18/producer" title="Producer" type="filter" />
<Directory filter="country" filterType="string" key="/library/sections/18/country" title="Country" type="filter" />
<Directory filter="studio" filterType="string" key="/library/sections/18/studio" title="Studio" type="filter" />
<Directory filter="resolution" filterType="string" key="/library/sections/18/resolution" title="Resolution" type="filter" />
<Directory filter="hdr" filterType="boolean" key="/library/sections/18/hdr" title="HDR" type="filter" />
<Directory filter="unwatched" filterType="boolean" key="/library/sections/18/unwatched" title="Unplayed" type="filter" />
<Directory filter="inProgress" filterType="boolean" key="/library/sections/18/inProgress" title="In Progress" type="filter" />
<Directory filter="unmatched" filterType="boolean" key="/library/sections/18/unmatched" title="Unmatched" type="filter" />
<Directory filter="audioLanguage" filterType="string" key="/library/sections/18/audioLanguage" title="Audio Language" type="filter" />
<Directory filter="subtitleLanguage" filterType="string" key="/library/sections/18/subtitleLanguage" title="Subtitle Language" type="filter" />
<Directory filter="label" filterType="string" key="/library/sections/18/label" title="Labels" type="filter" />
</MediaContainer> what the new endpoint returns <?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="19" allowSync="0" art="/:/resources/movie-fanart.jpg" content="secondary" identifier="com.plexapp.plugins.library" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1614701937" thumb="/:/resources/movie.png" title1="Movies" viewGroup="secondary" viewMode="65592">
<Directory filter="genre" filterType="string" key="/library/sections/18/genre" title="Genre" type="filter" />
<Directory filter="year" filterType="integer" key="/library/sections/18/year" title="Year" type="filter" />
<Directory filter="decade" filterType="integer" key="/library/sections/18/decade" title="Decade" type="filter" />
<Directory filter="contentRating" filterType="string" key="/library/sections/18/contentRating" title="Content Rating" type="filter" />
<Directory filter="collection" filterType="string" key="/library/sections/18/collection" title="Collection" type="filter" />
<Directory filter="director" filterType="string" key="/library/sections/18/director" title="Director" type="filter" />
<Directory filter="actor" filterType="string" key="/library/sections/18/actor" title="Actor" type="filter" />
<Directory filter="writer" filterType="string" key="/library/sections/18/writer" title="Writer" type="filter" />
<Directory filter="producer" filterType="string" key="/library/sections/18/producer" title="Producer" type="filter" />
<Directory filter="country" filterType="string" key="/library/sections/18/country" title="Country" type="filter" />
<Directory filter="studio" filterType="string" key="/library/sections/18/studio" title="Studio" type="filter" />
<Directory filter="resolution" filterType="string" key="/library/sections/18/resolution" title="Resolution" type="filter" />
<Directory filter="hdr" filterType="boolean" key="/library/sections/18/hdr" title="HDR" type="filter" />
<Directory filter="unwatched" filterType="boolean" key="/library/sections/18/unwatched" title="Unplayed" type="filter" />
<Directory filter="inProgress" filterType="boolean" key="/library/sections/18/inProgress" title="In Progress" type="filter" />
<Directory filter="unmatched" filterType="boolean" key="/library/sections/18/unmatched" title="Unmatched" type="filter" />
<Directory filter="audioLanguage" filterType="string" key="/library/sections/18/audioLanguage" title="Audio Language" type="filter" />
<Directory filter="subtitleLanguage" filterType="string" key="/library/sections/18/subtitleLanguage" title="Subtitle Language" type="filter" />
<Directory filter="label" filterType="string" key="/library/sections/18/label" title="Labels" type="filter" />
</MediaContainer>
|
I've confirmed this on my end as well. We'll have to see if this is only reflected in the Beta or will be present in the main release. Version 1.22.0.4136 to be specific. I'll have to update that key in that method from Can you confirm that this new key |
i do still have the current stable release up and yes switching the endpoint did still allow it to work in the current stable release |
fix confirmed working in previous stable version
I'm trying to use LibrarySection.search to search using ! in the search filter and when I add the ! after actor, country, director, genre, and writer no matter what value I give it, it just returns every movie in my library. studio! and year! seemed to work but i haven't tested any other filters other then the ones mentioned in this post. what i ran to test is belowis below
Output
Am i doing something wrong or is this feature not working correctly?
The text was updated successfully, but these errors were encountered: