diff --git a/plexAutoCollectionUpdater.py b/plexAutoCollectionUpdater.py index c1832d8..406f172 100644 --- a/plexAutoCollectionUpdater.py +++ b/plexAutoCollectionUpdater.py @@ -70,11 +70,14 @@ for movie in MatchingList: for id in TMDbCollection: MovieCollectionFinal.append(tmdbCollection.details(id)) +MovieCollectionList = [] + for movie in MovieCollectionFinal: coll = MovieCollection() nameLength = len(movie) coll.collectionTitle = movie.name[:nameLength - 13] coll.collectionId = movie.id + MovieCollectionList.append(coll) print(f":: {dt.now().strftime('%d-%m-%Y %H:%M:%S')} :: CollectionUpdater :: Checking Yaml File...") @@ -84,5 +87,17 @@ with open(Config.PlexAutoCollectionConfigFilePath, 'r') as f: except yaml.YAMLError as exc: print(exc) -for collection in currentYaml.items(): - print(collection.keys) \ No newline at end of file +currentYamlCollections = [] + +for movies in currentYaml['collections']: + currentYamlCollections.append(movies) + +for collection in MovieCollectionList: + if collection.collectionTitle not in currentYamlCollections: + with open(Config.PlexAutoCollectionConfigFilePath, 'r') as f: + new_coll = {f'{collection.collectionTitle}': {'sync_mode': 'sync', 'tmdb_collection': collection.collectionId, 'tmdb_summary': collection.collectionId}} + currentYaml['collections'].update(new_coll) + + if currentYaml: + with open(Config.PlexAutoCollectionConfigFilePath, 'w') as f: + yaml.safe_dump(currentYaml, f) \ No newline at end of file