2022-05-01 12:00:20 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from app.config import settings
|
2023-10-26 03:04:03 +00:00
|
|
|
from sonarr.info import url_api_sonarr
|
2022-05-01 12:00:20 +00:00
|
|
|
from constants import headers
|
|
|
|
|
|
|
|
|
|
|
|
def browse_sonarr_filesystem(path='#'):
|
|
|
|
if path == '#':
|
|
|
|
path = ''
|
2023-10-26 03:04:03 +00:00
|
|
|
url_sonarr_api_filesystem = (f"{url_api_sonarr()}filesystem?path={path}&allowFoldersWithoutTrailingSlashes=true&"
|
|
|
|
f"includeFiles=false&apikey={settings.sonarr.apikey}")
|
2022-05-01 12:00:20 +00:00
|
|
|
try:
|
2023-10-18 03:24:26 +00:00
|
|
|
r = requests.get(url_sonarr_api_filesystem, timeout=int(settings.sonarr.http_timeout), verify=False,
|
|
|
|
headers=headers)
|
2022-05-01 12:00:20 +00:00
|
|
|
r.raise_for_status()
|
|
|
|
except requests.exceptions.HTTPError:
|
|
|
|
logging.exception("BAZARR Error trying to get series from Sonarr. Http error.")
|
|
|
|
return
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
logging.exception("BAZARR Error trying to get series from Sonarr. Connection Error.")
|
|
|
|
return
|
|
|
|
except requests.exceptions.Timeout:
|
|
|
|
logging.exception("BAZARR Error trying to get series from Sonarr. Timeout Error.")
|
|
|
|
return
|
|
|
|
except requests.exceptions.RequestException:
|
|
|
|
logging.exception("BAZARR Error trying to get series from Sonarr.")
|
|
|
|
return
|
|
|
|
|
|
|
|
return r.json()
|