Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#48: update script to support Radarr API v3 and above #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
url = https://example.com:443
key = FCKGW-RHQQ2-YXRKT-8TG6W-2B7Q8

# Radarr API version (if you are using an old version of Radarr, you may be able to comment out this line)
version = 3

[Radarr4k]
url = http://127.0.0.1:8080
key = FCKGW-RHQQ2-YXRKT-8TG6W-2B7Q8

# Radarr API version (if you are using an old version of Radarr, you may be able to comment out this line)
version = 3

# Use these two lines to perform a string replacemnet on the movie path
path_from = '/Movies/'
path_to = '/4k Movies/'
Expand Down
29 changes: 14 additions & 15 deletions RadarrSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def ConfigSectionMap(section):
dict1[option] = None
return dict1

logger.debug('RadarSync Version {}'.format(VER))
logger.debug('RadarrSync Version {}'.format(VER))
Config = configparser.ConfigParser()

# Loads an alternate config file so that I can work on my servers without uploading config to github
Expand All @@ -51,9 +51,11 @@ def ConfigSectionMap(section):

radarr_url = ConfigSectionMap("Radarr")['url']
radarr_key = ConfigSectionMap("Radarr")['key']
radarr_version = ConfigSectionMap("Radarr")['version']
radarr_version_fragment = '/v'+radarr_version if radarr_version else ''
radarrSession = requests.Session()
radarrSession.trust_env = False
radarrMovies = radarrSession.get('{0}/api/movie?apikey={1}'.format(radarr_url, radarr_key))
radarrMovies = radarrSession.get('{0}/api{1}/movie?apikey={2}'.format(radarr_url, radarr_version_fragment, radarr_key))
if radarrMovies.status_code != 200:
logger.error('Radarr server error - response {}'.format(radarrMovies.status_code))
sys.exit(0)
Expand All @@ -71,7 +73,9 @@ def ConfigSectionMap(section):
SyncServer_url = ConfigSectionMap(server)['url']
SyncServer_key = ConfigSectionMap(server)['key']
SyncServer_target_profile = ConfigSectionMap(server)['target_profile']
SyncServerMovies = session.get('{0}/api/movie?apikey={1}'.format(SyncServer_url, SyncServer_key))
SyncServer_version = ConfigSectionMap(server)['version']
SyncServer_version_fragment = '/v'+SyncServer_version if SyncServer_version else ''
SyncServerMovies = session.get('{0}/api{1}/movie?apikey={2}'.format(SyncServer_url, SyncServer_version_fragment, SyncServer_key))
if SyncServerMovies.status_code != 200:
logger.error('4K Radarr server error - response {}'.format(SyncServerMovies.status_code))
sys.exit(0)
Expand All @@ -86,9 +90,8 @@ def ConfigSectionMap(section):
#logger.debug('found movie to be added')

newMovies = 0
searchid = []
for movie in radarrMovies.json():
if movie['profileId'] == int(ConfigSectionMap(server)['profile']):
if movie['qualityProfileId'] == int(ConfigSectionMap(server)['profile']):
if movie['tmdbId'] not in movieIds_to_syncserver:
logging.debug('title: {0}'.format(movie['title']))
logging.debug('qualityProfileId: {0}'.format(movie['qualityProfileId']))
Expand All @@ -106,19 +109,20 @@ def ConfigSectionMap(section):
path = path.replace(ConfigSectionMap(server)['path_from'], ConfigSectionMap(server)['path_to'])

payload = {'title': movie['title'],
'qualityProfileId': movie['qualityProfileId'],
'qualityProfileId': SyncServer_target_profile,
'titleSlug': movie['titleSlug'],
'tmdbId': movie['tmdbId'],
'path': path,
'monitored': movie['monitored'],
'images': images,
'profileId': SyncServer_target_profile,
'minimumAvailability': 'released'
'minimumAvailability': 'released',
'addOptions': {'searchForMovie': True}
}

r = session.post('{0}/api/movie?apikey={1}'.format(SyncServer_url, SyncServer_key), data=json.dumps(payload))
searchid.append(int(r.json()['id']))
logger.info('adding {0} to {1} server'.format(movie['title'], server))
r = session.post('{0}/api{1}/movie?apikey={2}'.format(SyncServer_url, SyncServer_version_fragment, SyncServer_key), data=json.dumps(payload), headers={'Content-Type': 'application/json'})
if r.status_code >= 300:
logger.error('Error adding movie to 4K Radarr server - response {}'.format(r.status_code))
else:
logging.debug('{0} already in {1} library'.format(movie['title'], server))
else:
Expand All @@ -128,8 +132,3 @@ def ConfigSectionMap(section):
))



if len(searchid):
payload = {'name' : 'MoviesSearch', 'movieIds' : searchid}
session.post('{0}/api/command?apikey={1}'.format(SyncServer_url, SyncServer_key), data=json.dumps(payload))