From e8f06e0070484a44bbbb1404ec37a2d4036bfee9 Mon Sep 17 00:00:00 2001 From: rouggy Date: Wed, 15 Dec 2021 17:08:00 +0100 Subject: [PATCH] update --- PlexAutoCollectionUpdater.py | 61 +++++++++++++++++++++--------------- config/config.py | 1 + 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/PlexAutoCollectionUpdater.py b/PlexAutoCollectionUpdater.py index 2190c6b..c4f07be 100644 --- a/PlexAutoCollectionUpdater.py +++ b/PlexAutoCollectionUpdater.py @@ -32,6 +32,7 @@ logger.info(f"Retrieving {len(plexMoviesLibrary)} Movies from Plex and Updating for item in plexMoviesLibrary: movie = UpdatedMovie() tmdbMovie = Movie() + tmdbMovieDetails = object() movie.PlexTitle = item.title for guid in item.guids: @@ -58,7 +59,7 @@ for item in plexMoviesLibrary: if movie.MovieTMDbCollectionTMDbId: logger.info(f'Movie {movie.PlexTitle} has been added to Collection List') MoviesList.append(movie) -logger.info("Retrieved Movies from Plex and Updated TMDb information for {len(MoviesList)} movies...") +logger.info(f"Retrieved Movies from Plex and Updated TMDb information for {len(MoviesList)} movies...") i = 0 count = 0 @@ -79,36 +80,44 @@ while i < len(MoviesList): logger.info(f"Found a total of {len(MovieListFinal)} collections, updating config file now !") -currentYaml = object() +def UpdateYAML(configFile): + currentYaml = object() -try: - with open(Config.PlexAutoCollectionConfigFilePath, 'r') as f: - try: - currentYaml = yaml.safe_load(f) - except yaml.YAMLError as exc: - print(exc) -except: - logger.warning(f"Could not find the config file with path: {Config.PlexAutoCollectionConfigFilePath}") + try: + with open(configFile, 'r') as f: + try: + currentYaml = yaml.safe_load(f) + except yaml.YAMLError as exc: + print(exc) + except: + logger.warning(f"Could not find the config file with path: {configFile}") -currentYamlCollections = [] + currentYamlCollections = [] -for movies in currentYaml['collections']: - currentYamlCollections.append(movies) + for movies in currentYaml['collections']: + currentYamlCollections.append(movies) -for collection in MovieListFinal: - if collection.MovieTMDbCollectionName not in currentYamlCollections: - with open(Config.PlexAutoCollectionConfigFilePath, 'r') as f: - new_coll = {f'{collection.MovieTMDbCollectionName}': {'sync_mode': 'sync', 'tmdb_collection': collection.MovieTMDbCollectionTMDbId, 'tmdb_summary': collection.MovieTMDbCollectionTMDbId}} - currentYaml['collections'].update(new_coll) + for collection in MovieListFinal: + if collection.MovieTMDbCollectionName not in currentYamlCollections: + with open(configFile, 'r') as f: + new_coll = {f'{collection.MovieTMDbCollectionName}': {'sync_mode': 'sync', + 'tmdb_collection': collection.MovieTMDbCollectionTMDbId, + 'tmdb_summary': collection.MovieTMDbCollectionTMDbId}} + currentYaml['collections'].update(new_coll) - if currentYaml: - logger.info(f"Adding new collection: {collection.MovieTMDbCollectionName} to Yaml file...") - with open(Config.PlexAutoCollectionConfigFilePath, 'w') as f: - yaml.safe_dump(currentYaml, f) + if currentYaml: + logger.info(f"Adding new collection: {collection.MovieTMDbCollectionName} to {configFile} file...") + with open(configFile, 'w') as f: + yaml.safe_dump(currentYaml, f) - if not os.path.exists(Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}"): - logger.info(f"Download poster for new collection {collection.MovieTMDbCollectionName}...") - os.mkdir(Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}") - urllib.request.urlretrieve(Config.tmdbImgUrl + f"{collection.MovieTMDbCollectionPosterPath}", Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}/poster.jpeg") + if not os.path.exists( + Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}"): + logger.info(f"Download poster for new collection {collection.MovieTMDbCollectionName}...") + os.mkdir(Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}") + urllib.request.urlretrieve(Config.tmdbImgUrl + f"{collection.MovieTMDbCollectionPosterPath}", + Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}/poster.jpeg") + +UpdateYAML(Config.PlexAutoCollectionConfigFilePath) +UpdateYAML(Config.PlexAutoCollectionConfigFilePath4K) logger.info(f"All collections have been updated in plex...") \ No newline at end of file diff --git a/config/config.py b/config/config.py index ef1674f..6037daf 100644 --- a/config/config.py +++ b/config/config.py @@ -6,4 +6,5 @@ class Config(object): plexBaseUrl = 'https://plex.rouggy.ovh' plexToken = 'VeQQwtf-sNtWWLwzCEih' PlexAutoCollectionConfigFilePath = '/opt/Plex-Auto-Collections/config/config.yml' + PlexAutoCollectionConfigFilePath4K = '/opt/Plex-Auto-Collections/config/config-4k.yml' PlexAutoCollectionConfigFileImagesPath = '/opt/Plex-Auto-Collections/config/images'