From 4f35571a20fce7932d00ee2204f69485b856d90c Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 21 Feb 2015 18:29:53 -0500 Subject: [PATCH] finishing touches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit included zybeon’s changes to nzbgetpostprocess allow ‘categories’ for nzbget and SAB to get set either from within NZBGet or in autoProcess.ini for SAB --- NZBGetPostProcess.py | 41 ++++++++++++++++++++++++++++------------- SABPostProcess.py | 4 ++-- autoProcess.ini.sample | 8 ++++++-- readSettings.py | 22 +++++++++++++++------- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/NZBGetPostProcess.py b/NZBGetPostProcess.py index 9c4ebb74..2666c961 100644 --- a/NZBGetPostProcess.py +++ b/NZBGetPostProcess.py @@ -16,12 +16,20 @@ # Convert file before passing to destination (True, False) #SHOULDCONVERT=False +# Category for Couchpotato +#CP_CAT=Couchpotato + +# Category for Sonarr +#SONARR_CAT=Sonarr + +# Category for Sickbeard +#SICK_CAT=Sickbeard + ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## import os, sys, re, json -import autoProcessMovie -import autoProcessTV + #Sanity checks for path string MP4folder = os.environ['NZBPO_MP4_FOLDER'].replace('"','') @@ -37,6 +45,8 @@ try: from readSettings import ReadSettings from mkvtomp4 import MkvtoMp4 + import autoProcessMovie + import autoProcessTV except ImportError: pass print "[ERROR] Wrong path to sickbeard_mp4_automator: "+os.environ['NZBPO_MP4_FOLDER'] @@ -52,7 +62,13 @@ nzb = os.environ['NZBPP_NZBFILENAME'] # Original NZB name category = os.environ['NZBPP_CATEGORY'] # NZB Category to determine destination #DEBUG#print "Category is %s", category - categories = ['sickbeard', 'couchpotato', 'sonarr'] + + couchcat = os.environ['NZBPO_CP_CAT'].lower() + sonarrcat = os.environ['NZBPO_SONARR_CAT'].lower() + sickcat = os.environ['NZBPO_SICK_CAT'].lower() + + categories = [sickcat, couchcat, sonarrcat] + # NZBGet argv: all passed as environment variables. clientAgent = "nzbget" # Exit codes used by NZBGet @@ -116,7 +132,7 @@ sys.exit(POSTPROCESS_NONE) # All checks done, now launching the script. - settings = ReadSettings(os.path.dirname(sys.argv[0]), MP4folder+"autoProcess.ini") + settings = ReadSettings(MP4folder, "autoProcess.ini") if shouldConvert: converted = 0 @@ -143,30 +159,29 @@ print "[WARNING] File conversion failed!" #DEBUG#print "%d of %d files converted", (converted, attempted) - if (category.lower() == cateories[0]): + if (category.lower() == categories[0]): #DEBUG#print "Sickbeard Processing Activated" autoProcessTV.processEpisode(path, settings, nzb) sys.exit(POSTPROCESS_SUCCESS) - elif (category.lower() == cateories[1]): + elif (category.lower() == categories[1]): #DEBUG#print "CouchPotato Processing Activated" autoProcessMovie.process(path, settings, nzb, status) sys.exit(POSTPROCESS_SUCCESS) - elif (category.lower() == cateories[2]): + elif (category.lower() == categories[2]): #DEBUG#print "Sonarr Processing Activated" - #Example:curl http://localhost:8989/api/command -X POST -d '{"name": "downloadedepisodesscan"}' --header "X-Api-Key:XXXXXXXXXXX" #Exit if missing requests module try: import requests except ImportError: print "[ERROR] Python module REQUESTS is required. Install with 'pip install requests' then try again." - sys.exit(0) + sys.exit(POSTPROCESS_ERROR) host=settings.Sonarr['host'] port=settings.Sonarr['port'] apikey = settings.Sonarr['apikey'] if apikey == '': - print "[WARNING] Your Sonarr API Key can not be blank. Update autoProcess.ini" + print "[WARNING] Your Sonarr API Key can not be blank. Update autoProcess.ini at %s" % MP4folder sys.exit(POSTPROCESS_ERROR) try: ssl=int(settings.Sonarr['ssl']) @@ -179,9 +194,9 @@ url = protocol+host+":"+port+"/api/command" payload = {'name': 'downloadedepisodesscan','path': path} print "[INFO] Requesting Sonarr to scan folder '"+path+"'" - headers = {'X-Api-Key': apikey} + #headers = {'X-Api-Key': apikey} try: - r = requests.post(url, data=json.dumps(payload), headers=headers) + r = requests.post(url, data=json.dumps(payload), headers={'X-Api-Key': apikey})#headers=headers) rstate = r.json() print "[INFO] Sonarr responds as "+rstate['state']+"." except: @@ -191,4 +206,4 @@ else: print "[ERROR] This script can only be called from NZBGet (11.0 or later)." - sys.exit(0) + sys.exit(0) \ No newline at end of file diff --git a/SABPostProcess.py b/SABPostProcess.py index f8b88b90..d74083cf 100644 --- a/SABPostProcess.py +++ b/SABPostProcess.py @@ -16,7 +16,7 @@ # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini") -categories = ['sickbeard', 'couchpotato', 'sonarr'] +categories = [settings.SAB['sb'], settings.SAB['cp'], settings.SAB['sonarr']] category = str(sys.argv[5]) if category.lower() not in categories: @@ -26,7 +26,7 @@ path = str(sys.argv[1]) nzb = str(sys.argv[2]) -if settings.Sickbeard['convert']: +if settings.SAB['convert']: print "Converting before passing" converter = MkvtoMp4(settings) converter.output_dir = None diff --git a/autoProcess.ini.sample b/autoProcess.ini.sample index bb7c98c6..790dec82 100644 --- a/autoProcess.ini.sample +++ b/autoProcess.ini.sample @@ -6,7 +6,6 @@ password= web_root= ssl=0 api_key= -convert=True [Sonarr] host=localhost @@ -56,7 +55,6 @@ apikey = delay = 65 method = renamer delete_failed = 0 -convert=True [uTorrent] label= @@ -66,3 +64,9 @@ action_after=removedata host=http://localhost:8080/ username= password= + +[SABNZBD] +convert=True +Sickbeard-category=sickbeard +Couchpotato-category=couchpotato +Sonarr-category=sonarr diff --git a/readSettings.py b/readSettings.py index 69d6cc77..40129cf9 100644 --- a/readSettings.py +++ b/readSettings.py @@ -22,8 +22,7 @@ def __init__(self, directory, filename): sb_defaults = {'host': 'localhost', 'port': '8081', 'ssl': "False", - 'api_key': '', - 'convert': 'True' } + 'api_key': '' } # Default MP4 conversion settings mp4_defaults = {'ffmpeg': 'ffmpeg.exe', 'ffprobe': 'ffprobe.exe', @@ -64,8 +63,7 @@ def __init__(self, directory, filename): 'method': 'renamer', 'delete_failed': 'False', 'ssl': 'False', - 'web_root': '', - 'convert': 'True' } + 'web_root': '' } # Default settings for Sonarr sonarr_defaults = {'host': 'localhost', 'port': '8989', @@ -80,8 +78,13 @@ def __init__(self, directory, filename): 'host': 'http://localhost:8080/', 'username': '', 'password': ''} + # Default SAB settings + sab_defaults = { 'convert': 'True', + 'Sickbeard-category': 'sickbeard', + 'Couchpotato-category': 'couchpotato', + 'Sonarr-category': 'sonarr' } - defaults = {'SickBeard': sb_defaults, 'CouchPotato': cp_defaults, 'Sonarr': sonarr_defaults, 'MP4': mp4_defaults, 'uTorrent': utorrent_defaults} + defaults = {'SickBeard': sb_defaults, 'CouchPotato': cp_defaults, 'Sonarr': sonarr_defaults, 'MP4': mp4_defaults, 'uTorrent': utorrent_defaults, 'SABNZBD': sab_defaults} write = False # Will be changed to true if a value is missing from the config file and needs to be written config = ConfigParser.SafeConfigParser() @@ -284,7 +287,6 @@ def __init__(self, directory, filename): self.CP['delay'] = config.get(section, "delay") self.CP['method'] = config.get(section, "method") self.CP['web_root'] = config.get(section, "web_root") - self.CP['convert'] = config.getboolean(section, "convert") try: self.CP['delay'] = float(self.CP['delay']) @@ -326,7 +328,6 @@ def __init__(self, directory, filename): #Read Sickbeard section information section = "SickBeard" self.Sickbeard = {} - self.Sickbeard['convert'] = config.get(section, "convert") # Convert self.Sickbeard['host'] = config.get(section, "host") # Server Address self.Sickbeard['port'] = config.get(section, "port") # Server Port self.Sickbeard['api_key'] = config.get(section, "api_key") # Sickbeard API key @@ -335,6 +336,13 @@ def __init__(self, directory, filename): self.Sickbeard['user'] = config.get(section, "username") self.Sickbeard['pass'] = config.get(section, "password") + section = "SABNZBD" + self.SAB = {} + self.SAB['convert'] = config.getboolean(section, "convert") # Convert + self.SAB['cp'] = config.get(section, "Couchpotato-category").lower() + self.SAB['sb'] = config.get(section, "Sickbeard-category").lower() + self.SAB['sonarr'] = config.get(section, "Sonarr-category").lower() + #Pass the values on self.config = config self.configFile = configFile