Updated logger code to now include the section, formatting has been modified as well.

Logging of debug messages is now optional via log_debug option location in autoProcessMedia.cfg

Lots of code cleanup has been performed including cleanup log messages and corrections of spelling errors.

Improved release lookup code for autoProcessMovie, narrows search results down by making API calls to the download clients to compare results in CouchPotato's database.
This commit is contained in:
echel0n 2014-04-18 13:16:18 -07:00
commit eb7822b60b
16 changed files with 420 additions and 441 deletions

View file

@ -286,27 +286,25 @@ from nzbtomedia import logger
# post-processing
def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None):
result = 0
# auto-detect section
section = nzbtomedia.CFG.findsection(inputCategory)
if section:
logger.info("Sending %s to %s for post-processing ..." % (inputName, str(section).upper()))
else:
logger.error("We could not find a section with containing a download category labeled %s in your autoProcessMedia.cfg, Exiting!" % inputCategory)
if nzbtomedia.CFG["CouchPotato"][inputCategory]:
logger.postprocess("Calling CouchPotatoServer to post-process: %s", inputName)
result = autoProcessMovie().process(nzbDir, inputName, status, clientAgent, download_id, inputCategory)
elif nzbtomedia.CFG["SickBeard", "NzbDrone"][inputCategory]:
logger.postprocess("Calling Sick-Beard to post-process: %s", inputName)
result = autoProcessTV().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
elif nzbtomedia.CFG["HeadPhones"][inputCategory]:
logger.postprocess("Calling HeadPhones to post-process: %s", inputName)
result = autoProcessMusic().process(nzbDir, inputName, status, clientAgent, inputCategory)
elif nzbtomedia.CFG["Mylar"][inputCategory]:
logger.postprocess("Calling Mylar to post-process: %s", inputName)
result = autoProcessComics().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
elif nzbtomedia.CFG["Gamez"][inputCategory]:
logger.postprocess("Calling Gamez to post-process: %s", inputName)
result = autoProcessGames().process(nzbDir, inputName, status, clientAgent, inputCategory)
else:
logger.postprocess("We could not find a section with the download category of %s in your autoProcessMedia.cfg. Exiting.", inputCategory)
result = -1
if result == 0:
# Clean up any leftover files
@ -321,22 +319,21 @@ def main(args, section=None):
# clientAgent for NZBs
clientAgent = nzbtomedia.NZB_CLIENTAGENT
logger.postprocess("#########################################################")
logger.postprocess("## ..::[%s]::.. CLIENT:%s ## STARTING", args[0], clientAgent)
logger.postprocess("#########################################################")
logger.info("#########################################################")
logger.info("## ..::[%s]::.. ##" % os.path.basename(__file__))
logger.info("#########################################################")
# debug command line options
logger.debug("Options passed into nzbToMedia: %s", args)
logger.debug("Options passed into nzbToMedia: %s" % args)
# Post-Processing Result
result = 0
status = 0
# NZBGet V11+
# Check if the script is called from nzbget 11.0 or later
if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5] < '11.0':
logger.postprocess("Script triggered from NZBGet (11.0 or later).")
logger.info("Script triggered from NZBGet (11.0 or later).")
if os.environ['NZBOP_UNPACK'] != 'yes':
logger.error("Please enable option \"Unpack\" in nzbget configuration file, exiting")
@ -345,7 +342,7 @@ def main(args, section=None):
# Check par status
if os.environ['NZBPP_PARSTATUS'] == '3':
logger.warning("Par-check successful, but Par-repair disabled, exiting")
logger.postprocess("Please check your Par-repair settings for future downloads.")
logger.info("Please check your Par-repair settings for future downloads.")
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_NONE)
if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4':
@ -362,16 +359,16 @@ def main(args, section=None):
if os.environ['NZBPP_HEALTH'] < 1000:
logger.warning("Download health is compromised and Par-check/repair disabled or no .par2 files found. Setting status \"failed\"")
logger.postprocess("Please check your Par-check/repair settings for future downloads.")
logger.info("Please check your Par-check/repair settings for future downloads.")
status = 1
else:
logger.postprocess("Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful")
logger.postprocess("Please check your Par-check/repair settings for future downloads.")
logger.info("Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful")
logger.info("Please check your Par-check/repair settings for future downloads.")
# Check if destination directory exists (important for reprocessing of history items)
if not os.path.isdir(os.environ['NZBPP_DIRECTORY']):
logger.error("Nothing to post-process: destination directory %s doesn't exist. Setting status \"failed\"", os.environ['NZBPP_DIRECTORY'])
logger.error("Nothing to post-process: destination directory %s doesn't exist. Setting status failed" % (os.environ['NZBPP_DIRECTORY']))
status = 1
# Check for download_id to pass to CouchPotato
@ -393,7 +390,7 @@ def main(args, section=None):
# 6 Group that the NZB was posted in e.g. alt.binaries.x
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
clientAgent = 'sabnzbd'
logger.postprocess("Script triggered from SABnzbd")
logger.info("Script triggered from SABnzbd")
result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent=clientAgent, download_id='')
# SABnzbd 0.7.17+
elif len(args) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS:
@ -407,7 +404,7 @@ def main(args, section=None):
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
# 8 Failure URL
clientAgent = 'sabnzbd'
logger.postprocess("Script triggered from SABnzbd 0.7.17+")
logger.info("Script triggered from SABnzbd 0.7.17+")
result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent=clientAgent, download_id='')
else:
# Perform Manual Run
@ -420,21 +417,20 @@ def main(args, section=None):
if nzbtomedia.CFG[section][category].isenabled():
dirNames = get_dirnames(section, category)
for dirName in dirNames:
logger.postprocess("nzbToMedia running %s:%s as a manual run on folder %s ...", section, category, dirName)
logger.info("Starting manual run for %s:%s - Folder:%s" % (section, category, dirName))
results = process(dirName, os.path.basename(dirName), 0, clientAgent=clientAgent, inputCategory=category)
if results != 0:
logger.error("A problem was reported when trying to manually run %s:%s.", section, category)
logger.error("A problem was reported when trying to perform a manual run for %s:%s." % (section, category))
result = results
else:
logger.postprocess("nzbToMedia %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category)
logger.debug("nzbToMedia %s:%s is DISABLED" % (section, category))
if result == 0:
logger.postprocess("The %s script completed successfully.", args[0])
logger.info("The %s script completed successfully." % args[0])
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS)
else:
logger.error("A problem was reported in the %s script.", args[0])
logger.error("A problem was reported in the %s script." % args[0])
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR)