Skip to content

Commit 8d36c41

Browse files
authored
Merge pull request #17 from burkasaurusrex/master
Add 'add_movie' option to Radarr config
2 parents 76f9fe6 + a67ec8e commit 8d36c41

File tree

5 files changed

+55
-30
lines changed

5 files changed

+55
-30
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ collections:
110110
- https://trakt.tv/users/2borno2b/lists/christmas-movies-extravanganza
111111
Marvel:
112112
trakt-list: https://trakt.tv/users/movistapp/lists/marvel
113+
Pixar:
114+
studio: Pixar
115+
details:
116+
summary: A collection of Pixar movies
117+
1990s:
118+
year: [1990,1991,1992,1993,1994,1995,1996,1997,1998,1999]
119+
details:
120+
summary: A collection of 1990s movies
113121
plex:
114122
library: Movies
115123
library_type: movie # or 'show'
@@ -120,7 +128,8 @@ radarr:
120128
token: ################
121129
quality_profile_id: 4
122130
root_folder_path: /mnt/user/PlexMedia/movies
123-
search: true
131+
add_movie: false
132+
search_movie: false
124133
tmdb:
125134
apikey: ################
126135
language: en

config.yml.template

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ collections:
1616
tmdb-summary: 4169
1717
Marvel:
1818
trakt-list: https://trakt.tv/users/movistapp/lists/marvel
19+
Pixar:
20+
studio: Pixar
21+
details:
22+
summary: A collection of Pixar movies
23+
1990s:
24+
year: [1990,1991,1992,1993,1994,1995,1996,1997,1998,1999]
25+
details:
26+
summary: A collection of 1990s movies
1927
plex:
2028
library: Movies
2129
library_type: ### 'movie' or 'show' ###
@@ -26,7 +34,8 @@ radarr:
2634
token: ###########################
2735
quality_profile_id: 4
2836
root_folder_path: /mnt/user/PlexMedia/movies
29-
search: false
37+
add_movie: false
38+
search_movie: false
3039
tmdb:
3140
apikey: ############################
3241
language: en

config_tools.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,20 @@ def __init__(self, config_path):
5656
config = Config(config_path).radarr
5757
self.url = config['url']
5858
self.token = config['token']
59-
self.quality = config['quality_profile_id']
60-
59+
self.quality_profile_id = config['quality_profile_id']
60+
self.root_folder_path = config['root_folder_path']
61+
# Set 'add_movie' to None if not set
62+
if 'add_movie' in config:
63+
self.add_movie = config['add_movie']
64+
else:
65+
self.add_movie = None
66+
# Support synonyms 'search_movie' and 'search'; add logical default to False
67+
if 'search_movie' in config:
68+
self.search_movie = config['search_movie']
69+
elif 'search' in config:
70+
self.search_movie = config['search']
71+
else:
72+
self.search_movie = False
6173

6274
class TMDB:
6375
def __init__(self, config_path):
@@ -92,7 +104,7 @@ def __init__(self, config_path):
92104
except:
93105
a = 1
94106

95-
def update_from_config(config_path, plex, skip_radarr=False):
107+
def update_from_config(config_path, plex):
96108
config = Config(config_path)
97109
collections = config.collections
98110
if isinstance(plex.Library, MovieSection):
@@ -137,7 +149,11 @@ def update_from_config(config_path, plex, skip_radarr=False):
137149
else:
138150
method_name = "TMDb"
139151
print("{} missing movies from {} List: {}".format(len(missing), method_name, v))
140-
if not skip_radarr:
152+
if 'add_movie' in config.radarr:
153+
if config.radarr['add_movie'] is True:
154+
print("Adding missing movies to Radarr")
155+
add_to_radarr(config_path, missing)
156+
else:
141157
if input("Add missing movies to Radarr? (y/n): ").upper() == "Y":
142158
add_to_radarr(config_path, missing)
143159
elif libtype == "show":

radarr_tools.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
import re, requests, os, yaml
2+
import config_tools
23
from tmdbv3api import TMDb
34
from tmdbv3api import Movie
45

56
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)
89

910
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
2513

2614
movie = Movie()
2715
for m in missing:
@@ -31,18 +19,18 @@ def add_to_radarr(config_path, missing):
3119
tmdb_title = tmdb_details['title']
3220
tmdb_id = tmdb_details['id']
3321
except IndexError:
34-
print("Unable to fetch necessary external information")
22+
print("Unable to fetch necessary external information, skipping")
3523
continue
3624

3725
# Validate TMDb year (several TMDb entries don't yet have release dates)
3826
try:
3927
tmdb_year = tmdb_details['release_date'].split("-")[0]
4028
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")
4230
continue
4331

4432
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")
4634
continue
4735

4836
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):
5442

5543
payload = {
5644
"title": tmdb_title,
57-
"qualityProfileId": quality,
45+
"qualityProfileId": config_radarr.quality_profile_id,
5846
"year": int(tmdb_year),
5947
"tmdbid": str(tmdb_id),
6048
"titleslug": titleslug,
6149
"monitored": "true",
62-
"rootFolderPath": rootfolder,
50+
"rootFolderPath": config_radarr.root_folder_path,
6351
"images": [{
6452
"covertype": "poster",
6553
"url": tmdb_poster
6654
}],
6755
"addOptions": {
68-
"searchForMovie": search
56+
"searchForMovie": config_radarr.search_movie
6957
}
7058
}
7159

60+
url = config_radarr.url + "/api/movie"
61+
querystring = {"apikey": "{}".format(config_radarr.token)}
62+
7263
response = requests.post(url, json=payload, params=querystring)
7364

7465
try:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PyYAML==5.1.2
22
tmdbv3api
33
lxml
4-
requests
4+
requests>=2.4.2
55
flask
66
git+git://github.com/pkkid/python-plexapi.git#egg=plexapi
77
trakt.py

0 commit comments

Comments
 (0)