Major overhaul of nzbToMedia code base plus a whole restrucure

This commit is contained in:
echel0n 2014-04-03 03:04:04 -07:00
commit 85d8739512
67 changed files with 1687 additions and 1734 deletions

View file

@ -60,25 +60,32 @@
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
# Exit codes used by NZBGet
import logging
import os
import sys
from nzbtomedia.autoProcess.autoProcessComics import autoProcessComics
from nzbtomedia.migratecfg import migratecfg
from nzbtomedia.nzbToMediaConfig import config
from nzbtomedia.nzbToMediaUtil import nzbtomedia_configure_logging, WakeUp, get_dirnames
import autoProcess.migratecfg as migratecfg
import autoProcess.autoProcessComics as autoProcessComics
from autoProcess.nzbToMediaEnv import *
from autoProcess.nzbToMediaUtil import *
# run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options.
if migratecfg().migrate():
# check to write settings from nzbGet UI to autoProcessMedia.cfg.
if os.environ.has_key('NZBOP_SCRIPTDIR'):
migratecfg().addnzbget()
#check to migrate old cfg before trying to load.
if os.path.isfile(os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg.sample")):
migratecfg.migrate()
# check to write settings from nzbGet UI to autoProcessMedia.cfg.
if os.environ.has_key('NZBOP_SCRIPTDIR'):
migratecfg.addnzbget()
nzbtomedia_configure_logging(config.LOG_FILE)
Logger = logging.getLogger(__name__)
Logger.info("====================") # Seperate old from new log
Logger.info("nzbToMylar %s", config.NZBTOMEDIA_VERSION)
nzbtomedia_configure_logging(LOG_FILE)
Logger = logging.getLogger(__name__)
Logger.info("MAIN: Loading config from %s", config.CONFIG_FILE)
else:
sys.exit(-1)
Logger.info("====================") # Seperate old from new log
Logger.info("nzbToMylar %s", VERSION)
# mylar category
mlCategory = (config().get("Mylar", "mlCategory")).split(',') # tv
WakeUp()
@ -87,25 +94,18 @@ WakeUp()
if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5] < '11.0':
Logger.info("MAIN: Script triggered from NZBGet (11.0 or later).")
# NZBGet argv: all passed as environment variables.
# Exit codes used by NZBGet
POSTPROCESS_PARCHECK=92
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_NONE=95
# Check nzbget.conf options
status = 0
if os.environ['NZBOP_UNPACK'] != 'yes':
Logger.error("MAIN: Please enable option \"Unpack\" in nzbget configuration file, exiting")
sys.exit(POSTPROCESS_ERROR)
sys.exit(config.NZBGET_POSTPROCESS_ERROR)
# Check par status
if os.environ['NZBPP_PARSTATUS'] == '3':
Logger.warning("MAIN: Par-check successful, but Par-repair disabled, exiting")
Logger.info("MAIN: Please check your Par-repair settings for future downloads.")
sys.exit(POSTPROCESS_NONE)
sys.exit(config.NZBGET_POSTPROCESS_NONE)
if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4':
Logger.warning("MAIN: Par-repair failed, setting status \"failed\"")
@ -135,9 +135,9 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5
# All checks done, now launching the script.
Logger.info("MAIN: Script triggered from NZBGet, starting autoProcessComics...")
result = autoProcessComics.processEpisode(os.environ['NZBPP_DIRECTORY'], os.environ['NZBPP_NZBNAME'], status)
result = autoProcessComics().processEpisode(os.environ['NZBPP_DIRECTORY'], os.environ['NZBPP_NZBNAME'], status)
# SABnzbd Pre 0.7.17
elif len(sys.argv) == SABNZB_NO_OF_ARGUMENTS:
elif len(sys.argv) == config.SABNZB_NO_OF_ARGUMENTS:
# SABnzbd argv:
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file
@ -147,9 +147,9 @@ elif len(sys.argv) == SABNZB_NO_OF_ARGUMENTS:
# 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
Logger.info("MAIN: Script triggered from SABnzbd, starting autoProcessComics...")
result = autoProcessComics.processEpisode(sys.argv[1], sys.argv[3], sys.argv[7])
result = autoProcessComics().processEpisode(sys.argv[1], sys.argv[3], sys.argv[7])
# SABnzbd 0.7.17+
elif len(sys.argv) >= SABNZB_0717_NO_OF_ARGUMENTS:
elif len(sys.argv) >= config.SABNZB_0717_NO_OF_ARGUMENTS:
# SABnzbd argv:
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file
@ -160,17 +160,23 @@ elif len(sys.argv) >= SABNZB_0717_NO_OF_ARGUMENTS:
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
# 8 Failure URL
Logger.info("MAIN: Script triggered from SABnzbd 0.7.17+, starting autoProcessComics...")
result = autoProcessComics.processEpisode(sys.argv[1], sys.argv[3], sys.argv[7])
result = autoProcessComics().processEpisode(sys.argv[1], sys.argv[3], sys.argv[7])
else:
result = 0
Logger.warn("MAIN: Invalid number of arguments received from client.")
Logger.info("MAIN: Running autoProcessComics as a manual run...")
result = autoProcessComics.processEpisode('Manual Run', 'Manual Run', 0)
for dirName in get_dirnames("Mylar", mlCategory[0]):
Logger.info("MAIN: Calling Mylar to post-process: %s", dirName)
result = autoProcessComics().processEpisode(dirName, dirName, 0)
if result != 0: break
if result == 0:
Logger.info("MAIN: The autoProcessComics script completed successfully.")
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
sys.exit(POSTPROCESS_SUCCESS)
sys.exit(config.NZBGET_POSTPROCESS_SUCCESS)
else:
Logger.info("MAIN: A problem was reported in the autoProcessComics script.")
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
sys.exit(POSTPROCESS_ERROR)
sys.exit(config.NZBGET_POSTPROCESS_ERROR)