#13 filter by original language

pull/30/head
meisnate12 4 years ago
parent 9314417ce4
commit 3b14ad0ae8

@ -640,10 +640,12 @@ class Config:
final_filter = filter final_filter = filter
if final_filter in util.movie_only_filters and library.is_show: if final_filter in util.movie_only_filters and library.is_show:
logger.error("Collection Error: {} filter only works for movie libraries".format(final_filter)) logger.error("Collection Error: {} filter only works for movie libraries".format(final_filter))
elif collections[c][m][filter] is None:
logger.error("Collection Error: {} filter is blank".format(final_filter))
elif final_filter in util.all_filters: elif final_filter in util.all_filters:
filters.append((final_filter, collections[c][m][filter])) filters.append((final_filter, collections[c][m][filter]))
else: else:
logger.error("Collection Error: {} filter not supported".format(filter)) logger.error("Collection Error: {} filter not supported".format(final_filter))
elif method_name == "plex_collectionless": elif method_name == "plex_collectionless":
new_dictionary = {} new_dictionary = {}
@ -940,24 +942,33 @@ class Config:
elif "trakt" in method: items_found += check_map(self.Trakt.get_items(method, value, library.is_movie)) elif "trakt" in method: items_found += check_map(self.Trakt.get_items(method, value, library.is_movie))
else: logger.error("Collection Error: {} method not supported".format(method)) else: logger.error("Collection Error: {} method not supported".format(method))
if len(items) > 0: map = library.add_to_collection(collection_obj if collection_obj else collection_name, items, filters, map=map) if len(items) > 0: map = library.add_to_collection(collection_obj if collection_obj else collection_name, items, filters, map, movie_map, show_map)
else: logger.error("No items found to add to this collection ") else: logger.error("No items found to add to this collection ")
if len(missing_movies) > 0 or len(missing_shows) > 0: if len(missing_movies) > 0 or len(missing_shows) > 0:
logger.info("") logger.info("")
if len(missing_movies) > 0: if len(missing_movies) > 0:
if "original_language" in filters:
terms = filters["original_language"] if isinstance(filters["original_language"], list) else [lang.lower() for lang in str(filters["original_language"]).split(", ")]
not_lang = False
if "original_language.not" in filters:
terms = filters["original_language.not"] if isinstance(filters["original_language.not"], list) else [lang.lower() for lang in str(filters["original_language.not"]).split(", ")]
not_lang = True
missing_movies_with_names = [] missing_movies_with_names = []
for missing_id in missing_movies: for missing_id in missing_movies:
try: try:
title = str(self.TMDb.get_movie(missing_id).title) movie = self.TMDb.get_movie(missing_id)
if (not_lang is True and movie.original_language not in terms) or (not_lang is False and movie.original_language in terms):
title = str(movie.title)
missing_movies_with_names.append((title, missing_id)) missing_movies_with_names.append((title, missing_id))
logger.info("{} Collection | ? | {} (TMDb: {})".format(collection_name, title, missing_id)) logger.info("{} Collection | ? | {} (TMDb: {})".format(collection_name, title, missing_id))
except Failed as e: except Failed as e:
logger.error(e) logger.error(e)
logger.info("{} Movie{} Missing".format(len(missing_movies), "s" if len(missing_movies) > 1 else "")) logger.info("{} Movie{} Missing".format(len(missing_movies_with_names), "s" if len(missing_movies_with_names) > 1 else ""))
library.save_missing(collection_name, missing_movies_with_names, True) library.save_missing(collection_name, missing_movies_with_names, True)
if do_arr and library.Radarr: if do_arr and library.Radarr:
library.Radarr.add_tmdb(missing_movies) library.Radarr.add_tmdb([missing_id for title, missing_id in missing_movies_with_names])
if len(missing_shows) > 0 and library.is_show: if len(missing_shows) > 0 and library.is_show:
missing_shows_with_names = [] missing_shows_with_names = []
for missing_id in missing_shows: for missing_id in missing_shows:

@ -68,6 +68,8 @@ class PlexAPI:
except Failed as e: logger.error(e) except Failed as e: logger.error(e)
logger.info("{} library's Tautulli Connection {}".format(params["name"], "Failed" if self.Tautulli is None else "Successful")) logger.info("{} library's Tautulli Connection {}".format(params["name"], "Failed" if self.Tautulli is None else "Successful"))
self.TMDb = params["tmdb"]
self.TVDb = params["tvdb"]
self.name = params["name"] self.name = params["name"]
self.missing_path = os.path.join(os.path.dirname(os.path.abspath(params["metadata_path"])), "{}_missing.yml".format(os.path.splitext(os.path.basename(params["metadata_path"]))[0])) self.missing_path = os.path.join(os.path.dirname(os.path.abspath(params["metadata_path"])), "{}_missing.yml".format(os.path.splitext(os.path.basename(params["metadata_path"]))[0]))
@ -160,7 +162,7 @@ class PlexAPI:
except yaml.scanner.ScannerError as e: except yaml.scanner.ScannerError as e:
logger.error("YAML Error: {}".format(str(e).replace("\n", "\n|\t "))) logger.error("YAML Error: {}".format(str(e).replace("\n", "\n|\t ")))
def add_to_collection(self, collection, items, filters, map={}): def add_to_collection(self, collection, items, filters, map, movie_map, show_map):
name = collection.title if isinstance(collection, Collections) else collection name = collection.title if isinstance(collection, Collections) else collection
collection_items = collection.items() if isinstance(collection, Collections) else [] collection_items = collection.items() if isinstance(collection, Collections) else []
total = len(items) total = len(items)
@ -181,6 +183,23 @@ class PlexAPI:
if attr is None or attr < threshold_date: if attr is None or attr < threshold_date:
match = False match = False
break break
elif method == "original_language":
terms = f[1] if isinstance(f[1], list) else [lang.lower() for lang in str(f[1]).split(", ")]
tmdb_id = None
movie = None
for key, value in movie_map.items():
if current.ratingKey == value:
try:
movie = self.TMDb.get_movie(key)
break
except Failed:
pass
if movie is None:
logger.warning("Filter Error: No TMDb ID found for {}".format(current.title))
continue
if (modifier == ".not" and movie.original_language in terms) or (modifier != ".not" and movie.original_language not in terms):
match = False
break
elif modifier in [".gte", ".lte"]: elif modifier in [".gte", ".lte"]:
if method == "originallyAvailableAt": if method == "originallyAvailableAt":
threshold_date = datetime.strptime(f[1], "%m/%d/%y") threshold_date = datetime.strptime(f[1], "%m/%d/%y")

@ -43,6 +43,7 @@ filter_alias = {
"genre": "genres", "genre": "genres",
"max_age": "max_age", "max_age": "max_age",
"originally_available": "originallyAvailableAt", "originally_available": "originallyAvailableAt",
"original_language": "original_language",
"rating": "rating", "rating": "rating",
"studio": "studio", "studio": "studio",
"subtitle_language": "subtitle_language", "subtitle_language": "subtitle_language",
@ -361,6 +362,7 @@ all_filters = [
"genre", "genre.not", "genre", "genre.not",
"max_age", "max_age",
"originally_available.gte", "originally_available.lte", "originally_available.gte", "originally_available.lte",
"original_language", "original_language.not",
"rating.gte", "rating.lte", "rating.gte", "rating.lte",
"studio", "studio.not", "studio", "studio.not",
"subtitle_language", "subtitle_language.not", "subtitle_language", "subtitle_language.not",
@ -372,6 +374,7 @@ movie_only_filters = [
"audio_language", "audio_language.not", "audio_language", "audio_language.not",
"country", "country.not", "country", "country.not",
"director", "director.not", "director", "director.not",
"original_language", "original_language.not",
"subtitle_language", "subtitle_language.not", "subtitle_language", "subtitle_language.not",
"video_resolution", "video_resolution.not", "video_resolution", "video_resolution.not",
"writer", "writer.not" "writer", "writer.not"

Loading…
Cancel
Save