diff --git a/modules/builder.py b/modules/builder.py index 2bf5ba05..64fcd2ca 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -1631,24 +1631,11 @@ class CollectionBuilder: if "name_mapping" in self.details: if self.details["name_mapping"]: name_mapping = self.details["name_mapping"] else: logger.error("Collection Error: name_mapping attribute is blank") - for ad in self.library.asset_directory: - path = os.path.join(ad, f"{name_mapping}") - if self.library.asset_folders: - if not os.path.isdir(path): - continue - poster_filter = os.path.join(ad, name_mapping, "poster.*") - background_filter = os.path.join(ad, name_mapping, "background.*") - else: - poster_filter = os.path.join(ad, f"{name_mapping}.*") - background_filter = os.path.join(ad, f"{name_mapping}_background.*") - matches = glob.glob(poster_filter) - if len(matches) > 0: - self.posters["asset_directory"] = os.path.abspath(matches[0]) - matches = glob.glob(background_filter) - if len(matches) > 0: - self.backgrounds["asset_directory"] = os.path.abspath(matches[0]) - for item in self.library.query(self.obj.items): - self.library.update_item_from_assets(item, dirs=[path]) + poster_image, background_image = self.library.update_item_from_assets(self.obj, collection_mode=True, upload=False, name=name_mapping) + if poster_image: + self.posters["asset_directory"] = poster_image + if background_image: + self.backgrounds["asset_directory"] = background_image def set_image(image_method, images, is_background=False): message = f"{'background' if is_background else 'poster'} to [{'File' if image_method in image_file_details else 'URL'}] {images[image_method]}" diff --git a/modules/plex.py b/modules/plex.py index 103df525..0c86be7f 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -574,7 +574,7 @@ class PlexAPI: if search_limit: logger.info(f"\t\t LIMIT {search_limit})") logger.debug(f"Search: {search_terms}") - return self.search(sort=sorts[search_sort], maxresults=search_limit, **search_terms) + items = self.search(sort=sorts[search_sort], maxresults=search_limit, **search_terms) elif method == "plex_collectionless": good_collections = [] logger.info("Collections Excluded") @@ -615,7 +615,7 @@ class PlexAPI: else: raise Failed(f"Plex Error: Method {method} not supported") if len(items) > 0: - return items + return [item.ratingKey for item in items] else: raise Failed("Plex Error: No Items found in Plex") @@ -664,11 +664,16 @@ class PlexAPI: util.print_stacktrace() logger.error(f"{item_type}: {name}{' Advanced' if advanced else ''} Details Update Failed") - def update_item_from_assets(self, item, dirs=None): + def update_item_from_assets(self, item, collection_mode=False, upload=True, dirs=None, name=None): if dirs is None: dirs = self.asset_directory - name = os.path.basename(os.path.dirname(item.locations[0]) if self.is_movie else item.locations[0]) + if not name and collection_mode: + name = item.title + elif not name: + name = os.path.basename(os.path.dirname(item.locations[0]) if self.is_movie else item.locations[0]) for ad in dirs: + poster_image = None + background_image = None if self.asset_folders: if not os.path.isdir(os.path.join(ad, name)): continue @@ -679,13 +684,22 @@ class PlexAPI: background_filter = os.path.join(ad, f"{name}_background.*") matches = glob.glob(poster_filter) if len(matches) > 0: - self.upload_image(item, os.path.abspath(matches[0]), url=False) - logger.info(f"Detail: asset_directory updated {item.title}'s poster to [file] {os.path.abspath(matches[0])}") + poster_image = os.path.abspath(matches[0]) + if upload: + self.upload_image(item, poster_image, url=False) + logger.info(f"Detail: asset_directory updated {item.title}'s poster to [file] {poster_image}") matches = glob.glob(background_filter) if len(matches) > 0: - self.upload_image(item, os.path.abspath(matches[0]), poster=False, url=False) - logger.info(f"Detail: asset_directory updated {item.title}'s background to [file] {os.path.abspath(matches[0])}") - if self.is_show: + background_image = os.path.abspath(matches[0]) + if upload: + self.upload_image(item, background_image, poster=False, url=False) + logger.info(f"Detail: asset_directory updated {item.title}'s background to [file] {background_image}") + if collection_mode: + for ite in self.query(item.items): + self.update_item_from_assets(ite, dirs=[os.path.join(ad, name)]) + if not upload: + return poster_image, background_image + if self.is_show and not collection_mode: for season in self.query(item.seasons): if self.asset_folders: season_filter = os.path.join(ad, name, f"Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}.*") diff --git a/plex_meta_manager.py b/plex_meta_manager.py index c9b2230d..38274753 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -141,24 +141,30 @@ def update_libraries(config, is_test, requested_collections, resume_from): if collections_to_run and not library_only: resume_from = run_collection(config, library, metadata, collections_to_run, is_test, resume_from, movie_map, show_map) - if library.show_unmanaged is True and not is_test and not requested_collections and not library_only: - logger.info("") - util.separator(f"Unmanaged Collections in {library.name} Library") - logger.info("") - unmanaged_count = 0 - collections_in_plex = [str(plex_col) for plex_col in library.collections] + if not is_test and not requested_collections: + unmanaged_collections = [] for col in library.get_all_collections(): - if col.title not in collections_in_plex: + if col.title not in library.collections: + unmanaged_collections.append(col) + + if library.show_unmanaged and not library_only: + logger.info("") + util.separator(f"Unmanaged Collections in {library.name} Library") + logger.info("") + for col in unmanaged_collections: logger.info(col.title) - unmanaged_count += 1 - logger.info("{} Unmanaged Collections".format(unmanaged_count)) + logger.info(f"{len(unmanaged_collections)} Unmanaged Collections") + + if library.assets_for_all and not collection_only: + logger.info("") + util.separator(f"All {'Movies' if library.is_movie else 'Shows'} Assets Check for {library.name} Library") + logger.info("") + for col in unmanaged_collections: + library.update_item_from_assets(col, collection_mode=True) + for item in library.get_all(): + library.update_item_from_assets(item) + - if library.assets_for_all is True and not is_test and not requested_collections and not collection_only: - logger.info("") - util.separator(f"All {'Movies' if library.is_movie else 'Shows'} Assets Check for {library.name} Library") - logger.info("") - for item in library.get_all(): - library.update_item_from_assets(item) has_run_again = False for library in config.libraries: if library.run_again: