diff --git a/README.md b/README.md index f8df5672..ff559bb3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Plex Meta Manager +#### Version 1.0.1 The original concept for Plex Meta Manager is [Plex Auto Collections](https://github.com/mza921/Plex-Auto-Collections), but this is rewritten from the ground up to be able to include a scheduler, metadata edits, multiple libraries, and logging. Plex Meta Manager is a Python 3 script that can be continuously run using YAML configuration files to update on a schedule the metadata of the movies, shows, and collections in your libraries as well as automatically build collections based on various methods all detailed in the wiki. Some collection examples that the script can automatically build and update daily include Plex Based Searches like actor, genre, or studio collections or Collections based on TMDb, IMDb, Trakt, TVDb, AniDB, or MyAnimeList lists and various other services. diff --git a/config/config.yml.template b/config/config.yml.template index 021603ac..1e90c918 100644 --- a/config/config.yml.template +++ b/config/config.yml.template @@ -13,6 +13,7 @@ plex: # Can be individually specified pe token: #################### sync_mode: append asset_directory: config/assets + show_unmanaged_collections: true radarr: # Can be individually specified per library as well url: http://192.168.1.12:7878 token: ################################ diff --git a/modules/config.py b/modules/config.py index a9ebe94c..3cbcce8f 100644 --- a/modules/config.py +++ b/modules/config.py @@ -142,6 +142,7 @@ class Config: self.general["plex"]["token"] = check_for_attribute(self.data, "token", parent="plex", default_is_none=True) if "plex" in self.data else None self.general["plex"]["asset_directory"] = check_for_attribute(self.data, "asset_directory", parent="plex", var_type="path", default=os.path.join(default_dir, "assets")) if "plex" in self.data else os.path.join(default_dir, "assets") self.general["plex"]["sync_mode"] = check_for_attribute(self.data, "sync_mode", parent="plex", default="append", test_list=["append", "sync"], options="| \tappend (Only Add Items to the Collection)\n| \tsync (Add & Remove Items from the Collection)") if "plex" in self.data else "append" + self.general["plex"]["show_unmanaged_collections"] = check_for_attribute(self.data, "show_unmanaged_collections", parent="plex", var_type="bool", default=True) if "plex" in self.data else True self.general["radarr"] = {} self.general["radarr"]["url"] = check_for_attribute(self.data, "url", parent="radarr", default_is_none=True) if "radarr" in self.data else None @@ -239,6 +240,16 @@ class Config: else: logger.warning("Config Warning: sync_mode attribute is blank using general value: {}".format(self.general["plex"]["sync_mode"])) + params["show_unmanaged_collections"] = self.general["plex"]["show_unmanaged_collections"] + if "plex" in libs[lib] and "show_unmanaged_collections" in libs[lib]["plex"]: + if libs[lib]["plex"]["show_unmanaged_collections"]: + if isinstance(libs[lib]["plex"]["show_unmanaged_collections"], bool): + params["plex"]["show_unmanaged_collections"] = libs[lib]["plex"]["show_unmanaged_collections"] + else: + logger.warning("Config Warning: plex sub-attribute show_unmanaged_collections must be either true or false using general value: {}".format(self.general["plex"]["show_unmanaged_collections"])) + else: + logger.warning("Config Warning: radarr sub-attribute add is blank using general value: {}".format(self.general["radarr"]["add"])) + params["tmdb"] = self.TMDb params["tvdb"] = self.TVDb @@ -533,6 +544,8 @@ class Config: logger.info("Collection Error: {} skipped. MyAnimeList must be configured".format(m)) map = {} elif collections[c][m] is not None: + logger.debug("Method: {}".format(m)) + logger.debug("Value: {}".format(collections[c][m])) if m in util.method_alias: method_name = util.method_alias[m] logger.warning("Collection Warning: {} attribute will run as {}".format(m, method_name)) @@ -843,8 +856,11 @@ class Config: library.clear_collection_missing(collection_name) for method, values in methods: + logger.debug("Method: {}".format(method)) + logger.debug("Values: {}".format(values)) pretty = util.pretty_names[method] if method in util.pretty_names else method for value in values: + logger.debug("Value: {}".format(value)) items = [] missing_movies = [] missing_shows = [] @@ -986,10 +1002,10 @@ class Config: edits["summary.value"] = details["summary"] edits["summary.locked"] = 1 if len(edits) > 0: + logger.debug(edits) plex_collection.edit(**edits) plex_collection.reload() logger.info("Details: have been updated") - logger.debug(edits) if "collection_mode" in details: plex_collection.modeUpdate(mode=details["collection_mode"]) if "collection_order" in details: @@ -1027,17 +1043,17 @@ class Config: except Exception as e: util.print_stacktrace() logger.error("Unknown Error: {}".format(e)) - - logger.info("") - util.seperator("Unmanaged Collections in {} Library".format(library.name)) - logger.info("") - unmanaged_count = 0 - collections_in_plex = [str(pcol) for pcol in collections] - for col in library.get_all_collections(): - if col.title not in collections_in_plex: - logger.info(col.title) - unmanaged_count += 1 - logger.info("{} Unmanaged Collections".format(unmanaged_count)) + if library.show_unmanaged_collections is True: + logger.info("") + util.seperator("Unmanaged Collections in {} Library".format(library.name)) + logger.info("") + unmanaged_count = 0 + collections_in_plex = [str(pcol) for pcol in collections] + for col in library.get_all_collections(): + if col.title not in collections_in_plex: + logger.info(col.title) + unmanaged_count += 1 + logger.info("{} Unmanaged Collections".format(unmanaged_count)) else: logger.error("No collection to update") diff --git a/modules/plex.py b/modules/plex.py index d4c0c827..d366bc8e 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -74,6 +74,7 @@ class PlexAPI: self.metadata_path = params["metadata_path"] self.asset_directory = params["asset_directory"] self.sync_mode = params["sync_mode"] + self.show_unmanaged_collections = params["show_unmanaged_collections"] self.plex = params["plex"] self.radarr = params["radarr"] self.sonarr = params["sonarr"] @@ -293,7 +294,10 @@ class PlexAPI: add_edit("originally_available", str(item.originallyAvailableAt)[:-9], self.metadata[m], key="originallyAvailableAt", value=originally_available) add_edit("rating", item.rating, self.metadata[m], value=rating) add_edit("content_rating", item.contentRating, self.metadata[m], key="contentRating") - add_edit("original_title", item.originalTitle, self.metadata[m], key="originalTitle", value=original_title) + if self.is_movie: + add_edit("original_title", item.originalTitle, self.metadata[m], key="originalTitle", value=original_title) + elif "original_title" in self.metadata[m]: + logger.error("Metadata Error: original_title does not work with shows") add_edit("studio", item.studio, self.metadata[m], value=studio) add_edit("tagline", item.tagline, self.metadata[m], value=tagline) add_edit("summary", item.summary, self.metadata[m], value=summary) diff --git a/modules/radarr.py b/modules/radarr.py index 2434a9d8..a0257edf 100644 --- a/modules/radarr.py +++ b/modules/radarr.py @@ -67,7 +67,7 @@ class RadarrAPI: "title": movie.title, "{}".format("qualityProfileId" if self.version == "v3" else "profileId"): self.quality_profile_id, "year": int(year), - "tmdbid": str(tmdb_id), + "tmdbid": int(tmdb_id), "titleslug": titleslug, "monitored": True, "rootFolderPath": self.root_folder_path, @@ -79,7 +79,11 @@ class RadarrAPI: logger.info("Added to Radarr | {:<6} | {}".format(tmdb_id, movie.title)) add_count += 1 else: - logger.error("Radarr Error: ({}) {}: ({}) {}".format(tmdb_id, movie.title, response.status_code, response.json()[0]["errorMessage"])) + try: + logger.error("Radarr Error: ({}) {}: ({}) {}".format(tmdb_id, movie.title, response.status_code, response.json()[0]["errorMessage"])) + except KeyError as e: + logger.debug(url_json) + logger.error("Radarr Error: {}".format(response.json())) logger.info("{} Movie{} added to Radarr".format(add_count, "s" if add_count > 1 else "")) @retry(stop_max_attempt_number=6, wait_fixed=10000) diff --git a/modules/sonarr.py b/modules/sonarr.py index 5a959288..1351ebcb 100644 --- a/modules/sonarr.py +++ b/modules/sonarr.py @@ -70,7 +70,11 @@ class SonarrAPI: logger.info("Added to Sonarr | {:<6} | {}".format(tvdb_id, show.title)) add_count += 1 else: - logger.error("Sonarr Error: ({}) {}: ({}) {}".format(tvdb_id, show.title, response.status_code, response.json()[0]["errorMessage"])) + try: + logger.error("Sonarr Error: ({}) {}: ({}) {}".format(tvdb_id, show.title, response.status_code, response.json()[0]["errorMessage"])) + except KeyError as e: + logger.debug(url_json) + logger.error("Sonarr Error: {}".format(response.json())) logger.info("{} Show{} added to Sonarr".format(add_count, "s" if add_count > 1 else "")) @retry(stop_max_attempt_number=6, wait_fixed=10000) diff --git a/modules/util.py b/modules/util.py index d0525641..91104620 100644 --- a/modules/util.py +++ b/modules/util.py @@ -1,4 +1,4 @@ -import logging, re, signal, sys, time, traceback +import datetime, logging, re, signal, sys, time, traceback try: import msvcrt diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 807e18ab..370fdbb7 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -56,7 +56,7 @@ logger.info(util.get_centered_text("| |_) | |/ _ \ \/ / | |\/| |/ _ \ __/ _` | | logger.info(util.get_centered_text("| __/| | __/> < | | | | __/ || (_| | | | | | (_| | | | | (_| | (_| | __/ | ")) logger.info(util.get_centered_text("|_| |_|\___/_/\_\ |_| |_|\___|\__\__,_| |_| |_|\__,_|_| |_|\__,_|\__, |\___|_| ")) logger.info(util.get_centered_text(" |___/ ")) -logger.info(util.get_centered_text(" Version: 1.0.0 ")) +logger.info(util.get_centered_text(" Version: 1.0.1 ")) util.seperator() if args.test: