check paths when adding to radarr/sonarr

pull/487/head
meisnate12 3 years ago
parent 78dce17cb9
commit d3eb57902b

@ -53,11 +53,20 @@ class Radarr:
tags = options["tag"] if "tag" in options else self.tag tags = options["tag"] if "tag" in options else self.tag
search = options["search"] if "search" in options else self.search search = options["search"] if "search" in options else self.search
arr_paths = {}
arr_ids = {}
for movie in self.api.all_movies():
if movie.path:
arr_paths[movie.path] = movie.tmdbId
arr_ids[movie.tmdbId] = movie
added = [] added = []
exists = [] exists = []
skipped = [] skipped = []
invalid = [] invalid = []
movies = [] movies = []
path_lookup = {}
mismatched = {}
for i, item in enumerate(tmdb_ids, 1): for i, item in enumerate(tmdb_ids, 1):
path = item[1] if isinstance(item, tuple) else None path = item[1] if isinstance(item, tuple) else None
tmdb_id = item[0] if isinstance(item, tuple) else item tmdb_id = item[0] if isinstance(item, tuple) else item
@ -68,8 +77,18 @@ class Radarr:
skipped.append(item) skipped.append(item)
continue continue
try: try:
if tmdb_id in arr_ids:
exists.append(arr_ids[tmdb_id])
continue
if path in arr_paths:
mismatched[path] = tmdb_id
continue
movie = self.api.get_movie(tmdb_id=tmdb_id) movie = self.api.get_movie(tmdb_id=tmdb_id)
movies.append((movie, path) if path else movie) if path:
movies.append((movie, path))
path_lookup[path] = tmdb_id
else:
movies.append(movie)
except ArrException: except ArrException:
invalid.append(item) invalid.append(item)
if len(movies) == 100 or len(tmdb_ids) == i: if len(movies) == 100 or len(tmdb_ids) == i:
@ -91,26 +110,29 @@ class Radarr:
self.config.Cache.update_radarr_adds(movie.tmdbId, self.library.original_mapping_name) self.config.Cache.update_radarr_adds(movie.tmdbId, self.library.original_mapping_name)
logger.info(f"{len(added)} Movie{'s' if len(added) > 1 else ''} added to Radarr") logger.info(f"{len(added)} Movie{'s' if len(added) > 1 else ''} added to Radarr")
if len(exists) > 0: if len(exists) > 0 or len(skipped) > 0:
logger.info("") logger.info("")
for movie in exists: if len(exists) > 0:
logger.info(f"Already in Radarr | {movie.tmdbId:<6} | {movie.title}") for movie in exists:
if self.config.Cache: logger.info(f"Already in Radarr | {movie.tmdbId:<6} | {movie.title}")
self.config.Cache.update_radarr_adds(movie.tmdbId, self.library.original_mapping_name) if self.config.Cache:
logger.info(f"{len(exists)} Movie{'s' if len(exists) > 1 else ''} already existing in Radarr") self.config.Cache.update_radarr_adds(movie.tmdbId, self.library.original_mapping_name)
if len(skipped) > 0:
for movie in skipped:
logger.info(f"Skipped: In Cache | {movie}")
logger.info(f"{len(exists) + len(skipped)} Movie{'s' if len(skipped) > 1 else ''} already exist in Radarr")
if len(skipped) > 0: if len(mismatched) > 0:
logger.info("") logger.info("")
for movie in skipped: for path, tmdb_id in mismatched.items():
logger.info(f"Skipped: In Cache | {movie}") logger.info(f"Plex TMDb ID: {tmdb_id:<7} | Radarr TMDb ID: {arr_paths[path]:<7} | Path: {path}")
if self.config.Cache: logger.info(f"{len(mismatched)} Movie{'s' if len(mismatched) > 1 else ''} with mismatched TMDb IDs")
self.config.Cache.update_radarr_adds(movie[0] if isinstance(movie, tuple) else movie, self.library.original_mapping_name)
logger.info(f"{len(skipped)} Movie{'s' if len(skipped) > 1 else ''} already existing in Radarr")
if len(invalid) > 0: if len(invalid) > 0:
logger.info("") logger.info("")
for tmdb_id in invalid: for tmdb_id in invalid:
logger.info(f"Invalid TMDb ID | {tmdb_id}") logger.info(f"Invalid TMDb ID | {tmdb_id}")
logger.info(f"{len(invalid)} Movie{'s' if len(invalid) > 1 else ''} with Invalid IDs")
return len(added) return len(added)

@ -79,11 +79,20 @@ class Sonarr:
search = options["search"] if "search" in options else self.search search = options["search"] if "search" in options else self.search
cutoff_search = options["cutoff_search"] if "cutoff_search" in options else self.cutoff_search cutoff_search = options["cutoff_search"] if "cutoff_search" in options else self.cutoff_search
arr_paths = {}
arr_ids = {}
for series in self.api.all_series():
if series.path:
arr_paths[series.path] = series.tvdbId
arr_paths[series.tvdbId] = series
added = [] added = []
exists = [] exists = []
skipped = [] skipped = []
invalid = [] invalid = []
shows = [] shows = []
path_lookup = {}
mismatched = {}
for i, item in enumerate(tvdb_ids, 1): for i, item in enumerate(tvdb_ids, 1):
path = item[1] if isinstance(item, tuple) else None path = item[1] if isinstance(item, tuple) else None
tvdb_id = item[0] if isinstance(item, tuple) else item tvdb_id = item[0] if isinstance(item, tuple) else item
@ -94,8 +103,18 @@ class Sonarr:
skipped.append(item) skipped.append(item)
continue continue
try: try:
if tvdb_id in arr_ids:
exists.append(arr_ids[tvdb_id])
continue
if path in arr_paths:
mismatched[path] = tvdb_id
continue
show = self.api.get_series(tvdb_id=tvdb_id) show = self.api.get_series(tvdb_id=tvdb_id)
shows.append((show, path) if path else show) if path:
shows.append((show, path))
path_lookup[path] = tvdb_id
else:
shows.append(show)
except ArrException: except ArrException:
invalid.append(item) invalid.append(item)
if len(shows) == 100 or len(tvdb_ids) == i: if len(shows) == 100 or len(tvdb_ids) == i:
@ -117,26 +136,30 @@ class Sonarr:
self.config.Cache.update_sonarr_adds(series.tvdbId, self.library.original_mapping_name) self.config.Cache.update_sonarr_adds(series.tvdbId, self.library.original_mapping_name)
logger.info(f"{len(added)} Series added to Sonarr") logger.info(f"{len(added)} Series added to Sonarr")
if len(exists) > 0: if len(exists) > 0 or len(skipped) > 0:
logger.info("") logger.info("")
for series in exists: if len(exists) > 0:
logger.info(f"Already in Sonarr | {series.tvdbId:<6} | {series.title}") for series in exists:
if self.config.Cache: logger.info(f"Already in Sonarr | {series.tvdbId:<6} | {series.title}")
self.config.Cache.update_sonarr_adds(series.tvdbId, self.library.original_mapping_name) if self.config.Cache:
logger.info(f"{len(exists)} Series already existing in Sonarr") self.config.Cache.update_sonarr_adds(series.tvdbId, self.library.original_mapping_name)
if len(skipped) > 0:
logger.info("")
for series in skipped:
logger.info(f"Skipped: In Cache | {series}")
logger.info(f"{len(exists) + len(skipped)} Series already exist in Sonarr")
if len(skipped) > 0: if len(mismatched) > 0:
logger.info("") logger.info("")
for series in skipped: for path, tmdb_id in mismatched.items():
logger.info(f"Skipped: In Cache | {series}") logger.info(f"Plex TVDb ID: {tmdb_id:<7} | Sonarr TVDb ID: {arr_paths[path]:<7} | Path: {path}")
if self.config.Cache: logger.info(f"{len(mismatched)} Series with mismatched TVDb IDs")
self.config.Cache.update_sonarr_adds(series[0] if isinstance(series, tuple) else series, self.library.original_mapping_name)
logger.info(f"{len(skipped)} Movie{'s' if len(skipped) > 1 else ''} already existing in Sonarr")
if len(invalid) > 0: if len(invalid) > 0:
for tvdb_id in invalid: for tvdb_id in invalid:
logger.info("") logger.info("")
logger.info(f"Invalid TVDb ID | {tvdb_id}") logger.info(f"Invalid TVDb ID | {tvdb_id}")
logger.info(f"{len(invalid)} Series with Invalid IDs")
return len(added) return len(added)

Loading…
Cancel
Save