From 264361f839e2891288759cb5ecf7301d69acfea5 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Mon, 15 Feb 2021 23:54:47 -0500 Subject: [PATCH] small fixes --- modules/config.py | 52 ++++++++++++++++++++++++----------------------- modules/plex.py | 4 ++-- modules/tests.py | 6 ++---- modules/util.py | 7 ++++--- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/modules/config.py b/modules/config.py index 3c7027af..4047658d 100644 --- a/modules/config.py +++ b/modules/config.py @@ -971,7 +971,7 @@ class Config: terms = None for filter_method, filter_data in filters: if filter_method.startswith("original_language"): - terms = filter_data if isinstance(filter_data, list) else [lang.strip().lower() for lang in str(filter_data).split(",")] + terms = util.get_list(filter_data, lower=True) not_lang = filter_method.endswith(".not") break @@ -1076,33 +1076,34 @@ class Config: if library.asset_directory: path = os.path.join(library.asset_directory, "{}".format(name_mapping)) - dirs = [folder for folder in os.listdir(path) if os.path.isdir(os.path.join(path, folder))] - if len(dirs) > 0: - for item in plex_collection.items(): - folder = os.path.basename(os.path.dirname(item.locations[0])) - if folder in dirs: - files = [file for file in os.listdir(os.path.join(path, folder)) if os.path.isfile(os.path.join(path, folder, file))] - poster_path = None - background_path = None - for file in files: - if poster_path is None and file.startswith("poster."): - poster_path = os.path.join(path, folder, file) - if background_path is None and file.startswith("background."): - background_path = os.path.join(path, folder, file) - if poster_path: - item.uploadPoster(filepath=poster_path) - logger.info("Detail: asset_directory updated {}'s poster to [file] {}".format(item.title, poster_path)) - if background_path: - item.uploadArt(filepath=background_path) - logger.info("Detail: asset_directory updated {}'s background to [file] {}".format(item.title, background_path)) - if poster_path is None and background_path is None: - logger.warning("No Files Found: {}".format(os.path.join(path, folder))) - else: - logger.warning("No Folder: {}".format(os.path.join(path, folder))) + if os.path.isdir(path): + dirs = [folder for folder in os.listdir(path) if os.path.isdir(os.path.join(path, folder))] + if len(dirs) > 0: + for item in plex_collection.items(): + folder = os.path.basename(os.path.dirname(item.locations[0])) + if folder in dirs: + files = [file for file in os.listdir(os.path.join(path, folder)) if os.path.isfile(os.path.join(path, folder, file))] + poster_path = None + background_path = None + for file in files: + if poster_path is None and file.startswith("poster."): + poster_path = os.path.join(path, folder, file) + if background_path is None and file.startswith("background."): + background_path = os.path.join(path, folder, file) + if poster_path: + item.uploadPoster(filepath=poster_path) + logger.info("Detail: asset_directory updated {}'s poster to [file] {}".format(item.title, poster_path)) + if background_path: + item.uploadArt(filepath=background_path) + logger.info("Detail: asset_directory updated {}'s background to [file] {}".format(item.title, background_path)) + if poster_path is None and background_path is None: + logger.warning("No Files Found: {}".format(os.path.join(path, folder))) + else: + logger.warning("No Folder: {}".format(os.path.join(path, folder))) except Exception as e: util.print_stacktrace() logger.error("Unknown Error: {}".format(e)) - if library.show_unmanaged is True: + if library.show_unmanaged is True and not test: logger.info("") util.seperator("Unmanaged Collections in {} Library".format(library.name)) logger.info("") @@ -1114,6 +1115,7 @@ class Config: unmanaged_count += 1 logger.info("{} Unmanaged Collections".format(unmanaged_count)) else: + logger.info("") logger.error("No collection to update") def map_guids(self, library): diff --git a/modules/plex.py b/modules/plex.py index 929ffad2..4075b91f 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -187,7 +187,7 @@ class PlexAPI: match = False break elif method == "original_language": - terms = f[1] if isinstance(f[1], list) else [lang.lower() for lang in str(f[1]).split(", ")] + terms = util.get_list(f[1], lower=True) tmdb_id = None movie = None for key, value in movie_map.items(): @@ -216,7 +216,7 @@ class PlexAPI: match = False break else: - terms = f[1] if isinstance(f[1], list) else str(f[1]).split(", ") + terms = util.get_list(f[1]) if method in ["video_resolution", "audio_language", "subtitle_language"]: for media in current.media: if method == "video_resolution": attrs = [media.videoResolution] diff --git a/modules/tests.py b/modules/tests.py index 156d0c9a..cf7ed4ef 100644 --- a/modules/tests.py +++ b/modules/tests.py @@ -10,10 +10,8 @@ def run_tests(default_dir): config = Config(default_dir) logger.info("") util.seperator("Mapping Tests") - - config.map_guids(config.libraries[0]) - config.map_guids(config.libraries[1]) - config.map_guids(config.libraries[2]) + for library in config.libraries: + config.map_guids(library) anidb_tests(config) imdb_tests(config) mal_tests(config) diff --git a/modules/util.py b/modules/util.py index f830934a..8b09d751 100644 --- a/modules/util.py +++ b/modules/util.py @@ -254,7 +254,7 @@ collectionless_lists = [ other_attributes = [ "schedule", "sync_mode", - "test", + "test", "tmdb_person" ] dictionary_lists = [ @@ -481,10 +481,11 @@ def choose_from_list(datalist, description, data=None, list_type="title", exact= else: return None -def get_list(data): +def get_list(data, lower=False): if isinstance(data, list): return data elif isinstance(data, dict): return [data] - else: return str(data).split(", ") + elif lower is True: return [d.strip().lower() for d in str(data).split(",")] + else: return [d.strip() for d in str(data).split(",")] def get_int_list(data, id_type): values = get_list(data)