diff --git a/DeleteSamples.py b/DeleteSamples.py index 03956f6c..6ca3b23b 100755 --- a/DeleteSamples.py +++ b/DeleteSamples.py @@ -45,26 +45,24 @@ def is_sample(filePath, inputName, maxSampleSize, SampleIDs): return True # Return False if none of these were met. return False + +if not os.environ.has_key('NZBOP_SCRIPTDIR'): + print "This script can only be called from NZBGet (11.0 or later)." + sys.exit(0) +if os.environ['NZBOP_VERSION'][0:5] < '11.0': + print "NZBGet Version %s is not supported. Please update NZBGet." % (str(os.environ['NZBOP_VERSION'][0:5])) + sys.exit(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': - print "Script triggered from NZBGet (11.0 or later)." - - # Check nzbget.conf options - status = 0 - - if os.environ['NZBOP_UNPACK'] != 'yes': - print "Please enable option \"Unpack\" in nzbget configuration file, exiting." - sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) +print "Script triggered from NZBGet Version %s." % (str(os.environ['NZBOP_VERSION'][0:5])) +status = 0 +if os.environ.has_key('NZBPP_TOTALSTATUS'): + if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS': + print "Download failed with status %s." % (os.environ['NZBPP_STATUS'])) + status = 1 +else: # Check par status - if os.environ['NZBPP_PARSTATUS'] == '3': - print "Par-check successful, but Par-repair disabled, exiting." - print "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': print "Par-repair failed, setting status \"failed\"." status = 1 @@ -86,33 +84,27 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 print "Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful." print "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']): - print "Nothing to post-process: destination directory", os.environ['NZBPP_DIRECTORY'], "doesn't exist. Setting status \"failed\"." - status = 1 +# Check if destination directory exists (important for reprocessing of history items) +if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): + print "Nothing to post-process: destination directory", os.environ['NZBPP_DIRECTORY'], "doesn't exist. Setting status \"failed\"." + status = 1 - # All checks done, now launching the script. +# All checks done, now launching the script. +if status == 1: + sys.exit(nzbtomedia.NZBGET_POSTPROCESS_NONE) - if status == 1: - sys.exit(nzbtomedia.NZBGET_POSTPROCESS_NONE) - - mediaContainer = os.environ['NZBPO_MEDIAEXTENSIONS'].split(',') - SampleIDs = os.environ['NZBPO_SAMPLEIDS'].split(',') - for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): - for file in filenames: - - filePath = os.path.join(dirpath, file) - fileName, fileExtension = os.path.splitext(file) - - if fileExtension in mediaContainer: # If the file is a video file - if is_sample(filePath, os.environ['NZBPP_NZBNAME'], os.environ['NZBPO_MAXSAMPLESIZE'], SampleIDs): # Ignore samples - print "Deleting sample file: ", filePath - try: - os.unlink(filePath) - except: - print "Error: unable to delete file", filePath - sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) - sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS) -else: - print "This script can only be called from NZBGet (11.0 or later)." - sys.exit(0) +mediaContainer = os.environ['NZBPO_MEDIAEXTENSIONS'].split(',') +SampleIDs = os.environ['NZBPO_SAMPLEIDS'].split(',') +for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): + for file in filenames: + filePath = os.path.join(dirpath, file) + fileName, fileExtension = os.path.splitext(file) + if fileExtension in mediaContainer: # If the file is a video file + if is_sample(filePath, os.environ['NZBPP_NZBNAME'], os.environ['NZBPO_MAXSAMPLESIZE'], SampleIDs): # Ignore samples + print "Deleting sample file: ", filePath + try: + os.unlink(filePath) + except: + print "Error: unable to delete file", filePath + sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) +sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS) diff --git a/ResetDateTime.py b/ResetDateTime.py index d45d9fca..1ba0730d 100755 --- a/ResetDateTime.py +++ b/ResetDateTime.py @@ -16,22 +16,23 @@ import os import sys import nzbtomedia -if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5] < '11.0': - print "Script triggered from NZBGet (11.0 or later)." +if not os.environ.has_key('NZBOP_SCRIPTDIR'): + print "This script can only be called from NZBGet (11.0 or later)." + sys.exit(0) - # Check nzbget.conf options - status = 0 +if os.environ['NZBOP_VERSION'][0:5] < '11.0': + print "NZBGet Version %s is not supported. Please update NZBGet." % (str(os.environ['NZBOP_VERSION'][0:5])) + sys.exit(0) - if os.environ['NZBOP_UNPACK'] != 'yes': - print "Please enable option \"Unpack\" in nzbget configuration file, exiting." - sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) +print "Script triggered from NZBGet Version %s." % (str(os.environ['NZBOP_VERSION'][0:5])) +status = 0 +if os.environ.has_key('NZBPP_TOTALSTATUS'): + if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS': + print "Download failed with status %s." % (os.environ['NZBPP_STATUS'])) + status = 1 +else: # Check par status - if os.environ['NZBPP_PARSTATUS'] == '3': - print "Par-check successful, but Par-repair disabled, exiting." - print "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': print "Par-repair failed, setting status \"failed\"." status = 1 @@ -53,29 +54,24 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 print "Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful." print "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']): - print "Nothing to post-process: destination directory", os.environ['NZBPP_DIRECTORY'], "doesn't exist. Setting status \"failed\"." - status = 1 +# Check if destination directory exists (important for reprocessing of history items) +if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): + print "Nothing to post-process: destination directory", os.environ['NZBPP_DIRECTORY'], "doesn't exist. Setting status \"failed\"." + status = 1 - # All checks done, now launching the script. +# All checks done, now launching the script. +if status == 1: + sys.exit(nzbtomedia.NZBGET_POSTPROCESS_NONE) - if status == 1: - sys.exit(nzbtomedia.NZBGET_POSTPROCESS_NONE) - - directory = os.path.normpath(os.environ['NZBPP_DIRECTORY']) - for dirpath, dirnames, filenames in os.walk(directory): - for file in filenames: - filepath = os.path.join(dirpath, file) - print "reseting datetime for file", filepath - try: - os.utime(filepath, None) - continue - except: - print "Error: unable to reset time for file", file - sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) - sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS) - -else: - print "This script can only be called from NZBGet (11.0 or later)." - sys.exit(0) +directory = os.path.normpath(os.environ['NZBPP_DIRECTORY']) +for dirpath, dirnames, filenames in os.walk(directory): + for file in filenames: + filepath = os.path.join(dirpath, file) + print "reseting datetime for file", filepath + try: + os.utime(filepath, None) + continue + except: + print "Error: unable to reset time for file", file + sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) +sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS) diff --git a/nzbToMedia.py b/nzbToMedia.py index b6b14b1f..598809c4 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -415,6 +415,11 @@ def main(args, section=None): # NZBGet if os.environ.has_key('NZBOP_SCRIPTDIR'): + # Check if the script is called from nzbget 11.0 or later + if os.environ['NZBOP_VERSION'][0:5] < '11.0': + logger.error("NZBGet Version %s is not supported. Please update NZBGet." %(str(os.environ['NZBOP_VERSION'][0:5]))) + sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) + logger.info("Script triggered from NZBGet Version %s." %(str(os.environ['NZBOP_VERSION'][0:5]))) # Check if the script is called from nzbget 13.0 or later @@ -423,12 +428,8 @@ def main(args, section=None): logger.info("Download failed with status %s." %(os.environ['NZBPP_STATUS'])) status = 1 - # Check if the script is called from nzbget 11.0 or later - elif os.environ['NZBOP_VERSION'][0:5] < '11.0': - logger.error("NZBGet Version %s is not supported. Please update NZBGet." %(str(os.environ['NZBOP_VERSION'][0:5]))) - sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) - else: + # Check par status if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': logger.warning("Par-repair failed, setting status \"failed\"") status = 1