|
|
@ -3,8 +3,26 @@ from misc.log import logger
|
|
|
|
log = logger.get_logger(__name__)
|
|
|
|
log = logger.get_logger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def filter_trakt_movies_list(trakt_movies, callback):
|
|
|
|
|
|
|
|
new_movies_list = []
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
for tmp in trakt_movies:
|
|
|
|
|
|
|
|
if 'movie' not in tmp or 'ids' not in tmp['movie'] or 'tmdb' not in tmp['movie']['ids']:
|
|
|
|
|
|
|
|
log.debug("Removing movie from Trakt list as it did not have the required fields: %s", tmp)
|
|
|
|
|
|
|
|
if callback:
|
|
|
|
|
|
|
|
callback('movie', tmp)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
new_movies_list.append(tmp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new_movies_list
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
log.exception("Exception filtering Trakt movies list: ")
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def movies_to_tmdb_dict(radarr_movies):
|
|
|
|
def movies_to_tmdb_dict(radarr_movies):
|
|
|
|
movies = {}
|
|
|
|
movies = {}
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
for tmp in radarr_movies:
|
|
|
|
for tmp in radarr_movies:
|
|
|
|
if 'tmdbId' not in tmp:
|
|
|
|
if 'tmdbId' not in tmp:
|
|
|
@ -20,10 +38,6 @@ def movies_to_tmdb_dict(radarr_movies):
|
|
|
|
def remove_existing_movies(radarr_movies, trakt_movies, callback=None):
|
|
|
|
def remove_existing_movies(radarr_movies, trakt_movies, callback=None):
|
|
|
|
new_movies_list = []
|
|
|
|
new_movies_list = []
|
|
|
|
|
|
|
|
|
|
|
|
if not radarr_movies or not trakt_movies:
|
|
|
|
|
|
|
|
log.error("Inappropriate parameters were supplied")
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# turn radarr movies result into a dict with tmdb id as keys
|
|
|
|
# turn radarr movies result into a dict with tmdb id as keys
|
|
|
|
processed_movies = movies_to_tmdb_dict(radarr_movies)
|
|
|
|
processed_movies = movies_to_tmdb_dict(radarr_movies)
|
|
|
@ -32,24 +46,94 @@ def remove_existing_movies(radarr_movies, trakt_movies, callback=None):
|
|
|
|
|
|
|
|
|
|
|
|
# loop list adding to movies that do not already exist
|
|
|
|
# loop list adding to movies that do not already exist
|
|
|
|
for tmp in trakt_movies:
|
|
|
|
for tmp in trakt_movies:
|
|
|
|
if 'movie' not in tmp or 'ids' not in tmp['movie'] or 'tmdb' not in tmp['movie']['ids']:
|
|
|
|
# check if movie exists in processed_movies
|
|
|
|
log.debug("Skipping movie because it did not have required fields: %s", tmp)
|
|
|
|
if tmp['movie']['ids']['tmdb'] in processed_movies:
|
|
|
|
|
|
|
|
movie_year = str(tmp['movie']['year']) if tmp['movie']['year'] else '????'
|
|
|
|
|
|
|
|
log.debug("Removing existing movie: \'%s (%s)\'", tmp['movie']['title'], movie_year)
|
|
|
|
if callback:
|
|
|
|
if callback:
|
|
|
|
callback('movie', tmp)
|
|
|
|
callback('movie', tmp)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
new_movies_list.append(tmp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
movies_removed = len(trakt_movies) - len(new_movies_list)
|
|
|
|
|
|
|
|
log.debug("Filtered %d movies from Trakt list that were already in Radarr.", movies_removed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new_movies_list, movies_removed
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
log.exception("Exception removing existing movies from Trakt list: ")
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def exclusions_to_tmdb_dict(radarr_exclusions):
|
|
|
|
|
|
|
|
movie_exclusions = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
for tmp in radarr_exclusions:
|
|
|
|
|
|
|
|
if 'tmdbId' not in tmp:
|
|
|
|
|
|
|
|
log.debug("Could not handle movie: %s", tmp['movieTitle'])
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
movie_exclusions[tmp['tmdbId']] = tmp
|
|
|
|
|
|
|
|
return movie_exclusions
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
log.exception("Exception processing Radarr movie exclusions to TMDB dict: ")
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_existing_exclusions(radarr_exclusions, trakt_movies, callback=None):
|
|
|
|
|
|
|
|
new_movies_list = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
# turn radarr movie exclusions result into a dict with tmdb id as keys
|
|
|
|
|
|
|
|
processed_movies = exclusions_to_tmdb_dict(radarr_exclusions)
|
|
|
|
|
|
|
|
if not processed_movies:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# loop list adding to movies that do not already exist
|
|
|
|
|
|
|
|
for tmp in trakt_movies:
|
|
|
|
# check if movie exists in processed_movies
|
|
|
|
# check if movie exists in processed_movies
|
|
|
|
if tmp['movie']['ids']['tmdb'] in processed_movies:
|
|
|
|
if tmp['movie']['ids']['tmdb'] in processed_movies:
|
|
|
|
movie_year = str(tmp['movie']['year']) if tmp['movie']['year'] else '????'
|
|
|
|
movie_year = str(tmp['movie']['year']) if tmp['movie']['year'] else '????'
|
|
|
|
log.debug("Removing existing movie: \'%s (%s)\'", tmp['movie']['title'], movie_year)
|
|
|
|
log.debug("Removing excluded movie: \'%s (%s)\'", tmp['movie']['title'], movie_year)
|
|
|
|
if callback:
|
|
|
|
if callback:
|
|
|
|
callback('movie', tmp)
|
|
|
|
callback('movie', tmp)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
new_movies_list.append(tmp)
|
|
|
|
new_movies_list.append(tmp)
|
|
|
|
|
|
|
|
|
|
|
|
log.debug("Filtered %d Trakt movies to %d movies that weren't already in Radarr", len(trakt_movies),
|
|
|
|
movies_removed = len(trakt_movies) - len(new_movies_list)
|
|
|
|
len(new_movies_list))
|
|
|
|
log.debug("Filtered %d movies from Trakt list that were excluded in Radarr.", movies_removed)
|
|
|
|
return new_movies_list
|
|
|
|
|
|
|
|
|
|
|
|
return new_movies_list, movies_removed
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
log.exception("Exception removing existing movies from Trakt list: ")
|
|
|
|
log.exception("Exception removing excluded movies from Trakt list: ")
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_existing_and_excluded_movies(radarr_movies, radarr_exclusions, trakt_movies, callback=None):
|
|
|
|
|
|
|
|
if not radarr_movies or not radarr_exclusions or not trakt_movies:
|
|
|
|
|
|
|
|
log.error("Inappropriate parameters were supplied.")
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
# clean up trakt_movies list
|
|
|
|
|
|
|
|
trakt_movies = filter_trakt_movies_list(trakt_movies, callback)
|
|
|
|
|
|
|
|
if not trakt_movies:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# filter out existing movies in radarr from new trakt list
|
|
|
|
|
|
|
|
preprocessed_movies_list, movies_removed_1 = remove_existing_movies(radarr_movies, trakt_movies, callback)
|
|
|
|
|
|
|
|
if not preprocessed_movies_list:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# filter out radarr exclusions from the list above
|
|
|
|
|
|
|
|
processed_movies_list, movies_removed_2 = remove_existing_exclusions(radarr_exclusions,
|
|
|
|
|
|
|
|
preprocessed_movies_list,
|
|
|
|
|
|
|
|
callback)
|
|
|
|
|
|
|
|
if not processed_movies_list:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
movies_removed_total = movies_removed_1 + movies_removed_2
|
|
|
|
|
|
|
|
log.debug("Filtered a total of %d movies from the Trakt movies list.", movies_removed_total)
|
|
|
|
|
|
|
|
return processed_movies_list
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
log.exception("Exception removing existing and excluded movies from Trakt list: ")
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|