Skip to content
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

Add support for 'group' and 'having' keys in smart filters #1286

Merged
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
9 changes: 7 additions & 2 deletions plexapi/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,9 @@ def _manualFields(self):
('id', 'integer', 'Rating Key'),
('index', 'integer', f'{self.type.capitalize()} Number'),
('lastRatedAt', 'date', f'{self.type.capitalize()} Last Rated'),
('updatedAt', 'date', 'Date Updated')
('updatedAt', 'date', 'Date Updated'),
('group', 'string', 'SQL Group By Statement'),
('having', 'string', 'SQL Having Clause')
]

if self.type == 'movie':
Expand Down Expand Up @@ -2778,11 +2780,14 @@ def _manualFields(self):

manualFields = []
for field, fieldType, fieldTitle in additionalFields:
if field not in {'group', 'having'}:
field = f"{prefix}{field}"
fieldXML = (
f'<Field key="{prefix}{field}" '
f'<Field key="{field}" '
f'title="{fieldTitle}" '
f'type="{fieldType}"/>'
)

manualFields.append(self._manuallyLoadXML(fieldXML, FilteringField))

return manualFields
Expand Down
5 changes: 4 additions & 1 deletion plexapi/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ def _parseQueryFeed(self, feed: "deque[Tuple[str, str]]") -> dict:
filtersDict = {}
special_keys = {"type", "sort"}
integer_keys = {"includeGuids", "limit"}
reserved_keys = special_keys | integer_keys
as_is_keys = {"group", "having"}
reserved_keys = special_keys | integer_keys | as_is_keys
while feed:
key, value = feed.popleft()
if key in integer_keys:
filtersDict[key] = int(value)
elif key in as_is_keys:
filtersDict[key] = value
elif key == "type":
filtersDict["libtype"] = utils.reverseSearchType(value)
elif key == "sort":
Expand Down