diff --git a/autoProcess/migratecfg.py b/autoProcess/migratecfg.py index 640dad75..5d6c2d7a 100644 --- a/autoProcess/migratecfg.py +++ b/autoProcess/migratecfg.py @@ -104,6 +104,16 @@ def migrate(): confignew.set(section, option, value) section = "Torrent" # reset in case extensions out of order. + section = "Extensions" + original = [] + try: + original = configold.items(section) + except: + pass + for item in original: + option, value = item + confignew.set(section, option, value) + section = "Transcoder" original = [] try: @@ -198,3 +208,97 @@ def migrate(): # rename our newly edited autoProcessMedia.cfg.sample to autoProcessMedia.cfg os.rename(configFilenamenew, configFilenameold) return + +def addnzbget(): + confignew = ConfigParser.ConfigParser() + confignew.optionxform = str + configFilenamenew = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") + confignew.read(configFilenamenew) + + section = "CouchPotato" + envKeys = ['CATEGORY', 'APIKEY', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT', 'DELAY', 'METHOD', 'DELETE_FAILED'] + cfgKeys = ['cpsCategory', 'apikey', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'delay', 'method', 'delete_failed'] + for index in range(len(envKeys)): + key = 'NZBPO_CPS' + envKeys[index] + if os.environ.has_key(key): + option = cfgKeys[index] + value = os.environ[key] + confignew.set(section, option, value) + + + section = "SickBeard" + envKeys = ['CATEGORY', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FAILED_FORK'] + cfgKeys = ['sbCategory', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'watch_dir', 'failed_fork'] + for index in range(len(envKeys)): + key = 'NZBPO_SB' + envKeys[index] + if os.environ.has_key(key): + option = cfgKeys[index] + value = os.environ[key] + confignew.set(section, option, value) + + section = "HeadPhones" + envKeys = ['CATEGORY', 'APIKEY', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT', 'DELAY'] + cfgKeys = ['hpCategory', 'apikey', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'delay'] + for index in range(len(envKeys)): + key = 'NZBPO_HP' + envKeys[index] + if os.environ.has_key(key): + option = cfgKeys[index] + value = os.environ[key] + confignew.set(section, option, value) + + section = "Mylar" + envKeys = ['CATEGORY', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT'] + cfgKeys = ['mlCategory', 'host', 'port', 'username', 'password', 'ssl', 'web_root'] + for index in range(len(envKeys)): + key = 'NZBPO_ML' + envKeys[index] + if os.environ.has_key(key): + option = cfgKeys[index] + value = os.environ[key] + confignew.set(section, option, value) + + section = "Gamez" + envKeys = ['CATEGORY', 'APIKEY', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT'] + cfgKeys = ['gzCategory', 'apikey', 'host', 'port', 'username', 'password', 'ssl', 'web_root'] + for index in range(len(envKeys)): + key = 'NZBPO_GZ' + envKeys[index] + if os.environ.has_key(key): + option = cfgKeys[index] + value = os.environ[key] + confignew.set(section, option, value) + + section = "Extensions" + envKeys = ['COMPRESSEDEXTENSIONS', 'MEDIAEXTENSIONS', 'METAEXTENSIONS'] + cfgKeys = ['compressedExtensions', 'mediaExtensions', 'metaExtensions'] + for index in range(len(envKeys)): + key = 'NZBPO_' + envKeys[index] + if os.environ.has_key(key): + option = cfgKeys[index] + value = os.environ[key] + confignew.set(section, option, value) + + section = "Transcoder" + envKeys = ['TRANSCODE', 'DUPLICATE', 'IGNOREEXTENSIONS', 'OUTPUTVIDEOEXTENSION', 'OUTPUTVIDEOCODEC', 'OUTPUTVIDEOPRESET', 'OUTPUTVIDEOFRAMERATE', 'OUTPUTVIDEOBITRATE', 'OUTPUTAUDIOCODEC', 'OUTPUTAUDIOBITRATE', 'OUTPUTSUBTITLECODEC'] + cfgKeys = ['transcode', 'duplicate', 'ignoreExtensions', 'outputVideoExtension', 'outputVideoCodec', 'outputVideoPreset', 'outputVideoFramerate', 'outputVideoBitrate', 'outputAudioCodec', 'outputAudioBitrate', 'outputSubtitleCodec'] + for index in range(len(envKeys)): + key = 'NZBPO_' + envKeys[index] + if os.environ.has_key(key): + option = cfgKeys[index] + value = os.environ[key] + confignew.set(section, option, value) + + section = "WakeOnLan" + envKeys = ['WAKE', 'HOST', 'PORT', 'MAC'] + cfgKeys = ['wake', 'host', 'port', 'mac'] + for index in range(len(envKeys)): + key = 'NZBPO_WOL' + envKeys[index] + if os.environ.has_key(key): + option = cfgKeys[index] + value = os.environ[key] + confignew.set(section, option, value) + + + # writing our configuration file to 'autoProcessMedia.cfg' + with open(configFilenamenew, 'wb') as configFile: + confignew.write(configFile) + + return diff --git a/changelog.txt b/changelog.txt index 25850667..998449ed 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,7 +8,10 @@ Uses single directory scanning for CouchPotato renamer Matches imdb_id, download_id, clientAgent with CPS database Impacts NZB -Fixed TLS support for NZBGet email notifications +Addeed direct configuration support via nzbget webUI (nzbget v11+) +All nzb scripts are now directly callabale in nzbget v11 +Settings made in nzbget webUI will be applied to the auotPorcessMedia.cfg when the scripts are run from nzbget. +Fixed TLS support for NZBGet email notifications (for V10 support) V7.1 28/03/2013 diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py index e1211a6b..4bc54239 100755 --- a/nzbToCouchPotato.py +++ b/nzbToCouchPotato.py @@ -1,4 +1,116 @@ #!/usr/bin/env python +# +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to CouchPotato. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +### OPTIONS ### + +## CouchPotato + +# CouchPotato script category. +# +# category that gets called for post-processing with CouchPotatoServer. +#cpsCategory=movie + +# CouchPotato api key. +#cpsapikey= + +# CouchPotato host. +#cpshost=localhost + +# CouchPotato port. +#cpsport=5050 + +# CouchPotato username. +#cpsusername= + +# CouchPotato password. +#cpspassword= + +# CouchPotato uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#cpsssl=0 + +# CouchPotato URL_Base +# +# set this if using a reverse proxy. +#cpsweb_root= + +# CouchPotato Postprocess Delay. +# +# must be at least 60 seconds. +#cpsdelay=65 + +# CouchPotato Postprocess Method. +# +# use "renamer" for CPS renamer (default) or "manage" to call a manage update. +#cpsmethod=renamer + +# CouchPotato Delete Failed Downloads +# +# set to 1 to delete failed, or 0 to leave files in place. +#cpsdelete_failed=0 + +## Extensions + +# Media Extensions +# +# This is a list of media extensions that may be transcoded if transcoder is enabled below. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## Transcoder + +# Transcode +# +# set to 1 to transcode, otherwise set to 0. +#transcode=0 + +# create a duplicate, or replace the original. +# +# set to 1 to cretae a new file or 0 to replace the original +#duplicate=1 + +# ignore extensions +# +# list of extensions that won't be transcoded. +#ignoreExtensions=.avi,.mkv + +# ffmpeg output settings. +#outputVideoExtension=.mp4 +#outputVideoCodec=libx264 +#outputVideoPreset=medium +#outputVideoFramerate=24 +#outputVideoBitrate=800k +#outputAudioCodec=libmp3lame +#outputAudioBitrate=128k +#outputSubtitleCodec= + +## WakeOnLan + +# use WOL +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## import os import sys @@ -12,6 +124,9 @@ from autoProcess.nzbToMediaUtil import * #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(os.path.dirname(sys.argv[0])) Logger = logging.getLogger(__name__) @@ -21,8 +136,75 @@ Logger.info("nzbToCouchPotato %s", VERSION) WakeUp() +# 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).") + + # NZBGet argv: all passed as environment variables. + clientAgent = "nzbget" + # 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("Please enable option \"Unpack\" in nzbget configuration file, exiting") + sys.exit(POSTPROCESS_ERROR) + + # Check par status + if os.environ['NZBPP_PARSTATUS'] == 3: + Logger.warning("Par-check successful, but Par-repair disabled, exiting") + sys.exit(POSTPROCESS_NONE) + + if os.environ['NZBPP_PARSTATUS'] == 1: + Logger.warning("Par-check failed, setting status \"failed\"") + status = 1 + + # Check unpack status + if os.environ['NZBPP_UNPACKSTATUS'] == 1: + Logger.warning("Unpack failed, setting status \"failed\"") + status = 1 + + if os.environ['NZBPP_UNPACKSTATUS'] == 0 and os.environ['NZBPP_PARSTATUS'] != 2: + # Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check + + for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): + for file in filenames: + fileExtension = os.path.splitext(file)[1] + + if fileExtension in ['.rar', '.7z'] or os.path.splitext(fileExtension)[1] in ['.rar', '.7z']: + Logger.warning("Post-Process: Archive files exist but unpack skipped, exiting") + sys.exit(POSTPROCESS_NONE) + + if fileExtension in ['.par2']: + Logger.warning("Post-Process: Unpack skipped and par-check skipped (although par2-files exist), exiting") + sys.exit(POSTPROCESS_NONE) + + if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")): + Logger.warning("Post-Process: _brokenlog.txt exists, download is probably damaged, exiting") + sys.exit(POSTPROCESS_NONE) + + Logger.info("Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful") + + # Check if destination directory exists (important for reprocessing of history items) + if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): + Logger.error("Post-Process: Nothing to post-process: destination directory %s doesn't exist", 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'] + Logger.info("Script triggered from NZBGet, starting autoProcessMovie...") + clientAgent = "nzbget" + result = autoProcessMovie.process(os.environ['NZBPP_DIRECTORY'], os.environ['NZBPP_NZBNAME'], status, clientAgent, download_id) # SABnzbd -if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: +elif len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file @@ -34,7 +216,7 @@ if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: Logger.info("Script triggered from SABnzbd, starting autoProcessMovie...") clientAgent = "sabnzbd" result = autoProcessMovie.process(sys.argv[1], sys.argv[2], sys.argv[7], clientAgent) -# NZBGet +# NZBGet V10 or earlier elif len(sys.argv) == NZBGET_NO_OF_ARGUMENTS: # NZBGet argv: # 1 The final directory of the job (full path) @@ -50,3 +232,12 @@ else: Logger.info("Running autoProcessMovie as a manual run...") clientAgent = "manual" result = autoProcessMovie.process('Manual Run', 'Manual Run', 0, clientAgent) + +if result == 0: + Logger.info("MAIN: The autoProcessMovie script completed successfully.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_SUCCESS) +else: + Logger.info("MAIN: A problem was reported in the autoProcessMovie script.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_ERROR) diff --git a/nzbToGamez.py b/nzbToGamez.py index 2e554bb2..cc7d04a7 100755 --- a/nzbToGamez.py +++ b/nzbToGamez.py @@ -1,4 +1,67 @@ #!/usr/bin/env python +# +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to Gamez. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +### OPTIONS ### + +## Gamez + +# Gamez script category. +# +# category that gets called for post-processing with Gamez. +#gzCategory=games + +# Gamez api key. +#gzapikey= + +# Gamez host. +#gzhost=localhost + +# Gamez port. +#gzport=8085 + +# Gamez username. +#gzusername= + +# Gamez password. +#gzpassword= + +# Gamez uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#gzssl=0 + +# Gamez web_root +# +# set this if using a reverse proxy. +#gzweb_root= + +## WakeOnLan + +# use WOL +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## import os import sys @@ -12,6 +75,9 @@ from autoProcess.nzbToMediaUtil import * #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(os.path.dirname(sys.argv[0])) Logger = logging.getLogger(__name__) @@ -21,8 +87,70 @@ Logger.info("nzbToGamez %s", VERSION) WakeUp() +# 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).") + + # 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("Please enable option \"Unpack\" in nzbget configuration file, exiting") + sys.exit(POSTPROCESS_ERROR) + + # Check par status + if os.environ['NZBPP_PARSTATUS'] == 3: + Logger.warning("Par-check successful, but Par-repair disabled, exiting") + sys.exit(POSTPROCESS_NONE) + + if os.environ['NZBPP_PARSTATUS'] == 1: + Logger.warning("Par-check failed, setting status \"failed\"") + status = 1 + + # Check unpack status + if os.environ['NZBPP_UNPACKSTATUS'] == 1: + Logger.warning("Unpack failed, setting status \"failed\"") + status = 1 + + if os.environ['NZBPP_UNPACKSTATUS'] == 0 and os.environ['NZBPP_PARSTATUS'] != 2: + # Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check + + for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): + for file in filenames: + fileExtension = os.path.splitext(file)[1] + + if fileExtension in ['.rar', '.7z'] or os.path.splitext(fileExtension)[1] in ['.rar', '.7z']: + Logger.warning("Post-Process: Archive files exist but unpack skipped, exiting") + sys.exit(POSTPROCESS_NONE) + + if fileExtension in ['.par2']: + Logger.warning("Post-Process: Unpack skipped and par-check skipped (although par2-files exist), exiting") + sys.exit(POSTPROCESS_NONE) + + if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")): + Logger.warning("Post-Process: _brokenlog.txt exists, download is probably damaged, exiting") + sys.exit(POSTPROCESS_NONE) + + Logger.info("Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful") + + # Check if destination directory exists (important for reprocessing of history items) + if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): + Logger.error("Post-Process: Nothing to post-process: destination directory %s doesn't exist", os.environ['NZBPP_DIRECTORY']) + status = 1 + + # All checks done, now launching the script. + Logger.info("Script triggered from NZBGet, starting autoProcessGames...") + result = autoProcessGames.process(os.environ['NZBPP_DIRECTORY'], os.environ['NZBPP_NZBNAME'], status) # SABnzbd -if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: +elif len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file @@ -46,3 +174,12 @@ elif len(sys.argv) == NZBGET_NO_OF_ARGUMENTS: else: Logger.warn("Invalid number of arguments received from client. Exiting") sys.exit(1) + +if result == 0: + Logger.info("MAIN: The autoProcessGames script completed successfully.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_SUCCESS) +else: + Logger.info("MAIN: A problem was reported in the autoProcessGames script.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_ERROR) diff --git a/nzbToHeadPhones.py b/nzbToHeadPhones.py index 04f10bfd..5eee33c4 100755 --- a/nzbToHeadPhones.py +++ b/nzbToHeadPhones.py @@ -1,4 +1,72 @@ #!/usr/bin/env python +# +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to HeadPhones. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +### OPTIONS ### + +## HeadPhones + +# HeadPhones script category. +# +# category that gets called for post-processing with HeadHones. +#hpCategory=music + +# HeadPhones api key. +#hpapikey= + +# HeadPhones host. +#hphost=localhost + +# HeadPhones port. +#hpport=8181 + +# HeadPhones username. +#hpusername= + +# HeadPhones password. +#hppassword= + +# HeadPhones uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#hpssl=0 + +# HeadPhones web_root +# +# set this if using a reverse proxy. +#hpweb_root= + +# HeadPhones Postprocess Delay. +# +# set as required to ensure correct processing. +#hpdelay=65 + +## WakeOnLan + +# use WOL +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## import os import sys @@ -12,6 +80,9 @@ from autoProcess.nzbToMediaUtil import * #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(os.path.dirname(sys.argv[0])) Logger = logging.getLogger(__name__) @@ -21,8 +92,70 @@ Logger.info("nzbToHeadPhones %s", VERSION) WakeUp() +# 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).") + + # 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("Please enable option \"Unpack\" in nzbget configuration file, exiting") + sys.exit(POSTPROCESS_ERROR) + + # Check par status + if os.environ['NZBPP_PARSTATUS'] == 3: + Logger.warning("Par-check successful, but Par-repair disabled, exiting") + sys.exit(POSTPROCESS_NONE) + + if os.environ['NZBPP_PARSTATUS'] == 1: + Logger.warning("Par-check failed, setting status \"failed\"") + status = 1 + + # Check unpack status + if os.environ['NZBPP_UNPACKSTATUS'] == 1: + Logger.warning("Unpack failed, setting status \"failed\"") + status = 1 + + if os.environ['NZBPP_UNPACKSTATUS'] == 0 and os.environ['NZBPP_PARSTATUS'] != 2: + # Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check + + for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): + for file in filenames: + fileExtension = os.path.splitext(file)[1] + + if fileExtension in ['.rar', '.7z'] or os.path.splitext(fileExtension)[1] in ['.rar', '.7z']: + Logger.warning("Post-Process: Archive files exist but unpack skipped, exiting") + sys.exit(POSTPROCESS_NONE) + + if fileExtension in ['.par2']: + Logger.warning("Post-Process: Unpack skipped and par-check skipped (although par2-files exist), exiting") + sys.exit(POSTPROCESS_NONE) + + if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")): + Logger.warning("Post-Process: _brokenlog.txt exists, download is probably damaged, exiting") + sys.exit(POSTPROCESS_NONE) + + Logger.info("Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful") + + # Check if destination directory exists (important for reprocessing of history items) + if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): + Logger.error("Post-Process: Nothing to post-process: destination directory %s doesn't exist", os.environ['NZBPP_DIRECTORY']) + status = 1 + + # All checks done, now launching the script + Logger.info("Script triggered from NZBGet, starting autoProcessMusic...") + result = autoProcessMusic.process(os.environ['NZBPP_DIRECTORY'], os.environ['NZBPP_NZBNAME'], status) # SABnzbd -if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: +elif len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file @@ -47,3 +180,12 @@ else: Logger.warn("Invalid number of arguments received from client.") Logger.info("Running autoProcessMusic as a manual run...") result = autoProcessMusic.process('Manual Run', 'Manual Run', 0) + +if result == 0: + Logger.info("MAIN: The autoProcessMusic script completed successfully.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_SUCCESS) +else: + Logger.info("MAIN: A problem was reported in the autoProcessMusic script.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_ERROR) diff --git a/nzbToMedia.py b/nzbToMedia.py index 4a3a9728..8c6e2dcb 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -1,4 +1,258 @@ #!/usr/bin/env python +# +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to CouchPotato, SickBeard, Mylar, Gamez, HeadPhones. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +### OPTIONS ### + +## CouchPotato + +# CouchPotato script category. +# +# category that gets called for post-processing with CouchPotatoServer. +#cpsCategory=movie + +# CouchPotato api key. +#cpsapikey= + +# CouchPotato host. +#cpshost=localhost + +# CouchPotato port. +#cpsport=5050 + +# CouchPotato username. +#cpsusername= + +# CouchPotato password. +#cpspassword= + +# CouchPotato uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#cpsssl=0 + +# CouchPotato URL_Base +# +# set this if using a reverse proxy. +#cpsweb_root= + +# CouchPotato Postprocess Delay. +# +# must be at least 60 seconds. +#cpsdelay=65 + +# CouchPotato Postprocess Method. +# +# use "renamer" for CPS renamer (default) or "manage" to call a manage update. +#cpsmethod=renamer + +# CouchPotato Delete Failed Downloads +# +# set to 1 to delete failed, or 0 to leave files in place. +#cpsdelete_failed=0 + +## SickBeard + +# SickBeard script category. +# +# category that gets called for post-processing with SickBeard. +#sbCategory=tv + +# SickBeard host. +#sbhost=localhost + +# SickBeard port. +#sbport=8081 + +# SickBeard username. +#sbusername= + +# SickBeard password. +#sbpassword= + +# SickBeard uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#sbssl=0 + +# SickBeard web_root +# +# set this if using a reverse proxy. +#sbweb_root= + +# SickBeard watch directory. +# +# set this if SickBeard and nzbGet are on different systems. +#sbwatch_dir= + +# SickBeard uses failed fork. +# +# set to 1 if using the custom "failed fork". Default sickBeard uses 0. +#sbfailed_fork=0 + +# SickBeard Delete Failed Downloads +# +# set to 1 to delete failed, or 0 to leave files in place. +#sbdelete_failed=0 + +## HeadPhones + +# HeadPhones script category. +# +# category that gets called for post-processing with HeadHones. +#hpCategory=music + +# HeadPhones api key. +#hpapikey= + +# HeadPhones host. +#hphost=localhost + +# HeadPhones port. +#hpport=8181 + +# HeadPhones username. +#hpusername= + +# HeadPhones password. +#hppassword= + +# HeadPhones uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#hpssl=0 + +# HeadPhones web_root +# +# set this if using a reverse proxy. +#hpweb_root= + +# HeadPhones Postprocess Delay. +# +# set as required to ensure correct processing. +#hpdelay=65 + +## Mylar + +# Mylar script category. +# +# category that gets called for post-processing with Mylar. +#myCategory=comics + +# Mylar host. +#myhost=localhost + +# Mylar port. +#myport=8090 + +# Mylar username. +#myusername= + +# Mylar password. +#mypassword= + +# Mylar uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#myssl=0 + +# Mylar web_root +# +# set this if using a reverse proxy. +#myweb_root= + +## Gamez + +# Gamez script category. +# +# category that gets called for post-processing with Gamez. +#gzCategory=games + +# Gamez api key. +#gzapikey= + +# Gamez host. +#gzhost=localhost + +# Gamez port. +#gzport=8085 + +# Gamez username. +#gzusername= + +# Gamez password. +#gzpassword= + +# Gamez uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#gzssl=0 + +# Gamez web_root +# +# set this if using a reverse proxy. +#gzweb_root= + +## Extensions + +# Media Extensions +# +# This is a list of media extensions that may be transcoded if transcoder is enabled below. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## Transcoder + +# Transcode +# +# set to 1 to transcode, otherwise set to 0. +#transcode=0 + +# create a duplicate, or replace the original. +# +# set to 1 to cretae a new file or 0 to replace the original +#duplicate=1 + +# ignore extensions +# +# list of extensions that won't be transcoded. +#ignoreExtensions=.avi,.mkv + +# ffmpeg output settings. +#outputVideoExtension=.mp4 +#outputVideoCodec=libx264 +#outputVideoPreset=medium +#outputVideoFramerate=24 +#outputVideoBitrate=800k +#outputAudioCodec=libmp3lame +#outputAudioBitrate=128k +#outputSubtitleCodec= + +## WakeOnLan + +# use WOL +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## import os import sys @@ -17,6 +271,9 @@ from autoProcess.nzbToMediaUtil import * # 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(os.path.dirname(sys.argv[0])) Logger = logging.getLogger(__name__) @@ -41,8 +298,73 @@ hpCategory = config.get("HeadPhones", "hpCategory") mlCategory = config.get("Mylar", "mlCategory") # comics gzCategory = config.get("Gamez", "gzCategory") # games +# 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).") + + # NZBGet argv: all passed as environment variables. + clientAgent = "nzbget" + # 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("Please enable option \"Unpack\" in nzbget configuration file, exiting") + sys.exit(POSTPROCESS_ERROR) + + # Check par status + if os.environ['NZBPP_PARSTATUS'] == 3: + Logger.warning("Par-check successful, but Par-repair disabled, exiting") + sys.exit(POSTPROCESS_NONE) + + if os.environ['NZBPP_PARSTATUS'] == 1: + Logger.warning("Par-check failed, setting status \"failed\"") + status = 1 + + # Check unpack status + if os.environ['NZBPP_UNPACKSTATUS'] == 1: + Logger.warning("Unpack failed, setting status \"failed\"") + status = 1 + + if os.environ['NZBPP_UNPACKSTATUS'] == 0 and os.environ['NZBPP_PARSTATUS'] != 2: + # Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check + + for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): + for file in filenames: + fileExtension = os.path.splitext(file)[1] + + if fileExtension in ['.rar', '.7z'] or os.path.splitext(fileExtension)[1] in ['.rar', '.7z']: + Logger.warning("Post-Process: Archive files exist but unpack skipped, exiting") + sys.exit(POSTPROCESS_NONE) + + if fileExtension in ['.par2']: + Logger.warning("Post-Process: Unpack skipped and par-check skipped (although par2-files exist), exiting") + sys.exit(POSTPROCESS_NONE) + + if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")): + Logger.warning("Post-Process: _brokenlog.txt exists, download is probably damaged, exiting") + sys.exit(POSTPROCESS_NONE) + + Logger.info("Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful") + + # Check if destination directory exists (important for reprocessing of history items) + if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): + Logger.error("Post-Process: Nothing to post-process: destination directory %s doesn't exist", 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'] + nzbDir, inputName, inputCategory = (os.environ['NZBPP_DIRECTORY'], os.environ['NZBPP_NZBNAME'], os.environ['NZBPP_CATEGORY']) # SABnzbd -if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: +elif len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file @@ -55,7 +377,7 @@ if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: clientAgent = "sabnzbd" nzbDir, inputName, status, inputCategory, download_id = (sys.argv[1], sys.argv[2], sys.argv[7], sys.argv[5], '') # NZBGet -elif len(sys.argv) == NZBGET_NO_OF_ARGUMENTS: +elif len(sys.argv) == NZBGET_NO_OF_ARGUMENTS: # nzbget v10 or earlier. # NZBGet argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file @@ -65,6 +387,7 @@ elif len(sys.argv) == NZBGET_NO_OF_ARGUMENTS: Logger.info("MAIN: Script triggered from NZBGet") clientAgent = "nzbget" nzbDir, inputName, status, inputCategory, download_id = (sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]) + else: # only CPS supports this manual run for now. Logger.warn("MAIN: Invalid number of arguments received from client.") Logger.info("MAIN: Running autoProcessMovie as a manual run...") @@ -89,5 +412,9 @@ elif inputCategory == gzCategory: if result == 0: Logger.info("MAIN: The autoProcess* script completed successfully.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_SUCCESS) else: Logger.info("MAIN: A problem was reported in the autoProcess* script.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_ERROR) \ No newline at end of file diff --git a/nzbToMylar.py b/nzbToMylar.py index d2ace54a..6fefa09f 100755 --- a/nzbToMylar.py +++ b/nzbToMylar.py @@ -1,4 +1,64 @@ #!/usr/bin/env python +# +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to Mylar. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +### OPTIONS ### + +## Mylar + +# Mylar script category. +# +# category that gets called for post-processing with Mylar. +#myCategory=comics + +# Mylar host. +#myhost=localhost + +# Mylar port. +#myport=8090 + +# Mylar username. +#myusername= + +# Mylar password. +#mypassword= + +# Mylar uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#myssl=0 + +# Mylar web_root +# +# set this if using a reverse proxy. +#myweb_root= + +## WakeOnLan + +# use WOL +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## import os import sys @@ -12,6 +72,9 @@ from autoProcess.nzbToMediaUtil import * #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(os.path.dirname(sys.argv[0])) Logger = logging.getLogger(__name__) @@ -21,8 +84,70 @@ Logger.info("nzbToMylar %s", VERSION) WakeUp() +# 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).") + + # 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("Please enable option \"Unpack\" in nzbget configuration file, exiting") + sys.exit(POSTPROCESS_ERROR) + + # Check par status + if os.environ['NZBPP_PARSTATUS'] == 3: + Logger.warning("Par-check successful, but Par-repair disabled, exiting") + sys.exit(POSTPROCESS_NONE) + + if os.environ['NZBPP_PARSTATUS'] == 1: + Logger.warning("Par-check failed, setting status \"failed\"") + status = 1 + + # Check unpack status + if os.environ['NZBPP_UNPACKSTATUS'] == 1: + Logger.warning("Unpack failed, setting status \"failed\"") + status = 1 + + if os.environ['NZBPP_UNPACKSTATUS'] == 0 and os.environ['NZBPP_PARSTATUS'] != 2: + # Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check + + for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): + for file in filenames: + fileExtension = os.path.splitext(file)[1] + + if fileExtension in ['.rar', '.7z'] or os.path.splitext(fileExtension)[1] in ['.rar', '.7z']: + Logger.warning("Post-Process: Archive files exist but unpack skipped, exiting") + sys.exit(POSTPROCESS_NONE) + + if fileExtension in ['.par2']: + Logger.warning("Post-Process: Unpack skipped and par-check skipped (although par2-files exist), exiting") + sys.exit(POSTPROCESS_NONE) + + if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")): + Logger.warning("Post-Process: _brokenlog.txt exists, download is probably damaged, exiting") + sys.exit(POSTPROCESS_NONE) + + Logger.info("Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful") + + # Check if destination directory exists (important for reprocessing of history items) + if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): + Logger.error("Post-Process: Nothing to post-process: destination directory %s doesn't exist", os.environ['NZBPP_DIRECTORY']) + status = 1 + + # All checks done, now launching the script. + Logger.info("Script triggered from NZBGet, starting autoProcessComics...") + result = autoProcessComics.processEpisode(os.environ['NZBPP_DIRECTORY'], os.environ['NZBPP_NZBNAME'], status) # SABnzbd -if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: +elif len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file @@ -46,3 +171,12 @@ elif len(sys.argv) == NZBGET_NO_OF_ARGUMENTS: else: Logger.warn("Invalid number of arguments received from client. Exiting") sys.exit(-1) + +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) +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) diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index 4139b254..b4b54435 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -1,26 +1,113 @@ #!/usr/bin/env python +# +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### -# Author: Nic Wolfe -# URL: http://code.google.com/p/sickbeard/ +# Post-Process to SickBeard. # -# This file is part of Sick Beard. +# This script sends the download to your automated media management servers. # -# Sick Beard is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Sick Beard is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Sick Beard. If not, see . -# -# Edited by Clinton Hall to prevent processing of failed downloads. -# Also added suppot for NZBGet. With help from thorli +# NOTE: This script requires Python to be installed on your system. +############################################################################## +### OPTIONS ### + +## SickBeard + +# SickBeard script category. +# +# category that gets called for post-processing with SickBeard. +#sbCategory=tv + +# SickBeard host. +#sbhost=localhost + +# SickBeard port. +#sbport=8081 + +# SickBeard username. +#sbusername= + +# SickBeard password. +#sbpassword= + +# SickBeard uses ssl. +# +# Set to 1 if using ssl, else set to 0. +#sbssl=0 + +# SickBeard web_root +# +# set this if using a reverse proxy. +#sbweb_root= + +# SickBeard watch directory. +# +# set this if SickBeard and nzbGet are on different systems. +#sbwatch_dir= + +# SickBeard uses failed fork. +# +# set to 1 if using the custom "failed fork". Default sickBeard uses 0. +#sbfailed_fork=0 + +# SickBeard Delete Failed Downloads +# +# set to 1 to delete failed, or 0 to leave files in place. +#sbdelete_failed=0 + +## Extensions + +# Media Extensions +# +# This is a list of media extensions that may be transcoded if transcoder is enabled below. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## Transcoder] + +# Transcode +# +# set to 1 to transcode, otherwise set to 0. +#transcode=0 + +# create a duplicate, or replace the original. +# +# set to 1 to cretae a new file or 0 to replace the original +#duplicate=1 + +# ignore extensions +# +# list of extensions that won't be transcoded. +#ignoreExtensions=.avi,.mkv + +# ffmpeg output settings. +#outputVideoExtension=.mp4 +#outputVideoCodec=libx264 +#outputVideoPreset=medium +#outputVideoFramerate=24 +#outputVideoBitrate=800k +#outputAudioCodec=libmp3lame +#outputAudioBitrate=128k +#outputSubtitleCodec= + +## WakeOnLan + +# use WOL +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## import os import sys @@ -34,6 +121,9 @@ from autoProcess.nzbToMediaUtil import * #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(os.path.dirname(sys.argv[0])) Logger = logging.getLogger(__name__) @@ -43,8 +133,70 @@ Logger.info("nzbToSickBeard %s", VERSION) WakeUp +# 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).") + + # 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("Please enable option \"Unpack\" in nzbget configuration file, exiting") + sys.exit(POSTPROCESS_ERROR) + + # Check par status + if os.environ['NZBPP_PARSTATUS'] == 3: + Logger.warning("Par-check successful, but Par-repair disabled, exiting") + sys.exit(POSTPROCESS_NONE) + + if os.environ['NZBPP_PARSTATUS'] == 1: + Logger.warning("Par-check failed, setting status \"failed\"") + status = 1 + + # Check unpack status + if os.environ['NZBPP_UNPACKSTATUS'] == 1: + Logger.warning("Unpack failed, setting status \"failed\"") + status = 1 + + if os.environ['NZBPP_UNPACKSTATUS'] == 0 and os.environ['NZBPP_PARSTATUS'] != 2: + # Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check + + for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): + for file in filenames: + fileExtension = os.path.splitext(file)[1] + + if fileExtension in ['.rar', '.7z'] or os.path.splitext(fileExtension)[1] in ['.rar', '.7z']: + Logger.warning("Post-Process: Archive files exist but unpack skipped, exiting") + sys.exit(POSTPROCESS_NONE) + + if fileExtension in ['.par2']: + Logger.warning("Post-Process: Unpack skipped and par-check skipped (although par2-files exist), exiting") + sys.exit(POSTPROCESS_NONE) + + if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")): + Logger.warning("Post-Process: _brokenlog.txt exists, download is probably damaged, exiting") + sys.exit(POSTPROCESS_NONE) + + Logger.info("Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful") + + # Check if destination directory exists (important for reprocessing of history items) + if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): + Logger.error("Post-Process: Nothing to post-process: destination directory %s doesn't exist", os.environ['NZBPP_DIRECTORY']) + status = 1 + + # All checks done, now launching the script. + Logger.info("Script triggered from NZBGet, starting autoProcessTV...") + result = autoProcessTV.processEpisode(os.environ['NZBPP_DIRECTORY'], os.environ['NZBPP_NZBNAME'], status) # SABnzbd -if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: +elif len(sys.argv) == SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file @@ -69,3 +221,12 @@ else: Logger.debug("Invalid number of arguments received from client.") Logger.info("Running autoProcessTV as a manual run...") result = autoProcessTV.processEpisode('Manual Run', 'Manual Run', 0) + +if result == 0: + Logger.info("MAIN: The autoProcessTV script completed successfully.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_SUCCESS) +else: + Logger.info("MAIN: A problem was reported in the autoProcessTV script.") + if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 + sys.exit(POSTPROCESS_ERROR) diff --git a/nzbget-postprocessing-files/testing/README.md b/nzbget-postprocessing-files/testing/README.md index dabaf843..977cc5e6 100644 --- a/nzbget-postprocessing-files/testing/README.md +++ b/nzbget-postprocessing-files/testing/README.md @@ -1 +1,4 @@ Currently testing NZBGet V11 +NZBGet V11+ calls multiple scripts directly. This current configuration is no-longer used and the entire nzbget-postprocessing-files folder will be deleted once NZBGet V11 is stable. + +Please see http://nzbget.sourceforge.net/forum/viewtopic.php?f=3&t=740 for details of the new scripts concept. diff --git a/nzbget-postprocessing-files/testing/nzbget-postprocess.conf b/nzbget-postprocessing-files/testing/nzbget-postprocess.conf deleted file mode 100644 index 1c5ac244..00000000 --- a/nzbget-postprocessing-files/testing/nzbget-postprocess.conf +++ /dev/null @@ -1,175 +0,0 @@ -# -# This file if part of nzbget -# -# Template configuration file for post-processing script "nzbget-postprocess.sh". -# Please refer to "nzbget-postprocess.sh" for usage instructions. -# -# Copyright (C) 2008-2013 Andrey Prygunkov -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# - -############################################################################## -### PATHS ### - -# Set the full path to python if it is not in your PATH. -PythonCmd=/usr/local/python/bin/python - -# Set the full path to nzbToSickBeard.py for SickBeard's postprocessing. -NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py - -# Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing -NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py - -# Set the full path to nzbToHeadPhones.py for HeadPhones's postprocessing. -NzbToHeadPhones=/usr/local/nzbget/var/nzbToHeadPhones.py - -# Set the full path to nzbToMylar.py for Mylar's postprocessing. -NzbToMylar=/usr/local/nzbget/var/nzbToMylar.py - -# Set the full path to nzbToGamez.py for Gamez's postprocessing. -NzbToGamez=/usr/local/nzbget/var/nzbToGamez.py - -# Set the full path to any dependency required for your Custom -# Postprocess script if it is not in your PATH. -CustomCmd=/usr/local/python/bin/python - -# Set the full path to the Custom Postprocess script. -CustomScript= - -# Set the full path to location to move failed downloads to. -Failed_Directory=/usr/local/downloads/failed - -############################################################################## -### OPTIONS ### - -# Rename img-files to iso (yes, no). -RenameIMG=yes - -# Joint TS-files (yes, no). -JoinTS=yes - -# Perform SickBeard's postprocessing (yes, no). -SickBeard=yes - -# Category for SickBeard's postprocessing. -SickBeardCategory=tv - -# Perform Couchpotato's postprocessing (yes, no). -CouchPotato=yes - -# Category for Couchpotato's postprocessing. -CouchPotatoCategory=movies - -# Perform HeadPhones' postprocessing (yes, no). -HeadPhones=yes - -# Category for HeadPhones' postprocessing. -HeadPhonesCategory=music - -# Perform Mylar's postprocessing (yes, no). -Mylar=yes - -# Category for Mylar's postprocessing. -MylarCategory=comics - -# Perform Gamez's postprocessing (yes, no). -Gamez=yes - -# Category for Gamez's postprocessing. -GamezCategory=games - -# Perform Custom postprocessing (yes, no). -Custom=yes - -# Category for Custom postprocessing (eg. pictures) -CustomCategory=pictures - -# Clean up list. space seperated, in single quotes, default '*.nzb *.sfv *.1' -FileCleanUp='*.nzb *.sfv *.1' - -# Remove all files when download fails (yes, no). -Delete_Failed=no - -# Toggle detailed output (yes, no). -Debug=no - -############################################################################## -### POSTPROCESSING-PARAMETERS ### - -# This section defines parameters, which can be set for each nzb-file -# individually using either web-interface or command line. -# Example command line for setting parameter "PostProcess" to value "no" for -# nzb-file with id=2: -# nzbget -E G O PostProcess=no 2 - -# Perform postprocessing (yes, no). -# -# Set to "no" to skip postprocessing for this nzb-file. -PostProcess=yes - -# Destination directory. -DestDir= - -############################################################################## -### EMAIL-PARAMETERS ### - -# This section defines parameters, which can be set to allow notifications to -# be sent via email. -# This uses sendEmail as authored by Brandon Zehm - -# List Categories for successful download email, default 'tv movies' -Email_successful='tv movies music comics games pictures' - -# List Categories for failed download email, default 'tv movies' -Email_failed='tv movies music comics games pictures' - -# Set the full path and file name for sendEmail application. -sendEmail=/usr/local/nzbget/var/sendEmail/sendEmail - -# Enter the email address you want this email to be sent from. -Email_From= - -# Enter the email address you want this email to be sent to. -Email_To= - -# Enter smtp server and port. eg smtp.live.com:25 -Email_Server= - -# Server uses tsl (auto, yes, no). -Tls=auto - -# Enter your smtp server user name (if required) -Email_User= - -# Enter your smtp server password (if required) -Email_Pass= - -# Enter your email subject, in single quotes. -# Use the following tags between the less than and greater than symbols. -# Use status to add 'completed'/'failed'. -# Use name to add the nzb name. -# Use cat to add the download categoty. -# Use script to name the external script used. -Email_Subject='The download of has .' - -# Enter your email message, in single quotes. -# Use the same substitutes as described above. -# Use
for new line. -Email_Message='The download of has .
This has been processed by the script