diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 2e32e897e..0840715a1 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -1,5 +1,6 @@ # coding=utf-8 +import os import requests import logging from database import database, dict_converter, get_exclusion_clause @@ -10,6 +11,8 @@ from list_subtitles import store_subtitles, series_full_scan_subtitles from get_subtitle import episode_download_subtitles from event_handler import event_stream +headers = {"User-Agent": os.environ["SZ_USER_AGENT"]} + def update_all_episodes(): series_full_scan_subtitles() @@ -37,7 +40,7 @@ def sync_episodes(): # Get episodes data for a series from Sonarr url_sonarr_api_episode = url_sonarr() + "/api/episode?seriesId=" + str(seriesId['sonarrSeriesId']) + "&apikey=" + apikey_sonarr try: - r = requests.get(url_sonarr_api_episode, timeout=60, verify=False) + r = requests.get(url_sonarr_api_episode, timeout=60, verify=False, headers=headers) r.raise_for_status() except requests.exceptions.HTTPError as errh: logging.exception("BAZARR Error trying to get episodes from Sonarr. Http error.") diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index eecd7ef62..9ab7fd7d0 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -12,6 +12,8 @@ from list_subtitles import store_subtitles_movie, movies_full_scan_subtitles from get_subtitle import movies_download_subtitles from database import database, dict_converter, get_exclusion_clause +headers = {"User-Agent": os.environ["SZ_USER_AGENT"]} + def update_all_movies(): movies_full_scan_subtitles() @@ -45,7 +47,7 @@ def update_movies(): url_radarr_api_movies = url_radarr() + "/api/v3/movie?apikey=" + apikey_radarr try: - r = requests.get(url_radarr_api_movies, timeout=60, verify=False) + r = requests.get(url_radarr_api_movies, timeout=60, verify=False, headers=headers) r.raise_for_status() except requests.exceptions.HTTPError as errh: logging.exception("BAZARR Error trying to get movies from Radarr. Http error.") @@ -288,7 +290,7 @@ def get_profile_list(): url_radarr_api_movies = url_radarr() + "/api/v3/qualityprofile?apikey=" + apikey_radarr try: - profiles_json = requests.get(url_radarr_api_movies, timeout=60, verify=False) + profiles_json = requests.get(url_radarr_api_movies, timeout=60, verify=False, headers=headers) except requests.exceptions.ConnectionError as errc: logging.exception("BAZARR Error trying to get profiles from Radarr. Connection Error.") except requests.exceptions.Timeout as errt: @@ -371,7 +373,7 @@ def get_tags(): url_sonarr_api_series = url_radarr() + "/api/tag?apikey=" + apikey_radarr try: - tagsDict = requests.get(url_sonarr_api_series, timeout=60, verify=False) + tagsDict = requests.get(url_sonarr_api_series, timeout=60, verify=False, headers=headers) except requests.exceptions.ConnectionError: logging.exception("BAZARR Error trying to get tags from Radarr. Connection Error.") return [] diff --git a/bazarr/get_series.py b/bazarr/get_series.py index fcdee9ddf..1160b1843 100644 --- a/bazarr/get_series.py +++ b/bazarr/get_series.py @@ -3,7 +3,6 @@ import os import requests import logging -import ast from config import settings, url_sonarr from list_subtitles import list_missing_subtitles @@ -12,6 +11,8 @@ from utils import get_sonarr_version from helper import path_mappings from event_handler import event_stream +headers = {"User-Agent": os.environ["SZ_USER_AGENT"]} + def update_series(): apikey_sonarr = settings.sonarr.apikey @@ -34,7 +35,7 @@ def update_series(): # Get shows data from Sonarr url_sonarr_api_series = url_sonarr() + "/api/series?apikey=" + apikey_sonarr try: - r = requests.get(url_sonarr_api_series, timeout=60, verify=False) + r = requests.get(url_sonarr_api_series, timeout=60, verify=False, headers=headers) r.raise_for_status() except requests.exceptions.HTTPError: logging.exception("BAZARR Error trying to get series from Sonarr. Http error.") @@ -171,7 +172,7 @@ def get_profile_list(): url_sonarr_api_series = url_sonarr() + "/api/v3/languageprofile?apikey=" + apikey_sonarr try: - profiles_json = requests.get(url_sonarr_api_series, timeout=60, verify=False) + profiles_json = requests.get(url_sonarr_api_series, timeout=60, verify=False, headers=headers) except requests.exceptions.ConnectionError: logging.exception("BAZARR Error trying to get profiles from Sonarr. Connection Error.") return None @@ -209,7 +210,7 @@ def get_tags(): url_sonarr_api_series = url_sonarr() + "/api/tag?apikey=" + apikey_sonarr try: - tagsDict = requests.get(url_sonarr_api_series, timeout=60, verify=False) + tagsDict = requests.get(url_sonarr_api_series, timeout=60, verify=False, headers=headers) except requests.exceptions.ConnectionError: logging.exception("BAZARR Error trying to get tags from Sonarr. Connection Error.") return []