From 0fef8d51d2a7767625581ac88d3ac8521ecb3688 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Wed, 31 Mar 2021 00:20:20 -0400 Subject: [PATCH] added --resume --- modules/config.py | 14 ++++++++++++-- modules/plex.py | 1 + plex_meta_manager.py | 12 +++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/modules/config.py b/modules/config.py index f339a6b7..1c23ef22 100644 --- a/modules/config.py +++ b/modules/config.py @@ -389,7 +389,7 @@ class Config: util.separator() - def update_libraries(self, test, requested_collections): + def update_libraries(self, test, requested_collections, resume_from): for library in self.libraries: os.environ["PLEXAPI_PLEXAPI_TIMEOUT"] = str(library.timeout) logger.info("") @@ -398,7 +398,7 @@ class Config: util.separator(f"Mapping {library.name} Library") logger.info("") movie_map, show_map = self.map_guids(library) - if not test: + if not test and not resume_from: if library.mass_genre_update: self.mass_metadata(library, movie_map, show_map) try: library.update_metadata(self.TMDb, test) @@ -406,6 +406,9 @@ class Config: logger.info("") util.separator(f"{library.name} Library {'Test ' if test else ''}Collections") collections = {c: library.collections[c] for c in util.get_list(requested_collections) if c in library.collections} if requested_collections else library.collections + if resume_from and resume_from not in collections: + logger.warning(f"Collection: {resume_from} not in {library.name}") + continue if collections: for mapping_name, collection_attrs in collections.items(): if test and ("test" not in collection_attrs or collection_attrs["test"] is not True): @@ -423,6 +426,13 @@ class Config: if no_template_test: continue try: + if resume_from and resume_from != mapping_name: + continue + elif resume_from == mapping_name: + resume_from = None + logger.info("") + util.separator(f"Resuming Collections") + logger.info("") util.separator(f"{mapping_name} Collection") logger.info("") diff --git a/modules/plex.py b/modules/plex.py index 771dd53e..5357e86a 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -113,6 +113,7 @@ class PlexAPI: self.Plex = next((s for s in self.PlexServer.library.sections() if s.title == params["name"] and ((self.is_movie and isinstance(s, MovieSection)) or (self.is_show and isinstance(s, ShowSection)))), None) if not self.Plex: raise Failed(f"Plex Error: Plex Library {params['name']} not found") + logger.info(f"Using Metadata File: {params['metadata_path']}") try: self.data, ind, bsi = yaml.util.load_yaml_guess_indent(open(params["metadata_path"], encoding="utf-8")) diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 91f84025..c02e3a0c 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -13,6 +13,7 @@ parser.add_argument("--my-tests", dest="tests", help=argparse.SUPPRESS, action=" parser.add_argument("--debug", dest="debug", help=argparse.SUPPRESS, action="store_true", default=False) parser.add_argument("-c", "--config", dest="config", help="Run with desired *.yml file", type=str) parser.add_argument("-t", "--time", dest="time", help="Time to update each day use format HH:MM (Default: 03:00)", default="03:00", type=str) +parser.add_argument("-re", "--resume", dest="resume", help="Resume collection run from a specific collection", type=str) parser.add_argument("-r", "--run", dest="run", help="Run without the scheduler", action="store_true", default=False) parser.add_argument("-rt", "--test", "--tests", "--run-test", "--run-tests", dest="test", help="Run in debug mode with only collections that have test: true", action="store_true", default=False) parser.add_argument("-cl", "--collection", "--collections", dest="collections", help="Process only specified collections (comma-separated list)", type=str) @@ -37,6 +38,7 @@ test = check_bool("PMM_TEST", args.test) debug = check_bool("PMM_DEBUG", args.debug) run = check_bool("PMM_RUN", args.run) collections = os.environ.get("PMM_COLLECTIONS") if os.environ.get("PMM_COLLECTIONS") else args.collections +resume = os.environ.get("PMM_RESUME") if os.environ.get("PMM_RESUME") else args.resume time_to_run = os.environ.get("PMM_TIME") if os.environ.get("PMM_TIME") else args.time if not re.match("^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$", time_to_run): @@ -94,7 +96,7 @@ if my_tests: tests.run_tests(default_dir) sys.exit(0) -def start(config_path, is_test, daily, collections_to_run): +def start(config_path, is_test, daily, collections_to_run, resume_from): if daily: start_type = "Daily " elif is_test: start_type = "Test " elif collections_to_run: start_type = "Collections " @@ -103,7 +105,7 @@ def start(config_path, is_test, daily, collections_to_run): util.separator(f"Starting {start_type}Run") try: config = Config(default_dir, config_path) - config.update_libraries(is_test, collections_to_run) + config.update_libraries(is_test, collections_to_run, resume_from) except Exception as e: util.print_stacktrace() logger.critical(e) @@ -111,11 +113,11 @@ def start(config_path, is_test, daily, collections_to_run): util.separator(f"Finished {start_type}Run\nRun Time: {str(datetime.now() - start_time).split('.')[0]}") try: - if run or test or collections: - start(config_file, test, False, collections) + if run or test or collections or resume: + start(config_file, test, False, collections, resume) else: length = 0 - schedule.every().day.at(time_to_run).do(start, config_file, False, True, None) + schedule.every().day.at(time_to_run).do(start, config_file, False, True, None, None) while True: schedule.run_pending() current = datetime.now().strftime("%H:%M")