mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 21:33:13 -07:00
Massive changes to the way we handle our config, its now loaded and stored in memory so that we don't keep loading it and possibly get corrupt values.
New logger class added,logger options removed from settings.
This commit is contained in:
parent
d8a3bdb7dc
commit
18926d1db8
30 changed files with 1603 additions and 1058 deletions
117
nzbToMedia.py
117
nzbToMedia.py
|
@ -1,10 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# adds lib directory to system path
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib')))
|
||||
|
||||
#
|
||||
##############################################################################
|
||||
### NZBGET POST-PROCESSING SCRIPT ###
|
||||
|
@ -305,57 +299,44 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib'
|
|||
|
||||
### NZBGET POST-PROCESSING SCRIPT ###
|
||||
##############################################################################
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import nzbtomedia
|
||||
from nzbtomedia.autoProcess.autoProcessComics import autoProcessComics
|
||||
from nzbtomedia.autoProcess.autoProcessGames import autoProcessGames
|
||||
from nzbtomedia.autoProcess.autoProcessMovie import autoProcessMovie
|
||||
from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic
|
||||
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
||||
from nzbtomedia.nzbToMediaConfig import config
|
||||
from nzbtomedia.nzbToMediaUtil import nzbtomedia_configure_logging, WakeUp, get_dirnames
|
||||
from nzbtomedia.nzbToMediaUtil import get_dirnames
|
||||
from nzbtomedia import logger
|
||||
|
||||
# post-processing
|
||||
def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None):
|
||||
|
||||
if config()["CouchPotato"].issubsection(inputCategory):
|
||||
Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName)
|
||||
if nzbtomedia.CFG["CouchPotato"].issubsection(inputCategory):
|
||||
logger.postprocess("Calling CouchPotatoServer to post-process: %s", logger.MESSAGE), inputName
|
||||
return autoProcessMovie().process(nzbDir, inputName, status, clientAgent, download_id, inputCategory)
|
||||
elif config()["SickBeard", "NzbDrone"].issubsection(inputCategory):
|
||||
Logger.info("MAIN: Calling Sick-Beard to post-process: %s", inputName)
|
||||
elif nzbtomedia.CFG["SickBeard", "NzbDrone"].issubsection(inputCategory):
|
||||
logger.postprocess("Calling Sick-Beard to post-process: %s",logger.MESSAGE), inputName
|
||||
return autoProcessTV().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||
elif config()["HeadPhones"].issubsection(inputCategory):
|
||||
Logger.info("MAIN: Calling HeadPhones to post-process: %s", inputName)
|
||||
elif nzbtomedia.CFG["HeadPhones"].issubsection(inputCategory):
|
||||
logger.postprocess("Calling HeadPhones to post-process: %s", logger.MESSAGE), inputName
|
||||
return autoProcessMusic().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||
elif config()["Mylar"].issubsection(inputCategory):
|
||||
Logger.info("MAIN: Calling Mylar to post-process: %s", inputName)
|
||||
elif nzbtomedia.CFG["Mylar"].issubsection(inputCategory):
|
||||
logger.postprocess("Calling Mylar to post-process: %s",logger.MESSAGE), inputName
|
||||
return autoProcessComics().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||
elif config()["Gamez"].issubsection(inputCategory):
|
||||
Logger.info("MAIN: Calling Gamez to post-process: %s", inputName)
|
||||
elif nzbtomedia.CFG["Gamez"].issubsection(inputCategory):
|
||||
logger.postprocess("Calling Gamez to post-process: %s",logger.MESSAGE), inputName
|
||||
return autoProcessGames().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||
else:
|
||||
Logger.warning("MAIN: We could not find the section %s with a download category of %s in your autoProcessMedia.cfg. Exiting.", section, inputCategory)
|
||||
logger.postprocess("We could not find the section %s with a download category of %s in your autoProcessMedia.cfg. Exiting.",logger.WARNING), section, inputCategory
|
||||
return -1
|
||||
|
||||
########################################################################################################################
|
||||
logger.postprocess("====================") # Seperate old from new log
|
||||
logger.postprocess("nzbToMedia %s", nzbtomedia.NZBTOMEDIA_VERSION)
|
||||
|
||||
# run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options.
|
||||
if config().migrate():
|
||||
# check to write settings from nzbGet UI to autoProcessMedia.cfg.
|
||||
if os.environ.has_key('NZBOP_SCRIPTDIR'):
|
||||
config().addnzbget()
|
||||
|
||||
nzbtomedia_configure_logging(config.LOG_FILE)
|
||||
|
||||
Logger = logging.getLogger()
|
||||
Logger.info("====================") # Seperate old from new log
|
||||
Logger.info("nzbToMedia %s", config.NZBTOMEDIA_VERSION)
|
||||
|
||||
Logger.info("MAIN: Loading config from %s", config.CONFIG_FILE)
|
||||
else:
|
||||
print("Unable to find " + config.CONFIG_FILE + " or " + config.SAMPLE_CONFIG_FILE)
|
||||
sys.exit(-1)
|
||||
|
||||
WakeUp()
|
||||
logger.postprocess("Loading config from %s", nzbtomedia.CONFIG_FILE)
|
||||
|
||||
# Post-Processing Result
|
||||
result = 0
|
||||
|
@ -363,7 +344,7 @@ result = 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.info("MAIN: Script triggered from NZBGet (11.0 or later).")
|
||||
logger.postprocess("Script triggered from NZBGet (11.0 or later).")
|
||||
|
||||
# NZBGet argv: all passed as environment variables.
|
||||
clientAgent = "nzbget"
|
||||
|
@ -372,48 +353,48 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5
|
|||
status = 0
|
||||
|
||||
if os.environ['NZBOP_UNPACK'] != 'yes':
|
||||
Logger.error("MAIN: Please enable option \"Unpack\" in nzbget configuration file, exiting")
|
||||
sys.exit(config.NZBGET_POSTPROCESS_ERROR)
|
||||
logger.error("Please enable option \"Unpack\" in nzbget configuration file, exiting")
|
||||
sys.exit(nzbtomedia.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(config.NZBGET_POSTPROCESS_NONE)
|
||||
logger.warning("Par-check successful, but Par-repair disabled, exiting")
|
||||
logger.postprocess("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':
|
||||
Logger.warning("MAIN: Par-repair failed, setting status \"failed\"")
|
||||
logger.warning("Par-repair failed, setting status \"failed\"")
|
||||
status = 1
|
||||
|
||||
# Check unpack status
|
||||
if os.environ['NZBPP_UNPACKSTATUS'] == '1':
|
||||
Logger.warning("MAIN: Unpack failed, setting status \"failed\"")
|
||||
logger.warning("Unpack failed, setting status \"failed\"")
|
||||
status = 1
|
||||
|
||||
if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] == '0':
|
||||
# Unpack was skipped due to nzb-file properties or due to errors during par-check
|
||||
|
||||
if os.environ['NZBPP_HEALTH'] < 1000:
|
||||
Logger.warning("MAIN: Download health is compromised and Par-check/repair disabled or no .par2 files found. Setting status \"failed\"")
|
||||
Logger.info("MAIN: Please check your Par-check/repair settings for future downloads.")
|
||||
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.")
|
||||
status = 1
|
||||
|
||||
else:
|
||||
Logger.info("MAIN: Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful")
|
||||
Logger.info("MAIN: Please check your Par-check/repair settings for future downloads.")
|
||||
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.")
|
||||
|
||||
# Check if destination directory exists (important for reprocessing of history items)
|
||||
if not os.path.isdir(os.environ['NZBPP_DIRECTORY']):
|
||||
Logger.error("MAIN: 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
|
||||
|
||||
# All checks done, now launching the script.
|
||||
download_id = ""
|
||||
if os.environ.has_key('NZBPR_COUCHPOTATO'):download_id = os.environ['NZBPR_COUCHPOTATO']
|
||||
result = process(os.environ['NZBPP_DIRECTORY'], inputName=os.environ['NZBPP_NZBFILENAME'], clientAgent = "nzbget", inputCategory=os.environ['NZBPP_CATEGORY'])
|
||||
if result != 0: Logger.info("MAIN: A problem was reported in the autoProcess* script.")
|
||||
if result != 0: logger.error("A problem was reported in the autoProcess* script.")
|
||||
# SABnzbd Pre 0.7.17
|
||||
elif len(sys.argv) == config.SABNZB_NO_OF_ARGUMENTS:
|
||||
elif len(sys.argv) == nzbtomedia.SABNZB_NO_OF_ARGUMENTS:
|
||||
# SABnzbd argv:
|
||||
# 1 The final directory of the job (full path)
|
||||
# 2 The original name of the NZB file
|
||||
|
@ -422,11 +403,11 @@ elif len(sys.argv) == config.SABNZB_NO_OF_ARGUMENTS:
|
|||
# 5 User-defined category
|
||||
# 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")
|
||||
logger.postprocess("Script triggered from SABnzbd")
|
||||
result = process(sys.argv[1], inputName=sys.argv[2], status=sys.argv[7], inputCategory=sys.argv[5], clientAgent = "sabnzbd", download_id='')
|
||||
if result != 0: Logger.info("MAIN: A problem was reported in the autoProcess* script.")
|
||||
if result != 0: logger.error("A problem was reported in the autoProcess* script.")
|
||||
# SABnzbd 0.7.17+
|
||||
elif len(sys.argv) >= config.SABNZB_0717_NO_OF_ARGUMENTS:
|
||||
elif len(sys.argv) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS:
|
||||
# SABnzbd argv:
|
||||
# 1 The final directory of the job (full path)
|
||||
# 2 The original name of the NZB file
|
||||
|
@ -436,33 +417,33 @@ elif len(sys.argv) >= config.SABNZB_0717_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
|
||||
# 8 Failure URL
|
||||
Logger.info("MAIN: Script triggered from SABnzbd 0.7.17+")
|
||||
logger.postprocess("Script triggered from SABnzbd 0.7.17+")
|
||||
result = process(sys.argv[1], inputName=sys.argv[2], status=sys.argv[7], inputCategory=sys.argv[5], clientAgent = "sabnzbd", download_id='')
|
||||
if result != 0:Logger.info("MAIN: A problem was reported in the autoProcess* script.")
|
||||
if result != 0:logger.error("A problem was reported in the autoProcess* script.")
|
||||
else:
|
||||
result = 0
|
||||
|
||||
# init sub-sections
|
||||
subsections = config()["CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez"].subsections
|
||||
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||
subsections = nzbtomedia.CFG["CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez"].subsections
|
||||
logger.warning("Invalid number of arguments received from client.")
|
||||
for section, subsection in subsections.items():
|
||||
for category in subsection:
|
||||
if config()[section].isenabled(category):
|
||||
if nzbtomedia.CFG[section].isenabled(category):
|
||||
dirNames = get_dirnames(section, category)
|
||||
for dirName in dirNames:
|
||||
Logger.info("MAIN: nzbToMedia running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||
logger.postprocess("nzbToMedia running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||
results = process(dirName, os.path.basename(dirName), 0, inputCategory=category)
|
||||
if results != 0:
|
||||
result = results
|
||||
Logger.info("MAIN: A problem was reported when trying to manually run %s:%s.", section, category)
|
||||
logger.error("A problem was reported when trying to manually run %s:%s.", section, category)
|
||||
else:
|
||||
Logger.info("MAIN: nzbToMedia %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category)
|
||||
logger.postprocess("nzbToMedia %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category)
|
||||
|
||||
if result == 0:
|
||||
Logger.info("MAIN: The nzbToMedia script completed successfully.")
|
||||
logger.postprocess("The nzbToMedia script completed successfully.")
|
||||
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
||||
sys.exit(config.NZBGET_POSTPROCESS_SUCCESS)
|
||||
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS)
|
||||
else:
|
||||
Logger.info("MAIN: A problem was reported in the nzbToMedia script.")
|
||||
logger.error("A problem was reported in the nzbToMedia script.")
|
||||
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
||||
sys.exit(config.NZBGET_POSTPROCESS_ERROR)
|
||||
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue