Skip to content

Commit

Permalink
finishing touches
Browse files Browse the repository at this point in the history
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
  • Loading branch information
michael committed Feb 21, 2015
1 parent b3d143d commit 4f35571
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
41 changes: 28 additions & 13 deletions NZBGetPostProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('"','')
Expand All @@ -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']
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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'])
Expand All @@ -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:
Expand All @@ -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)
4 changes: 2 additions & 2 deletions SABPostProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions autoProcess.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ password=
web_root=
ssl=0
api_key=
convert=True

[Sonarr]
host=localhost
Expand Down Expand Up @@ -56,7 +55,6 @@ apikey =
delay = 65
method = renamer
delete_failed = 0
convert=True

[uTorrent]
label=
Expand All @@ -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
22 changes: 15 additions & 7 deletions readSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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()
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4f35571

Please sign in to comment.