fix for filter validate

This commit is contained in:
meisnate12 2021-06-15 23:20:45 -04:00
parent 6d2a34ac65
commit 63b48e928d
2 changed files with 16 additions and 21 deletions

View file

@ -1304,13 +1304,21 @@ class CollectionBuilder:
final_values.append(value)
else:
final_values = util.get_list(data)
try:
return self.library.validate_search_list(final_values, attribute, title=not pairs, pairs=pairs)
except Failed as e:
if validate:
raise
search_choices = self.library.get_search_choices(attribute, title=not pairs)
valid_list = []
for value in final_values:
if str(value).lower() in search_choices:
if pairs:
valid_list.append((value, search_choices[str(value).lower()]))
else:
valid_list.append(search_choices[str(value).lower()])
else:
logger.error(e)
error = f"Plex Error: {attribute}: {value} not found"
if validate:
raise Failed(error)
else:
logger.error(error)
return valid_list
elif attribute in ["year", "episode_year"] and modifier in [".gt", ".gte", ".lt", ".lte"]:#
return util.check_year(data, self.current_year, final)
elif attribute in plex.date_attributes and modifier in [".before", ".after"]:#

View file

@ -474,9 +474,10 @@ class Plex:
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed)
def get_search_choices(self, search_name, title=True):
final_search = search_translation[search_name] if search_name in search_translation else search_name
try:
choices = {}
for choice in self.Plex.listFilterChoices(search_name):
for choice in self.Plex.listFilterChoices(final_search):
choices[choice.title.lower()] = choice.title if title else choice.key
choices[choice.key.lower()] = choice.title if title else choice.key
return choices
@ -538,20 +539,6 @@ class Plex:
smart_filter = self.get_collection(collection)._data.attrib.get('content')
return smart_filter[smart_filter.index("?"):]
def validate_search_list(self, data, search_name, title=True, pairs=False):
final_search = search_translation[search_name] if search_name in search_translation else search_name
search_choices = self.get_search_choices(final_search, title=title)
valid_list = []
for value in util.get_list(data):
if str(value).lower() in search_choices:
if pairs:
valid_list.append((value, search_choices[str(value).lower()]))
else:
valid_list.append(search_choices[str(value).lower()])
else:
raise Failed(f"Plex Error: {search_name}: {value} not found")
return valid_list
def get_collection(self, data):
if isinstance(data, int):
collection = self.fetchItem(data)