add filter method

pull/282/head
meisnate12 4 years ago
parent 19c3e170db
commit 98f6f6d95b

@ -1377,9 +1377,24 @@ class CollectionBuilder:
except (BadRequest, NotFound): except (BadRequest, NotFound):
logger.error(f"Plex Error: Item {item} not found") logger.error(f"Plex Error: Item {item} not found")
continue continue
match = True if self.check_filters(current, f"{(' ' * (max_length - len(str(i))))}{i}/{total}"):
logger.info(util.adjust_space(f"{name} Collection | {'=' if current in collection_items else '+'} | {current.title}"))
if current in collection_items:
self.plex_map[current.ratingKey] = None
elif self.smart_label_collection:
self.library.query_data(current.addLabel, name)
else:
self.library.query_data(current.addCollection, name)
elif self.details["show_filtered"] is True:
logger.info(f"{name} Collection | X | {current.title}")
media_type = f"{'Movie' if self.library.is_movie else 'Show'}{'s' if total > 1 else ''}"
util.print_end()
logger.info("")
logger.info(f"{total} {media_type} Processed")
def check_filters(self, current, display):
if self.filters: if self.filters:
util.print_return(f"Filtering {(' ' * (max_length - len(str(i)))) + str(i)}/{total} {current.title}") util.print_return(f"Filtering {display} {current.title}")
for filter_method, filter_data in self.filters: for filter_method, filter_data in self.filters:
modifier = filter_method[-4:] modifier = filter_method[-4:]
method = filter_method[:-4] if modifier in [".not", ".lte", ".gte"] else filter_method method = filter_method[:-4] if modifier in [".not", ".lte", ".gte"] else filter_method
@ -1387,8 +1402,7 @@ class CollectionBuilder:
if method_name == "max_age": if method_name == "max_age":
threshold_date = datetime.now() - timedelta(days=filter_data) threshold_date = datetime.now() - timedelta(days=filter_data)
if current.originallyAvailableAt is None or current.originallyAvailableAt < threshold_date: if current.originallyAvailableAt is None or current.originallyAvailableAt < threshold_date:
match = False return False
break
elif method_name == "original_language": elif method_name == "original_language":
movie = None movie = None
for key, value in self.library.movie_map.items(): for key, value in self.library.movie_map.items():
@ -1401,10 +1415,8 @@ class CollectionBuilder:
if movie is None: if movie is None:
logger.warning(f"Filter Error: No TMDb ID found for {current.title}") logger.warning(f"Filter Error: No TMDb ID found for {current.title}")
continue continue
if (modifier == ".not" and movie.original_language in filter_data) \ if (modifier == ".not" and movie.original_language in filter_data) or (modifier != ".not" and movie.original_language not in filter_data):
or (modifier != ".not" and movie.original_language not in filter_data): return False
match = False
break
elif method_name == "audio_track_title": elif method_name == "audio_track_title":
jailbreak = False jailbreak = False
for media in current.media: for media in current.media:
@ -1419,8 +1431,7 @@ class CollectionBuilder:
if jailbreak: break if jailbreak: break
if jailbreak: break if jailbreak: break
if (jailbreak and modifier == ".not") or (not jailbreak and modifier != ".not"): if (jailbreak and modifier == ".not") or (not jailbreak and modifier != ".not"):
match = False return False
break
elif method_name == "filepath": elif method_name == "filepath":
jailbreak = False jailbreak = False
for location in current.locations: for location in current.locations:
@ -1430,15 +1441,15 @@ class CollectionBuilder:
break break
if jailbreak: break if jailbreak: break
if (jailbreak and modifier == ".not") or (not jailbreak and modifier != ".not"): if (jailbreak and modifier == ".not") or (not jailbreak and modifier != ".not"):
match = False return False
break
elif modifier in [".gte", ".lte"]: elif modifier in [".gte", ".lte"]:
if method_name == "vote_count": if method_name == "vote_count":
tmdb_item = None tmdb_item = None
for key, value in self.library.movie_map.items(): for key, value in self.library.movie_map.items():
if current.ratingKey in value: if current.ratingKey in value:
try: try:
tmdb_item = self.config.TMDb.get_movie(key) if self.library.is_movie else self.config.TMDb.get_show(key) tmdb_item = self.config.TMDb.get_movie(
key) if self.library.is_movie else self.config.TMDb.get_show(key)
break break
except Failed: except Failed:
pass pass
@ -1449,8 +1460,7 @@ class CollectionBuilder:
else: else:
attr = getattr(current, method_name) / 60000 if method_name == "duration" else getattr(current, method_name) attr = getattr(current, method_name) / 60000 if method_name == "duration" else getattr(current, method_name)
if attr is None or (modifier == ".lte" and attr > filter_data) or (modifier == ".gte" and attr < filter_data): if attr is None or (modifier == ".lte" and attr > filter_data) or (modifier == ".gte" and attr < filter_data):
match = False return False
break
else: else:
attrs = [] attrs = []
if method_name in ["video_resolution", "audio_language", "subtitle_language"]: if method_name in ["video_resolution", "audio_language", "subtitle_language"]:
@ -1469,25 +1479,10 @@ class CollectionBuilder:
else: else:
raise Failed(f"Filter Error: filter: {method_name} not supported") raise Failed(f"Filter Error: filter: {method_name} not supported")
if (not list(set(filter_data) & set(attrs)) and modifier != ".not")\ if (not list(set(filter_data) & set(attrs)) and modifier != ".not") or (list(set(filter_data) & set(attrs)) and modifier == ".not"):
or (list(set(filter_data) & set(attrs)) and modifier == ".not"): return False
match = False util.print_return(f"Filtering {display} {current.title}")
break return True
util.print_return(f"Filtering {(' ' * (max_length - len(str(i)))) + str(i)}/{total} {current.title}")
if match:
logger.info(util.adjust_space(f"{name} Collection | {'=' if current in collection_items else '+'} | {current.title}"))
if current in collection_items:
self.plex_map[current.ratingKey] = None
elif self.smart_label_collection:
self.library.query_data(current.addLabel, name)
else:
self.library.query_data(current.addCollection, name)
elif self.details["show_filtered"] is True:
logger.info(f"{name} Collection | X | {current.title}")
media_type = f"{'Movie' if self.library.is_movie else 'Show'}{'s' if total > 1 else ''}"
util.print_end()
logger.info("")
logger.info(f"{total} {media_type} Processed")
def run_missing(self): def run_missing(self):
arr_filters = [] arr_filters = []

Loading…
Cancel
Save