1
1
import re , requests , os , yaml
2
+ import config_tools
2
3
from tmdbv3api import TMDb
3
4
from tmdbv3api import Movie
4
5
5
6
def add_to_radarr (config_path , missing ):
6
- # config_path = os.path.join(os.getcwd(), 'config.yml' )
7
- config = yaml . load ( open ( config_path ), Loader = yaml . FullLoader )
7
+ config_tmdb = config_tools . TMDB ( config_path )
8
+ config_radarr = config_tools . Radarr ( config_path )
8
9
9
10
tmdb = TMDb ()
10
- tmdb .api_key = config ['tmdb' ]['apikey' ]
11
- tmdb .language = "en"
12
-
13
- url = config ['radarr' ]['url' ] + "/api/movie"
14
- token = config ['radarr' ]['token' ]
15
- quality = config ['radarr' ]['quality_profile_id' ]
16
- rootfolder = config ['radarr' ]['root_folder_path' ]
17
- search = config ['radarr' ]['search' ]
18
- querystring = {"apikey" : "{}" .format (token )}
19
-
20
- if "None" in (tmdb .api_key , url , token , quality , rootfolder ):
21
- print ("All TMDB / Radarr details must be filled out in the configuration "
22
- "file to import missing movies into Radarr" )
23
- print ("\n " )
24
- return
11
+ tmdb .api_key = config_tmdb .apikey
12
+ tmdb .language = config_tmdb .language
25
13
26
14
movie = Movie ()
27
15
for m in missing :
@@ -31,18 +19,18 @@ def add_to_radarr(config_path, missing):
31
19
tmdb_title = tmdb_details ['title' ]
32
20
tmdb_id = tmdb_details ['id' ]
33
21
except IndexError :
34
- print ("Unable to fetch necessary external information" )
22
+ print ("Unable to fetch necessary external information, skipping " )
35
23
continue
36
24
37
25
# Validate TMDb year (several TMDb entries don't yet have release dates)
38
26
try :
39
27
tmdb_year = tmdb_details ['release_date' ].split ("-" )[0 ]
40
28
except KeyError :
41
- print (tmdb_title + " does not have a release date yet" )
29
+ print (tmdb_title + " does not have a release date yet, skipping " )
42
30
continue
43
31
44
32
if tmdb_year .isdigit () == False :
45
- print (tmdb_title + " does not have a release date yet" )
33
+ print (tmdb_title + " does not have a release date yet, skipping " )
46
34
continue
47
35
48
36
tmdb_poster = "https://image.tmdb.org/t/p/original{}" .format (tmdb_details ['poster_path' ])
@@ -54,21 +42,24 @@ def add_to_radarr(config_path, missing):
54
42
55
43
payload = {
56
44
"title" : tmdb_title ,
57
- "qualityProfileId" : quality ,
45
+ "qualityProfileId" : config_radarr . quality_profile_id ,
58
46
"year" : int (tmdb_year ),
59
47
"tmdbid" : str (tmdb_id ),
60
48
"titleslug" : titleslug ,
61
49
"monitored" : "true" ,
62
- "rootFolderPath" : rootfolder ,
50
+ "rootFolderPath" : config_radarr . root_folder_path ,
63
51
"images" : [{
64
52
"covertype" : "poster" ,
65
53
"url" : tmdb_poster
66
54
}],
67
55
"addOptions" : {
68
- "searchForMovie" : search
56
+ "searchForMovie" : config_radarr . search_movie
69
57
}
70
58
}
71
59
60
+ url = config_radarr .url + "/api/movie"
61
+ querystring = {"apikey" : "{}" .format (config_radarr .token )}
62
+
72
63
response = requests .post (url , json = payload , params = querystring )
73
64
74
65
try :
0 commit comments