From eac9619dcbff589519d774cb42a314333de56f55 Mon Sep 17 00:00:00 2001 From: echel0n Date: Thu, 17 Apr 2014 05:16:29 -0700 Subject: [PATCH] nzbTo* files will now send section variable to nzbToMedia script so that manually processing doesn't bother with trying to post-process unrequired folders, also I've changed the way we call nzbToMedia so this should resolve issue #328 encoding issues. Custom userscripts folder added to avoid auto-update conflicts so long as the custom scripts are stored in said folder, this folder is added to .gitignore --- .gitignore | 3 ++- TorrentToMedia.py | 10 +++++----- autoProcessMedia.cfg.spec | 4 ++-- nzbToCouchPotato.py | 11 +++-------- nzbToGamez.py | 11 +++-------- nzbToHeadPhones.py | 10 +++------- nzbToMedia.py | 22 +++++++++++----------- nzbToMylar.py | 11 +++-------- nzbToNzbDrone.py | 11 +++-------- nzbToSickBeard.py | 11 +++-------- nzbtomedia/__init__.py | 9 +++++++-- nzbtomedia/nzbToMediaUtil.py | 4 ++-- 12 files changed, 47 insertions(+), 70 deletions(-) diff --git a/.gitignore b/.gitignore index af144f73..dfea5fbf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ *.pyc *.pyo *.log +/userscripts/ /logs/ -/.idea/ +/.idea/ \ No newline at end of file diff --git a/TorrentToMedia.py b/TorrentToMedia.py index d861b0d5..8d332eaa 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -323,7 +323,7 @@ def external_script(outputDestination, torrentName, torrentLabel): logger.postprocess("%s files were processed, but %s still remain. outputDirectory will not be cleaned.", num_files, num_files_new) return final_result -def main(): +def main(args): # Initialize the config nzbtomedia.initialize() @@ -332,7 +332,7 @@ def main(): logger.postprocess("#########################################################") # debug command line options - logger.debug("Options passed into TorrentToMedia: " + str(sys.argv)) + logger.debug("Options passed into TorrentToMedia: " + str(args)) # Post-Processing Result result = 0 @@ -341,7 +341,7 @@ def main(): clientAgent = nzbtomedia.CLIENTAGENT try: - inputDirectory, inputName, inputCategory, inputHash, inputID = parse_args(clientAgent) + inputDirectory, inputName, inputCategory, inputHash, inputID = parse_args(clientAgent, args) except: logger.error("There was a problem loading variables") return -1 @@ -366,7 +366,7 @@ def main(): result = processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent) logger.postprocess("All done.") - return result + sys.exit(result) if __name__ == "__main__": - exit(main()) + main(sys.argv) diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index 9635d775..d6233111 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -179,8 +179,8 @@ user_script_categories = NONE #What extension do you want to process? Specify all the extension, or use "ALL" to process all files. user_script_mediaExtensions = .mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg - #Specify the path of the script - user_script_path = /media/test/script/script.sh + #Specify the path to your custom script + user_script_path = /nzbToMedia/userscripts/script.sh #Specify the argument(s) passed to script, comma separated in order. #for example FP,FN,DN, TN, TL for file path (absolute file name with path), file name, absolute directory name (with path), Torrent Name, Torrent Label/Category. #So the result is /media/test/script/script.sh FP FN DN TN TL. Add other arguments as needed eg -f, -r diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py index f4e837d7..b06612fa 100755 --- a/nzbToCouchPotato.py +++ b/nzbToCouchPotato.py @@ -127,13 +127,8 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## - -# Stub file to call nzbToMedia +import sys import nzbToMedia -def main(): - # call nzbToMedia - nzbToMedia.main() - -if __name__ == "__main__": - exit(main()) +section = "CouchPotato" +nzbToMedia.main(sys.argv, section) \ No newline at end of file diff --git a/nzbToGamez.py b/nzbToGamez.py index 5380f432..eeeb05b3 100755 --- a/nzbToGamez.py +++ b/nzbToGamez.py @@ -64,13 +64,8 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## - -# Stub file to call nzbToMedia +import sys import nzbToMedia -def main(): - # call nzbToMedia - nzbToMedia.main() - -if __name__ == "__main__": - exit(main()) +section = "Gamez" +nzbToMedia.main(sys.argv, section) \ No newline at end of file diff --git a/nzbToHeadPhones.py b/nzbToHeadPhones.py index 525cde7f..1bf8f862 100755 --- a/nzbToHeadPhones.py +++ b/nzbToHeadPhones.py @@ -68,12 +68,8 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## -# Stub file to call nzbToMedia +import sys import nzbToMedia -def main(): - # call nzbToMedia - nzbToMedia.main() - -if __name__ == "__main__": - exit(main()) +section = "HeadPhones" +nzbToMedia.main(sys.argv, section) \ No newline at end of file diff --git a/nzbToMedia.py b/nzbToMedia.py index 826224cf..c3ab9b57 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -329,16 +329,16 @@ def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id= return result -def main(): +def main(args, section=None): # Initialize the config - nzbtomedia.initialize() + nzbtomedia.initialize(section) logger.postprocess("#########################################################") logger.postprocess("## ..::[%s]::.. :: STARTING", os.path.splitext(os.path.basename(os.path.normpath(os.path.abspath(__file__))))[0]) logger.postprocess("#########################################################") # debug command line options - logger.debug("Options passed into nzbToMedia: " + str(sys.argv)) + logger.debug("Options passed into nzbToMedia: " + str(args)) # Post-Processing Result result = 0 @@ -393,7 +393,7 @@ def main(): # All checks done, now launching the script. result = process(os.environ['NZBPP_DIRECTORY'], inputName=os.environ['NZBPP_NZBFILENAME'], status=status, clientAgent = "nzbget", download_id=download_id, inputCategory=os.environ['NZBPP_CATEGORY']) # SABnzbd Pre 0.7.17 - elif len(sys.argv) == nzbtomedia.SABNZB_NO_OF_ARGUMENTS: + elif len(args) == nzbtomedia.SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file @@ -403,9 +403,9 @@ def main(): # 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.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='') + result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent = "sabnzbd", download_id='') # SABnzbd 0.7.17+ - elif len(sys.argv) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS: + elif len(args) >= 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 @@ -416,7 +416,7 @@ def main(): # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 # 8 Failure URL 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='') + result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent = "sabnzbd", download_id='') else: # Perform Manual Run logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...") @@ -437,15 +437,15 @@ def main(): logger.postprocess("nzbToMedia %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category) if result == 0: - logger.postprocess("The nzbToMedia script completed successfully.") + logger.postprocess("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 nzbToMedia script.") + logger.error("A problem was reported in the nzbToMedia script.", args[0]) if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) - return result + sys.exit(result) if __name__ == '__main__': - exit(main()) \ No newline at end of file + main(sys.argv) \ No newline at end of file diff --git a/nzbToMylar.py b/nzbToMylar.py index 91b20aa7..15c0a7b1 100755 --- a/nzbToMylar.py +++ b/nzbToMylar.py @@ -67,13 +67,8 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## - -# Stub file to call nzbToMedia +import sys import nzbToMedia -def main(): - # call nzbToMedia - nzbToMedia.main() - -if __name__ == "__main__": - exit(main()) +section = "Mylar" +nzbToMedia.main(sys.argv, section) \ No newline at end of file diff --git a/nzbToNzbDrone.py b/nzbToNzbDrone.py index 0f51c5c4..5b9db78a 100755 --- a/nzbToNzbDrone.py +++ b/nzbToNzbDrone.py @@ -110,13 +110,8 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## - -# Stub file to call nzbToMedia +import sys import nzbToMedia -def main(): - # call nzbToMedia - nzbToMedia.main() - -if __name__ == "__main__": - exit(main()) +section = "NzbDrone" +nzbToMedia.main(sys.argv, section) \ No newline at end of file diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index 04d7e1fa..f8f097b8 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -130,13 +130,8 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## - -# Stub file to call nzbToMedia +import sys import nzbToMedia -def main(): - # call nzbToMedia - nzbToMedia.main() - -if __name__ == "__main__": - exit(main()) +section = "SickBeard" +nzbToMedia.main(sys.argv, section) \ No newline at end of file diff --git a/nzbtomedia/__init__.py b/nzbtomedia/__init__.py index 79c7c6b3..cad58c63 100644 --- a/nzbtomedia/__init__.py +++ b/nzbtomedia/__init__.py @@ -97,7 +97,7 @@ USER_SCRIPT_RUNONCE = None __INITIALIZED__ = False -def initialize(): +def initialize(section=None): global NZBGET_POSTPROCESS_ERROR, NZBGET_POSTPROCESS_NONE, NZBGET_POSTPROCESS_PARCHECK, NZBGET_POSTPROCESS_SUCCESS,\ NZBTOMEDIA_TIMEOUT, FORKS, FORK_DEFAULT, FORK_FAILED_TORRENT, FORK_FAILED, SICKBEARD_TORRENT, SICKBEARD_FAILED,\ PROGRAM_DIR, CFG, CFG_LOGGING, CONFIG_FILE, CONFIG_MOVIE_FILE, CONFIG_SPEC_FILE, LOG_DIR, NZBTOMEDIA_BRANCH,\ @@ -222,7 +222,12 @@ def initialize(): MINSAMPLESIZE = int(CFG["Extensions"]["minSampleSize"]) # 200 (in MB) SAMPLEIDS = (CFG["Extensions"]["SampleIDs"]) # sample,-s. - SECTIONS = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez") + # check for script-defied section and if None set to allow sections + if section: + SECTIONS = (section,) + else: + SECTIONS = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez") + SUBSECTIONS = CFG[SECTIONS] CATEGORIES += SUBSECTIONS.sections diff --git a/nzbtomedia/nzbToMediaUtil.py b/nzbtomedia/nzbToMediaUtil.py index 37fd4412..dc8e08ad 100644 --- a/nzbtomedia/nzbToMediaUtil.py +++ b/nzbtomedia/nzbToMediaUtil.py @@ -367,7 +367,7 @@ def parse_transmission(args): inputID = os.getenv('TR_TORRENT_ID') return inputDirectory, inputName, inputCategory, inputHash, inputID -def parse_args(clientAgent): +def parse_args(clientAgent, args): clients = { 'other': parse_other, 'rtorrent': parse_rtorrent, @@ -377,7 +377,7 @@ def parse_args(clientAgent): } try: - return clients[clientAgent](sys.argv) + return clients[clientAgent](args) except:return None, None, None, None, None def get_dirnames(section, subsections=None):