fix for filter validate

pull/309/head
meisnate12 4 years ago
parent 6d2a34ac65
commit 63b48e928d

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

@ -474,9 +474,10 @@ class Plex:
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed) @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): 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: try:
choices = {} 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.title.lower()] = choice.title if title else choice.key
choices[choice.key.lower()] = choice.title if title else choice.key choices[choice.key.lower()] = choice.title if title else choice.key
return choices return choices
@ -538,20 +539,6 @@ class Plex:
smart_filter = self.get_collection(collection)._data.attrib.get('content') smart_filter = self.get_collection(collection)._data.attrib.get('content')
return smart_filter[smart_filter.index("?"):] 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): def get_collection(self, data):
if isinstance(data, int): if isinstance(data, int):
collection = self.fetchItem(data) collection = self.fetchItem(data)

Loading…
Cancel
Save