Add support for Radarr v3 API

This commit is contained in:
burkasaurusrex 2020-07-25 06:17:09 -06:00
parent 4ce154d8ec
commit 66ae96298a
2 changed files with 30 additions and 9 deletions

View file

@ -26,9 +26,22 @@ class Config:
self.data = yaml.load(yml, Loader=yaml.FullLoader) self.data = yaml.load(yml, Loader=yaml.FullLoader)
self.collections = self.data['collections'] self.collections = self.data['collections']
self.plex = self.data['plex'] self.plex = self.data['plex']
self.tmdb = self.data['tmdb'] # Make 'tmdb' key optional
self.trakt = self.data['trakt'] if 'tmdb' in self.data:
self.radarr = self.data['radarr'] self.tmdb = self.data['tmdb']
else:
self.tmdb = {}
# Make 'trakt' key optional
if 'trakt' in self.data:
self.trakt = self.data['trakt']
else:
self.trakt = {}
# Make 'radarr' key optional
if 'radarr' in self.data:
self.radarr = self.data['radarr']
else:
self.radarr = {}
# Make 'image-server' key optional
if 'image-server' in self.data: if 'image-server' in self.data:
self.image_server = self.data['image-server'] self.image_server = self.data['image-server']
else: else:
@ -59,6 +72,11 @@ class Radarr:
def __init__(self, config_path): def __init__(self, config_path):
config = Config(config_path).radarr config = Config(config_path).radarr
self.url = config['url'] self.url = config['url']
# Set 'version' to v2 if not set
if 'version' in config:
self.version = config['version']
else:
self.version = "v2"
self.token = config['token'] self.token = config['token']
self.quality_profile_id = config['quality_profile_id'] self.quality_profile_id = config['quality_profile_id']
self.root_folder_path = config['root_folder_path'] self.root_folder_path = config['root_folder_path']

View file

@ -57,13 +57,16 @@ def add_to_radarr(config_path, missing):
} }
} }
url = config_radarr.url + "/api/movie" if config_radarr.version == "v3":
slug = "/api/v3/movie"
else:
slug = "/api/movie"
url = config_radarr.url + slug
querystring = {"apikey": "{}".format(config_radarr.token)} querystring = {"apikey": "{}".format(config_radarr.token)}
response = requests.post(url, json=payload, params=querystring) response = requests.post(url, json=payload, params=querystring)
try: if response.status_code < 400:
if response.json()[0]['errorMessage'] == "This movie has already been added": print("+++ " + tmdb_title + ": Added to Radarr")
print(tmdb_title + " already added to Radarr") else:
except KeyError: print("--- " + tmdb_title + ": " + response.json()[0]['errorMessage'])
print("+++ " + tmdb_title + " added to Radarr")