2019-08-26 03:17:01 +00:00
|
|
|
import re, json, requests, os, yaml
|
|
|
|
from tmdbv3api import TMDb
|
|
|
|
from tmdbv3api import Movie
|
|
|
|
|
2019-12-28 10:55:36 +00:00
|
|
|
def add_to_radarr(config_path, missing):
|
|
|
|
# config_path = os.path.join(os.getcwd(), 'config.yml')
|
2019-08-26 03:17:01 +00:00
|
|
|
config = yaml.load(open(config_path), Loader=yaml.FullLoader)
|
|
|
|
|
|
|
|
tmdb = TMDb()
|
|
|
|
tmdb.api_key = config['tmdb']['apikey']
|
|
|
|
tmdb.language = "en"
|
|
|
|
|
|
|
|
url = config['radarr']['url'] + "/api/movie"
|
|
|
|
token = config['radarr']['token']
|
2020-04-19 11:40:01 +00:00
|
|
|
quality = config['radarr']['quality_profile_id']
|
|
|
|
rootfolder = config['radarr']['root_folder_path']
|
2019-08-26 04:32:22 +00:00
|
|
|
search = config['radarr']['search']
|
2019-08-26 03:17:01 +00:00
|
|
|
querystring = {"apikey": "{}".format(token)}
|
|
|
|
|
2020-04-19 11:40:01 +00:00
|
|
|
if "None" in (tmdb.api_key, url, token, quality, rootfolder):
|
2019-08-26 03:17:01 +00:00
|
|
|
print("All TMDB / Radarr details must be filled out in the configuration "
|
|
|
|
"file to import missing movies into Radarr")
|
|
|
|
print("\n")
|
|
|
|
return
|
|
|
|
|
|
|
|
movie = Movie()
|
|
|
|
for m in missing:
|
|
|
|
tmdb_details = movie.external(external_id=str(m), external_source="imdb_id")['movie_results'][0]
|
|
|
|
|
|
|
|
tmdb_title = tmdb_details['title']
|
|
|
|
tmdb_year = tmdb_details['release_date'].split("-")[0]
|
|
|
|
tmdb_id = tmdb_details['id']
|
|
|
|
tmdb_poster = "https://image.tmdb.org/t/p/original{}".format(tmdb_details['poster_path'])
|
|
|
|
|
|
|
|
titleslug = "{} {}".format(tmdb_title, tmdb_year)
|
|
|
|
titleslug = re.sub(r'([^\s\w]|_)+', '', titleslug)
|
|
|
|
titleslug = titleslug.replace(" ", "-")
|
|
|
|
titleslug = titleslug.lower()
|
|
|
|
|
|
|
|
payload = {
|
|
|
|
"title": tmdb_title,
|
|
|
|
"qualityProfileId": quality,
|
|
|
|
"year": int(tmdb_year),
|
|
|
|
"tmdbid": str(tmdb_id),
|
|
|
|
"titleslug": titleslug,
|
|
|
|
"monitored": "true",
|
2020-04-19 11:40:01 +00:00
|
|
|
"rootFolderPath": rootfolder,
|
2019-08-26 03:17:01 +00:00
|
|
|
"images": [{
|
|
|
|
"covertype": "poster",
|
|
|
|
"url": tmdb_poster
|
2019-08-26 04:32:22 +00:00
|
|
|
}],
|
|
|
|
"addOptions": {
|
|
|
|
"searchForMovie": search
|
|
|
|
}
|
2019-08-26 03:17:01 +00:00
|
|
|
}
|
|
|
|
headers = {
|
|
|
|
'Content-Type': "application/json",
|
|
|
|
'cache-control': "no-cache",
|
|
|
|
'Postman-Token': "0eddcc07-12ba-49d3-9756-3aa8256deaf3"
|
|
|
|
}
|
|
|
|
|
|
|
|
response = requests.request("POST", url, data=json.dumps(payload), headers=headers, params=querystring)
|
|
|
|
r_json = json.loads(response.text)
|
|
|
|
|
|
|
|
try:
|
|
|
|
if r_json[0]['errorMessage'] == "This movie has already been added":
|
|
|
|
print(tmdb_title + " already added to Radarr")
|
|
|
|
except KeyError:
|
2019-12-28 10:55:36 +00:00
|
|
|
print("+++ " + tmdb_title + " added to Radarr")
|