diff --git a/config/config.py b/config/config.py index 01faa6b..ef1674f 100644 --- a/config/config.py +++ b/config/config.py @@ -6,3 +6,4 @@ class Config(object): plexBaseUrl = 'https://plex.rouggy.ovh' plexToken = 'VeQQwtf-sNtWWLwzCEih' PlexAutoCollectionConfigFilePath = '/opt/Plex-Auto-Collections/config/config.yml' + PlexAutoCollectionConfigFileImagesPath = '/opt/Plex-Auto-Collections/config/images' diff --git a/models/movie_collection.py b/models/movie_collection.py index 6bae606..31e6a22 100644 --- a/models/movie_collection.py +++ b/models/movie_collection.py @@ -2,6 +2,7 @@ class MovieCollection: def __init__(self): self.collectionTitle = "" self.collectionId = "" + self.collectionImgPath = "" def get_existing_collections(self): pass \ No newline at end of file diff --git a/plexAutoCollectionUpdater.py b/plexAutoCollectionUpdater.py index 406f172..5241d8e 100644 --- a/plexAutoCollectionUpdater.py +++ b/plexAutoCollectionUpdater.py @@ -4,7 +4,7 @@ from plexapi.server import PlexServer from fuzzywuzzy import fuzz from models.movie_collection import MovieCollection from datetime import datetime as dt -import yaml +import yaml, os, urllib.request # Instantiate Tmdb object tmdb = TMDb() @@ -77,9 +77,10 @@ for movie in MovieCollectionFinal: nameLength = len(movie) coll.collectionTitle = movie.name[:nameLength - 13] coll.collectionId = movie.id + coll.collectionImgPath = movie.poster_path MovieCollectionList.append(coll) -print(f":: {dt.now().strftime('%d-%m-%Y %H:%M:%S')} :: CollectionUpdater :: Checking Yaml File...") +print(f":: {dt.now().strftime('%d-%m-%Y %H:%M:%S')} :: CollectionUpdater :: Checking and Updating Yaml File...") with open(Config.PlexAutoCollectionConfigFilePath, 'r') as f: try: @@ -99,5 +100,11 @@ for collection in MovieCollectionList: currentYaml['collections'].update(new_coll) if currentYaml: + print(f":: {dt.now().strftime('%d-%m-%Y %H:%M:%S')} :: CollectionUpdater :: Adding new collection: {collection.collectionTitle} to Yaml file...") with open(Config.PlexAutoCollectionConfigFilePath, 'w') as f: - yaml.safe_dump(currentYaml, f) \ No newline at end of file + yaml.safe_dump(currentYaml, f) + + if not os.path.exists(Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.collectionTitle}"): + print(f":: {dt.now().strftime('%d-%m-%Y %H:%M:%S')} :: CollectionUpdater :: Download poster for new collection {collection.collectionTitle}...") + os.mkdir(Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.collectionTitle}") + urllib.request.urlretrieve(Config.PlexAutoCollectionConfigFileImagesPath + f"{collection.collectionImgPath}", Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.collectionTitle}/poster.jpeg") \ No newline at end of file