Skip to content

Commit f95f25f

Browse files
committed
fix: continue using legacy api for Sonarr v3
1 parent 935ebc5 commit f95f25f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

sonarr.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,38 @@ def __init__(self, api_url, api_key, verbose=False):
2222
self.logger.error(
2323
"Invalid Sonarr URL detected. Please update your settings to include http:// or https:// on the beginning of the URL."
2424
)
25-
self.api_url = api_url + "/api/v3/{endpoint}?apikey=" + api_key
25+
self.sonarr_version = self.discover_version(api_url, api_key)
26+
if not self.sonarr_version.startswith("4."):
27+
self.api_url = api_url + "/api/{endpoint}?apikey=" + api_key
2628
self._quality_profiles = self.get_all_quality_profiles()
2729
self._root_folders = self.get_root_folders()
2830
self._all_series = {}
2931
self.get_all_series()
3032

33+
def discover_version(self, api_url, api_key):
34+
try:
35+
self.api_url = api_url + "/api/v3/{endpoint}?apikey=" + api_key
36+
sonarrInfo = self._api_get("system/status")
37+
self.logger.debug(
38+
f"Discovered Sonarr version {sonarrInfo.get('version')} using v3 api."
39+
)
40+
return sonarrInfo.get("version")
41+
except requests.exceptions.HTTPError as e:
42+
self.logger.debug(f"Sonarr v3 API threw exception: {e}")
43+
44+
try:
45+
self.api_url = api_url + "/api/{endpoint}?apikey=" + api_key
46+
sonarrInfo = self._api_get("system/status")
47+
self.logger.warning(
48+
f"Discovered Sonarr version {sonarrInfo.get('version')}. Using legacy API. Consider upgrading to the latest version of Radarr for the best experience."
49+
)
50+
return sonarrInfo.get("version")
51+
except requests.exceptions.HTTPError as e:
52+
self.logger.debug(f"Sonarr legacy API threw exception: {e}")
53+
54+
self.logger.debug("Failed to discover Sonarr version")
55+
return None
56+
3157
def lookup_series(self, title=None, tvdb_id=None):
3258
r = self._api_get(
3359
"series/lookup", {"term": f"tvdb:{tvdb_id}" if tvdb_id else quote(title)}

0 commit comments

Comments
 (0)