-
Notifications
You must be signed in to change notification settings - Fork 58
/
radarr_tools.py
executable file
·68 lines (58 loc) · 2.42 KB
/
radarr_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import re, json, requests, os, yaml
from tmdbv3api import TMDb
from tmdbv3api import Movie
def add_to_radarr(missing):
config_path = os.path.join(os.getcwd(), 'config.yml')
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"
quality = config['radarr']['quality_profile_id']
token = config['radarr']['token']
search = config['radarr']['search']
querystring = {"apikey": "{}".format(token)}
if "None" in (tmdb.api_key, url, quality, token):
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",
"rootFolderPath": "//mnt//user//PlexMedia//movies",
"images": [{
"covertype": "poster",
"url": tmdb_poster
}],
"addOptions": {
"searchForMovie": search
}
}
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:
print("+++ " + tmdb_title + " added to Radarr")