This commit is contained in:
Gregory Salaun 2021-12-15 17:08:00 +01:00
parent 15f4540ec5
commit e8f06e0070
2 changed files with 36 additions and 26 deletions

View File

@ -32,6 +32,7 @@ logger.info(f"Retrieving {len(plexMoviesLibrary)} Movies from Plex and Updating
for item in plexMoviesLibrary: for item in plexMoviesLibrary:
movie = UpdatedMovie() movie = UpdatedMovie()
tmdbMovie = Movie() tmdbMovie = Movie()
tmdbMovieDetails = object()
movie.PlexTitle = item.title movie.PlexTitle = item.title
for guid in item.guids: for guid in item.guids:
@ -58,7 +59,7 @@ for item in plexMoviesLibrary:
if movie.MovieTMDbCollectionTMDbId: if movie.MovieTMDbCollectionTMDbId:
logger.info(f'Movie {movie.PlexTitle} has been added to Collection List') logger.info(f'Movie {movie.PlexTitle} has been added to Collection List')
MoviesList.append(movie) 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 i = 0
count = 0 count = 0
@ -79,16 +80,17 @@ while i < len(MoviesList):
logger.info(f"Found a total of {len(MovieListFinal)} collections, updating config file now !") logger.info(f"Found a total of {len(MovieListFinal)} collections, updating config file now !")
def UpdateYAML(configFile):
currentYaml = object() currentYaml = object()
try: try:
with open(Config.PlexAutoCollectionConfigFilePath, 'r') as f: with open(configFile, 'r') as f:
try: try:
currentYaml = yaml.safe_load(f) currentYaml = yaml.safe_load(f)
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
print(exc) print(exc)
except: except:
logger.warning(f"Could not find the config file with path: {Config.PlexAutoCollectionConfigFilePath}") logger.warning(f"Could not find the config file with path: {configFile}")
currentYamlCollections = [] currentYamlCollections = []
@ -97,18 +99,25 @@ for movies in currentYaml['collections']:
for collection in MovieListFinal: for collection in MovieListFinal:
if collection.MovieTMDbCollectionName not in currentYamlCollections: if collection.MovieTMDbCollectionName not in currentYamlCollections:
with open(Config.PlexAutoCollectionConfigFilePath, 'r') as f: with open(configFile, 'r') as f:
new_coll = {f'{collection.MovieTMDbCollectionName}': {'sync_mode': 'sync', 'tmdb_collection': collection.MovieTMDbCollectionTMDbId, 'tmdb_summary': collection.MovieTMDbCollectionTMDbId}} new_coll = {f'{collection.MovieTMDbCollectionName}': {'sync_mode': 'sync',
'tmdb_collection': collection.MovieTMDbCollectionTMDbId,
'tmdb_summary': collection.MovieTMDbCollectionTMDbId}}
currentYaml['collections'].update(new_coll) currentYaml['collections'].update(new_coll)
if currentYaml: if currentYaml:
logger.info(f"Adding new collection: {collection.MovieTMDbCollectionName} to Yaml file...") logger.info(f"Adding new collection: {collection.MovieTMDbCollectionName} to {configFile} file...")
with open(Config.PlexAutoCollectionConfigFilePath, 'w') as f: with open(configFile, 'w') as f:
yaml.safe_dump(currentYaml, f) yaml.safe_dump(currentYaml, f)
if not os.path.exists(Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}"): if not os.path.exists(
Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}"):
logger.info(f"Download poster for new collection {collection.MovieTMDbCollectionName}...") logger.info(f"Download poster for new collection {collection.MovieTMDbCollectionName}...")
os.mkdir(Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}") os.mkdir(Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}")
urllib.request.urlretrieve(Config.tmdbImgUrl + f"{collection.MovieTMDbCollectionPosterPath}", Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}/poster.jpeg") 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...") logger.info(f"All collections have been updated in plex...")

View File

@ -6,4 +6,5 @@ class Config(object):
plexBaseUrl = 'https://plex.rouggy.ovh' plexBaseUrl = 'https://plex.rouggy.ovh'
plexToken = 'VeQQwtf-sNtWWLwzCEih' plexToken = 'VeQQwtf-sNtWWLwzCEih'
PlexAutoCollectionConfigFilePath = '/opt/Plex-Auto-Collections/config/config.yml' PlexAutoCollectionConfigFilePath = '/opt/Plex-Auto-Collections/config/config.yml'
PlexAutoCollectionConfigFilePath4K = '/opt/Plex-Auto-Collections/config/config-4k.yml'
PlexAutoCollectionConfigFileImagesPath = '/opt/Plex-Auto-Collections/config/images' PlexAutoCollectionConfigFileImagesPath = '/opt/Plex-Auto-Collections/config/images'