mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-01-06 06:52:07 +08:00
Added user-agent to all Sonarr and Radarr API calls
This commit is contained in:
parent
9993f123f1
commit
daa2d1e8bf
3 changed files with 16 additions and 11 deletions
|
@ -7,6 +7,8 @@ import string
|
|||
|
||||
from config import settings, url_sonarr, url_radarr
|
||||
|
||||
headers = {"User-Agent": os.environ["SZ_USER_AGENT"]}
|
||||
|
||||
|
||||
def browse_bazarr_filesystem(path='#'):
|
||||
if path == '#' or path == '/' or path == '':
|
||||
|
@ -49,7 +51,7 @@ def browse_sonarr_filesystem(path='#'):
|
|||
"&allowFoldersWithoutTrailingSlashes=true&includeFiles=false&apikey=" + \
|
||||
settings.sonarr.apikey
|
||||
try:
|
||||
r = requests.get(url_sonarr_api_filesystem, timeout=60, verify=False)
|
||||
r = requests.get(url_sonarr_api_filesystem, 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.")
|
||||
|
@ -75,7 +77,7 @@ def browse_radarr_filesystem(path='#'):
|
|||
"&allowFoldersWithoutTrailingSlashes=true&includeFiles=false&apikey=" + \
|
||||
settings.radarr.apikey
|
||||
try:
|
||||
r = requests.get(url_radarr_api_filesystem, timeout=60, verify=False)
|
||||
r = requests.get(url_radarr_api_filesystem, timeout=60, verify=False, headers=headers)
|
||||
r.raise_for_status()
|
||||
except requests.exceptions.HTTPError:
|
||||
logging.exception("BAZARR Error trying to get series from Radarr. Http error.")
|
||||
|
|
|
@ -62,6 +62,8 @@ login_auth = settings.auth.type
|
|||
|
||||
update_notifier()
|
||||
|
||||
headers = {"User-Agent": os.environ["SZ_USER_AGENT"]}
|
||||
|
||||
|
||||
def check_login(actual_method):
|
||||
@wraps(actual_method)
|
||||
|
@ -131,7 +133,7 @@ def series_images(url):
|
|||
baseUrl = settings.sonarr.base_url
|
||||
url_image = (url_sonarr() + '/api/' + url.lstrip(baseUrl) + '?apikey=' + apikey).replace('poster-250', 'poster-500')
|
||||
try:
|
||||
req = requests.get(url_image, stream=True, timeout=15, verify=False)
|
||||
req = requests.get(url_image, stream=True, timeout=15, verify=False, headers=headers)
|
||||
except:
|
||||
return '', 404
|
||||
else:
|
||||
|
@ -145,7 +147,7 @@ def movies_images(url):
|
|||
baseUrl = settings.radarr.base_url
|
||||
url_image = url_radarr() + '/api/' + url.lstrip(baseUrl) + '?apikey=' + apikey
|
||||
try:
|
||||
req = requests.get(url_image, stream=True, timeout=15, verify=False)
|
||||
req = requests.get(url_image, stream=True, timeout=15, verify=False, headers=headers)
|
||||
except:
|
||||
return '', 404
|
||||
else:
|
||||
|
@ -172,7 +174,7 @@ def proxy(protocol, url):
|
|||
url = protocol + '://' + unquote(url)
|
||||
params = request.args
|
||||
try:
|
||||
result = requests.get(url, params, allow_redirects=False, verify=False, timeout=5)
|
||||
result = requests.get(url, params, allow_redirects=False, verify=False, timeout=5, headers=headers)
|
||||
except Exception as e:
|
||||
return dict(status=False, error=repr(e))
|
||||
else:
|
||||
|
|
|
@ -28,6 +28,7 @@ import datetime
|
|||
import glob
|
||||
|
||||
region = make_region().configure('dogpile.cache.memory')
|
||||
headers = {"User-Agent": os.environ["SZ_USER_AGENT"]}
|
||||
|
||||
|
||||
class BinaryNotFound(Exception):
|
||||
|
@ -206,7 +207,7 @@ def get_sonarr_version():
|
|||
if settings.general.getboolean('use_sonarr'):
|
||||
try:
|
||||
sv = url_sonarr() + "/api/system/status?apikey=" + settings.sonarr.apikey
|
||||
sonarr_version = requests.get(sv, timeout=60, verify=False).json()['version']
|
||||
sonarr_version = requests.get(sv, timeout=60, verify=False, headers=headers).json()['version']
|
||||
except Exception:
|
||||
logging.debug('BAZARR cannot get Sonarr version')
|
||||
sonarr_version = 'unknown'
|
||||
|
@ -218,7 +219,7 @@ def get_sonarr_platform():
|
|||
if settings.general.getboolean('use_sonarr'):
|
||||
try:
|
||||
sv = url_sonarr() + "/api/system/status?apikey=" + settings.sonarr.apikey
|
||||
response = requests.get(sv, timeout=60, verify=False).json()
|
||||
response = requests.get(sv, timeout=60, verify=False, headers=headers).json()
|
||||
if response['isLinux'] or response['isOsx']:
|
||||
sonarr_platform = 'posix'
|
||||
elif response['isWindows']:
|
||||
|
@ -235,7 +236,7 @@ def notify_sonarr(sonarr_series_id):
|
|||
'name': 'RescanSeries',
|
||||
'seriesId': int(sonarr_series_id)
|
||||
}
|
||||
requests.post(url, json=data, timeout=60, verify=False)
|
||||
requests.post(url, json=data, timeout=60, verify=False, headers=headers)
|
||||
except Exception as e:
|
||||
logging.debug('BAZARR notify Sonarr')
|
||||
|
||||
|
@ -245,7 +246,7 @@ def get_radarr_version():
|
|||
if settings.general.getboolean('use_radarr'):
|
||||
try:
|
||||
rv = url_radarr() + "/api/system/status?apikey=" + settings.radarr.apikey
|
||||
radarr_version = requests.get(rv, timeout=60, verify=False).json()['version']
|
||||
radarr_version = requests.get(rv, timeout=60, verify=False, headers=headers).json()['version']
|
||||
except Exception:
|
||||
logging.debug('BAZARR cannot get Radarr version')
|
||||
radarr_version = 'unknown'
|
||||
|
@ -257,7 +258,7 @@ def get_radarr_platform():
|
|||
if settings.general.getboolean('use_radarr'):
|
||||
try:
|
||||
rv = url_radarr() + "/api/system/status?apikey=" + settings.radarr.apikey
|
||||
response = requests.get(rv, timeout=60, verify=False).json()
|
||||
response = requests.get(rv, timeout=60, verify=False, headers=headers).json()
|
||||
if response['isLinux'] or response['isOsx']:
|
||||
radarr_platform = 'posix'
|
||||
elif response['isWindows']:
|
||||
|
@ -274,7 +275,7 @@ def notify_radarr(radarr_id):
|
|||
'name': 'RescanMovie',
|
||||
'movieId': int(radarr_id)
|
||||
}
|
||||
requests.post(url, json=data, timeout=60, verify=False)
|
||||
requests.post(url, json=data, timeout=60, verify=False, headers=headers)
|
||||
except Exception as e:
|
||||
logging.debug('BAZARR notify Radarr')
|
||||
|
||||
|
|
Loading…
Reference in a new issue