Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #
- ###################################################################################################
- ### SONARR POST-PROCESSING SCRIPT ###
- # ###
- # Script to force a rescanSeries on an 2nd instance of Sonarr. ###
- # ###
- # Example usecases are: ###
- # ###
- # 1) Fire & forget dual deployments ###
- # This bypasses the 12 hour discscan cycle and checks if new files are present on ### ###
- # the disc. This decreases unneeded grabs by the 2nd Sonarr instance. ###
- # ###
- # !!! Make sure to alter your log file location !!! ###
- # !!! Make sure to alter your API key !!! ###
- # !!! Make sure to alter your IP/port config !!! ###
- # ###
- ###################################################################################################
- from datetime import datetime
- from os import environ, path
- from sys import argv
- import json
- import urllib2
- ### Variables ###
- # Get the SeriesID from the environment variables or argv
- # Manual troubleshoot mode example command: python scriptname.py Arrow
- if len(argv) >= 2:
- sonarr_series_title = argv[1]
- else:
- sonarr_series_title = environ.get('sonarr_series_title')
- #Logfile location and open it unbuffered so you can read it during execution.
- fp = open('/volume1/Sonarr/update_2nd_sonarr.log', 'a',0)
- ### Processing script ###
- ### Grab the series ID from 2nd Sonarr instance ###
- #Accessing the URL and GET the series information from the 2nd Sonarr instance
- SeriesDump = json.load(urllib2.urlopen('http://192.168.0.1:8989/api/series?apikey=Your_API_Key'))
- #Extract the SeriesID from the API response
- for ID in SeriesDump:
- if ID["title"] == sonarr_series_title:
- SeriesID = ID["id"]
- break
- ### Trigger disc rescan on 2nd Sonarr Instance ###
- #JSON payload which command to perform
- data = {'name': 'rescanSeries', 'seriesId' : SeriesID}
- #Accessing the URL en POSTing the command
- req = urllib2.Request('http://192.168.0.1:8989/api/command?apikey=Your_API_Key')
- req.add_header('Content-Type', 'application/json')
- response = urllib2.urlopen(req, json.dumps(data))
- #Timestamp variable for logfile
- sttime = datetime.now().strftime('%Y%m%d %H:%M:%S - ')
- #Write to logfile
- fp.write(sttime + sonarr_series_title + ' was rescanned due to grab on 1st Sonarr instance.\n\n')
- fp.close()
- raise SystemExit
Advertisement
Add Comment
Please, Sign In to add comment