update
This commit is contained in:
parent
261c00fc91
commit
936d2858c3
@ -22,64 +22,66 @@ baseurl = Config.plexBaseUrl
|
||||
token = Config.plexToken
|
||||
plex = PlexServer(baseurl, token)
|
||||
|
||||
plexMoviesLibrary = plex.library.section('Movies')
|
||||
plexMoviesLibrary = plexMoviesLibrary.search()
|
||||
def MovieCollectionList(library):
|
||||
plexMoviesLibrary = plex.library.section(library)
|
||||
plexMoviesLibrary = plexMoviesLibrary.search()
|
||||
|
||||
MoviesList = []
|
||||
MoviesList = []
|
||||
|
||||
logger.info(f"Retrieving {len(plexMoviesLibrary)} Movies from Plex and Updating TMDb information...")
|
||||
logger.info(f"Retrieving {len(plexMoviesLibrary)} Movies from Plex and Updating TMDb information...")
|
||||
|
||||
for item in plexMoviesLibrary:
|
||||
movie = UpdatedMovie()
|
||||
tmdbMovie = Movie()
|
||||
for item in plexMoviesLibrary:
|
||||
movie = UpdatedMovie()
|
||||
tmdbMovie = Movie()
|
||||
|
||||
movie.PlexTitle = item.title
|
||||
for guid in item.guids:
|
||||
if "tmdb://" in guid.id:
|
||||
movie.TMDbId = guid.id[7:]
|
||||
elif "imdb://" in guid.id:
|
||||
movie.ImdbId = guid.id[7:]
|
||||
movie.PlexTitle = item.title
|
||||
for guid in item.guids:
|
||||
if "tmdb://" in guid.id:
|
||||
movie.TMDbId = guid.id[7:]
|
||||
elif "imdb://" in guid.id:
|
||||
movie.ImdbId = guid.id[7:]
|
||||
|
||||
# Search for the movie on TMDb
|
||||
try:
|
||||
tmdbMovieDetails = tmdbMovie.details(movie_id=movie.TMDbId)
|
||||
logger.debug(f'Getting TMDb details for {movie.PlexTitle}')
|
||||
except:
|
||||
logger.warning(f"CollectionUpdater :: Cannot get details of {movie.PlexTitle} from TMDb")
|
||||
# Search for the movie on TMDb
|
||||
try:
|
||||
tmdbMovieDetails = tmdbMovie.details(movie_id=movie.TMDbId)
|
||||
logger.debug(f'Getting TMDb details for {movie.PlexTitle}')
|
||||
except:
|
||||
logger.warning(f"CollectionUpdater :: Cannot get details of {movie.PlexTitle} from TMDb")
|
||||
|
||||
if tmdbMovieDetails['belongs_to_collection']:
|
||||
movie.MovieTMDbCollectionName = tmdbMovieDetails['belongs_to_collection'].name[:len(tmdbMovieDetails['belongs_to_collection'].name) - 7]
|
||||
movie.MovieTMDbCollectionTMDbId = tmdbMovieDetails['belongs_to_collection'].id
|
||||
movie.MovieTMDbCollectionPosterPath = tmdbMovieDetails['belongs_to_collection'].poster_path
|
||||
if tmdbMovieDetails['belongs_to_collection']:
|
||||
movie.MovieTMDbCollectionName = tmdbMovieDetails['belongs_to_collection'].name[:len(tmdbMovieDetails['belongs_to_collection'].name) - 7]
|
||||
movie.MovieTMDbCollectionTMDbId = tmdbMovieDetails['belongs_to_collection'].id
|
||||
movie.MovieTMDbCollectionPosterPath = tmdbMovieDetails['belongs_to_collection'].poster_path
|
||||
|
||||
movie.TMDbTitle = tmdbMovieDetails.title
|
||||
movie.TMDbTitle = tmdbMovieDetails.title
|
||||
|
||||
# Add movie to the list of Movies
|
||||
if movie.MovieTMDbCollectionTMDbId:
|
||||
logger.info(f'Movie {movie.PlexTitle} has been added to Collection List')
|
||||
MoviesList.append(movie)
|
||||
logger.info(f"Retrieved Movies from Plex and Updated TMDb information for {len(MoviesList)} movies...")
|
||||
# Add movie to the list of Movies
|
||||
if movie.MovieTMDbCollectionTMDbId:
|
||||
logger.info(f'Movie {movie.PlexTitle} has been added to Collection List')
|
||||
MoviesList.append(movie)
|
||||
logger.info(f"Retrieved Movies from Plex and Updated TMDb information for {len(MoviesList)} movies...")
|
||||
|
||||
i = 0
|
||||
count = 0
|
||||
MovieListFinal = []
|
||||
ExistingCollectionId = []
|
||||
|
||||
while i < len(MoviesList):
|
||||
for movie in MoviesList:
|
||||
if MoviesList[i].MovieTMDbCollectionTMDbId == movie.MovieTMDbCollectionTMDbId:
|
||||
count += 1
|
||||
if count > 2:
|
||||
if not MoviesList[i].MovieTMDbCollectionTMDbId in ExistingCollectionId:
|
||||
logger.info(f"Keeping collection {MoviesList[i].MovieTMDbCollectionName} which contains 3 or more movies")
|
||||
ExistingCollectionId.append(MoviesList[i].MovieTMDbCollectionTMDbId)
|
||||
MovieListFinal.append(MoviesList[i])
|
||||
i += 1
|
||||
i = 0
|
||||
count = 0
|
||||
MovieListFinal = []
|
||||
ExistingCollectionId = []
|
||||
|
||||
logger.info(f"Found a total of {len(MovieListFinal)} collections, updating config file now !")
|
||||
while i < len(MoviesList):
|
||||
for movie in MoviesList:
|
||||
if MoviesList[i].MovieTMDbCollectionTMDbId == movie.MovieTMDbCollectionTMDbId:
|
||||
count += 1
|
||||
if count > 2:
|
||||
if not MoviesList[i].MovieTMDbCollectionTMDbId in ExistingCollectionId:
|
||||
logger.info(f"Keeping collection {MoviesList[i].MovieTMDbCollectionName} which contains 3 or more movies")
|
||||
ExistingCollectionId.append(MoviesList[i].MovieTMDbCollectionTMDbId)
|
||||
MovieListFinal.append(MoviesList[i])
|
||||
i += 1
|
||||
count = 0
|
||||
|
||||
def UpdateYAML(configFile):
|
||||
logger.info(f"Found a total of {len(MovieListFinal)} collections, updating config file now !")
|
||||
return MovieListFinal
|
||||
|
||||
def UpdateYAML(configFile, MovieListFinal):
|
||||
try:
|
||||
with open(configFile, 'r') as f:
|
||||
try:
|
||||
@ -114,7 +116,10 @@ def UpdateYAML(configFile):
|
||||
urllib.request.urlretrieve(Config.tmdbImgUrl + f"{collection.MovieTMDbCollectionPosterPath}",
|
||||
Config.PlexAutoCollectionConfigFileImagesPath + f"/{collection.MovieTMDbCollectionName}/poster.jpeg")
|
||||
|
||||
UpdateYAML(Config.PlexAutoCollectionConfigFilePath)
|
||||
#UpdateYAML(Config.PlexAutoCollectionConfigFilePath4K)
|
||||
MovieListFinal = MovieCollectionList('Movies')
|
||||
UpdateYAML(Config.PlexAutoCollectionConfigFilePath, MovieListFinal)
|
||||
|
||||
MovieListFinal = MovieCollectionList('4K Movies')
|
||||
UpdateYAML(Config.PlexAutoCollectionConfigFilePath4K)
|
||||
|
||||
logger.info(f"All collections have been updated in plex...")
|
Loading…
x
Reference in New Issue
Block a user