Fixed an issue that could clear episodes history in case Sonarr API return something else than valid series or episodes.

pull/2258/head v1.3.2-beta.15
morpheus65535 12 months ago
parent addae11b61
commit 97bdf0066e

@ -85,5 +85,11 @@ def get_movies_from_radarr_api(apikey_radarr, radarr_id=None):
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
logging.exception("BAZARR Error trying to get movies from Radarr.") logging.exception("BAZARR Error trying to get movies from Radarr.")
return return
except Exception as e:
logging.exception(f"Exception raised while getting movies from Radarr API: {e}")
return
else: else:
return r.json() if r.status_code == 200:
return r.json()
else:
return

@ -78,6 +78,8 @@ def sync_episodes(series_id, send_event=True):
episodes_to_update.append(parsed_episode) episodes_to_update.append(parsed_episode)
else: else:
episodes_to_add.append(episodeParser(episode)) episodes_to_add.append(episodeParser(episode))
else:
return
# Remove old episodes from DB # Remove old episodes from DB
episodes_to_delete = list(set(current_episodes_id_db_list) - set(current_episodes_sonarr)) episodes_to_delete = list(set(current_episodes_id_db_list) - set(current_episodes_sonarr))

@ -43,7 +43,7 @@ def update_series(send_event=True):
tagsDict = get_tags() tagsDict = get_tags()
# Get shows data from Sonarr # Get shows data from Sonarr
series = get_series_from_sonarr_api(url=url_sonarr(), apikey_sonarr=apikey_sonarr) series = get_series_from_sonarr_api(apikey_sonarr=apikey_sonarr)
if not isinstance(series, list): if not isinstance(series, list):
return return
else: else:
@ -157,8 +157,7 @@ def update_one_series(series_id, action):
# Get series data from sonarr api # Get series data from sonarr api
series = None series = None
series_data = get_series_from_sonarr_api(url=url_sonarr(), apikey_sonarr=settings.sonarr.apikey, series_data = get_series_from_sonarr_api(apikey_sonarr=settings.sonarr.apikey, sonarr_series_id=int(series_id))
sonarr_series_id=int(series_id))
if not series_data: if not series_data:
return return

@ -67,7 +67,7 @@ def get_tags():
return tagsDict.json() return tagsDict.json()
def get_series_from_sonarr_api(url, apikey_sonarr, sonarr_series_id=None): def get_series_from_sonarr_api(apikey_sonarr, sonarr_series_id=None):
url_sonarr_api_series = (f"{url_api_sonarr()}series/{sonarr_series_id if sonarr_series_id else ''}?" url_sonarr_api_series = (f"{url_api_sonarr()}series/{sonarr_series_id if sonarr_series_id else ''}?"
f"apikey={apikey_sonarr}") f"apikey={apikey_sonarr}")
try: try:
@ -87,12 +87,18 @@ def get_series_from_sonarr_api(url, apikey_sonarr, sonarr_series_id=None):
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
logging.exception("BAZARR Error trying to get series from Sonarr.") logging.exception("BAZARR Error trying to get series from Sonarr.")
return return
except Exception as e:
logging.exception(f"Exception raised while getting series from Sonarr API: {e}")
return
else: else:
result = r.json() if r.status_code == 200:
if isinstance(result, dict): result = r.json()
return [result] if isinstance(result, dict):
return [result]
else:
return r.json()
else: else:
return r.json() return
def get_episodes_from_sonarr_api(apikey_sonarr, series_id=None, episode_id=None): def get_episodes_from_sonarr_api(apikey_sonarr, series_id=None, episode_id=None):
@ -118,8 +124,14 @@ def get_episodes_from_sonarr_api(apikey_sonarr, series_id=None, episode_id=None)
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
logging.exception("BAZARR Error trying to get episodes from Sonarr.") logging.exception("BAZARR Error trying to get episodes from Sonarr.")
return return
except Exception as e:
logging.exception(f"Exception raised while getting episodes from Sonarr API: {e}")
return
else: else:
return r.json() if r.status_code == 200:
return r.json()
else:
return
def get_episodesFiles_from_sonarr_api(apikey_sonarr, series_id=None, episode_file_id=None): def get_episodesFiles_from_sonarr_api(apikey_sonarr, series_id=None, episode_file_id=None):
@ -146,5 +158,11 @@ def get_episodesFiles_from_sonarr_api(apikey_sonarr, series_id=None, episode_fil
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr.") logging.exception("BAZARR Error trying to get episodeFiles from Sonarr.")
return return
except Exception as e:
logging.exception(f"Exception raised while getting episodes from Sonarr API: {e}")
return
else: else:
return r.json() if r.status_code == 200:
return r.json()
else:
return

Loading…
Cancel
Save