From d52e4acd7391d99e9cfc07dbbe24e36d2be154b1 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 3 Apr 2014 01:39:45 +0100 Subject: [PATCH 1/9] Ignore all logs, even if there is more than one --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a9ed5401..d47fee77 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,6 @@ autoProcessMedia.cfg *.pyc *.pyo -postprocess.log +postprocess.log* /.idea/ *.cfg.old From ab375502171e68bae5d0b25b5b617a5de973df08 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 3 Apr 2014 11:19:21 +1030 Subject: [PATCH 2/9] fix description for NZBGet --- nzbToCouchPotato.py | 2 +- nzbToMedia.py | 2 +- nzbToSickBeard.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py index 728ffdfe..c83ee915 100755 --- a/nzbToCouchPotato.py +++ b/nzbToCouchPotato.py @@ -72,7 +72,7 @@ # Media Extensions # -# This is a list of media extensions that may be transcoded if transcoder is enabled below. +# This is a list of media extensions that are used to verify that the download does contain valid media. #mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso ## Transcoder diff --git a/nzbToMedia.py b/nzbToMedia.py index 01392f89..b8446a56 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -222,7 +222,7 @@ # Media Extensions # -# This is a list of media extensions that may be transcoded if transcoder is enabled below. +# This is a list of media extensions that are used to verify that the download does contain valid media. #mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso ## Transcoder diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index bf32077a..db90be10 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -75,7 +75,7 @@ # Media Extensions # -# This is a list of media extensions that may be transcoded if transcoder is enabled below. +# This is a list of media extensions that are used to verify that the download does contain valid media. #mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso ## Transcoder From fc7ba70c6a001232b7f0ed1f705766ba50688172 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 3 Apr 2014 12:18:44 +1030 Subject: [PATCH 3/9] remove extra mvoing of files. HP now allows Directory to be set. --- TorrentToMedia.py | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 3b91515d..1507d29b 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -120,11 +120,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): Logger.debug("MAIN: Scanning files in directory: %s", inputDirectory) - if inputCategory in hpCategory: - noFlatten.extend(hpCategory) # Make sure we preserve folder structure for HeadPhones. - if useLink in ['sym','move']: # These don't work for HeadPhones. - useLink = 'no' # default to copy. - + noFlatten.extend(hpCategory) # Make sure we preserve folder structure for HeadPhones. if inputCategory in sbCategory and sbFork in SICKBEARD_TORRENT: # Don't flatten when sending to SICKBEARD_TORRENT noFlatten.extend(sbCategory) @@ -197,13 +193,6 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): Logger.exception("MAIN: Failed to link file: %s", file) continue elif fileExtension in compressedContainer: - if inputCategory in hpCategory: # We need to link all files for HP in order to move these back to support seeding. - Logger.info("MAIN: Linking compressed archive file %s for file %s", fileExtension, filePath) - try: - copy_link(filePath, targetDirectory, useLink, outputDestination) - copy_list.append([filePath, os.path.join(outputDestination, file)]) - except: - Logger.exception("MAIN: Failed to link file: %s", file) # find part numbers in second "extension" from right, if we have more than 1 compressed file in the same directory. if re.search(r'\d+', os.path.splitext(fileName)[1]) and os.path.dirname(filePath) in extracted_folder and not any(item in os.path.splitext(fileName)[1] for item in ['.720p','.1080p','.x264']): part = int(re.search(r'\d+', os.path.splitext(fileName)[1]).group()) @@ -214,10 +203,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): continue Logger.info("MAIN: Found compressed archive %s for file %s", fileExtension, filePath) try: - if inputCategory in hpCategory: # HP needs to scan the same dir as passed to downloader. - extractor.extract(filePath, inputDirectory) - else: - extractor.extract(filePath, outputDestination) + extractor.extract(filePath, outputDestination) extractionSuccess = True # we use this variable to determine if we need to pause a torrent or not in uTorrent (don't need to pause archived content) extracted_folder.append(os.path.dirname(filePath)) except: @@ -283,7 +269,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): result = autoProcessTV.processEpisode(outputDestination, inputName, status, clientAgent, inputCategory) elif inputCategory in hpCategory: Logger.info("MAIN: Calling HeadPhones to post-process: %s", inputName) - result = autoProcessMusic.process(inputDirectory, inputName, status, inputCategory) + result = autoProcessMusic.process(outputDestination, inputName, status, inputCategory) elif inputCategory in mlCategory: Logger.info("MAIN: Calling Mylar to post-process: %s", inputName) result = autoProcessComics.processEpisode(outputDestination, inputName, status, inputCategory) @@ -294,25 +280,6 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): if result == 1: Logger.info("MAIN: A problem was reported in the autoProcess* script. If torrent was paused we will resume seeding") - if inputCategory in hpCategory: - # we need to move the output dir files back... - Logger.debug("MAIN: Moving temporary HeadPhones files back to allow seeding.") - for item in copy_list: - if os.path.isfile(os.path.normpath(item[1])): # check to ensure temp files still exist. - if os.path.isfile(os.path.normpath(item[0])): # both exist, remove temp version - Logger.debug("MAIN: File %s still present. Removing tempoary file %s", str(item[0]), str(item[1])) - os.unlink(os.path.normpath(item[1])) - continue - else: # move temp version back to allow seeding or Torrent removal. - Logger.debug("MAIN: Moving %s to %s", str(item[1]), str(item[0])) - newDestination = os.path.split(os.path.normpath(item[0])) - try: - copy_link(os.path.normpath(item[1]), os.path.normpath(item[0]), 'move', newDestination[0]) - except: - Logger.exception("MAIN: Failed to move file: %s", file) - continue - shutil.rmtree(outputDestination) - # Hardlink solution for uTorrent, need to implent support for deluge, transmission if clientAgent in ['utorrent', 'transmission', 'deluge'] and inputHash: # Delete torrent and torrentdata from Torrent client if processing was successful. From e3bb60aa57f4fb975c3e519db44a0823dfbc278d Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 3 Apr 2014 12:50:35 +1030 Subject: [PATCH 4/9] change handling of SB_Torrent. --- TorrentToMedia.py | 21 +++------------------ autoProcess/autoProcessTV.py | 8 +++++++- autoProcess/migratecfg.py | 2 ++ autoProcessMedia.cfg.sample | 2 +- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 1507d29b..cdf976df 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -40,7 +40,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): sbFork, sbParams = autoFork() - if inputCategory in sbCategory and sbFork in SICKBEARD_TORRENT and Torrent_ForceLink != 1: + if inputCategory in sbCategory and sbFork in SICKBEARD_TORRENT and Torrent_NoLink == 1: Logger.info("MAIN: Calling SickBeard's %s branch to post-process: %s",sbFork ,inputName) result = autoProcessTV.processEpisode(inputDirectory, inputName, int(0)) if result == 1: @@ -121,8 +121,6 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): Logger.debug("MAIN: Scanning files in directory: %s", inputDirectory) noFlatten.extend(hpCategory) # Make sure we preserve folder structure for HeadPhones. - if inputCategory in sbCategory and sbFork in SICKBEARD_TORRENT: # Don't flatten when sending to SICKBEARD_TORRENT - noFlatten.extend(sbCategory) outputDestinationMaster = outputDestination # Save the original, so we can change this within the loop below, and reset afterwards. now = datetime.datetime.now() @@ -163,15 +161,6 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): else: continue # This file has not been recently moved or created, skip it - if inputCategory in sbCategory and sbFork in SICKBEARD_TORRENT: # We want to link every file. - Logger.info("MAIN: Found file %s in %s", fileExtension, filePath) - try: - copy_link(filePath, targetDirectory, useLink, outputDestination) - copy_list.append([filePath, os.path.join(outputDestination, file)]) - except: - Logger.exception("MAIN: Failed to link file: %s", file) - continue - if fileExtension in mediaContainer: # If the file is a video file if is_sample(filePath, inputName, minSampleSize, SampleIDs) and not inputCategory in hpCategory: # Ignore samples Logger.info("MAIN: Ignoring sample file: %s ", filePath) @@ -223,7 +212,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): flatten(outputDestination) # Now check if movie files exist in destination: - if inputCategory in cpsCategory + sbCategory and not (inputCategory in sbCategory and sbFork in SICKBEARD_TORRENT): + if inputCategory in cpsCategory + sbCategory: for dirpath, dirnames, filenames in os.walk(outputDestination): for file in filenames: filePath = os.path.join(dirpath, file) @@ -243,10 +232,6 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): else: Logger.debug("MAIN: Found %s media files in output. %s were found in input", str(video2), str(video)) - if inputCategory in sbCategory and sbFork in SICKBEARD_TORRENT: - if len(copy_list) > 0: - Logger.debug("MAIN: Found and linked %s files", str(len(copy_list))) - status = int(0) processCategories = cpsCategory + sbCategory + hpCategory + mlCategory + gzCategory @@ -449,7 +434,7 @@ if __name__ == "__main__": cpsCategory = (config().get("CouchPotato", "cpsCategory")).split(',') # movie sbCategory = (config().get("SickBeard", "sbCategory")).split(',') # tv - Torrent_ForceLink = int(config().get("SickBeard", "Torrent_ForceLink")) # 1 + Torrent_NoLink = int(config().get("SickBeard", "Torrent_NoLink")) # 0 hpCategory = (config().get("HeadPhones", "hpCategory")).split(',') # music mlCategory = (config().get("Mylar", "mlCategory")).split(',') # comics gzCategory = (config().get("Gamez", "gzCategory")).split(',') # games diff --git a/autoProcess/autoProcessTV.py b/autoProcess/autoProcessTV.py index 2cb3a3c7..70163467 100644 --- a/autoProcess/autoProcessTV.py +++ b/autoProcess/autoProcessTV.py @@ -98,6 +98,10 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent = "manual", process_method = config().get(section, "process_method") except config.NoOptionError: process_method = None + try: + Torrent_NoLink = int(config().get(section, "Torrent_NoLink")) + except (config.NoOptionError, ValueError): + Torrent_NoLink = 0 mediaContainer = (config().get("Extensions", "mediaExtensions")).split(',') minSampleSize = int(config().get("Extensions", "minSampleSize")) @@ -160,7 +164,9 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent = "manual", params[param] = dirName if param == "process_method": - if process_method: + if fork in SICKBEARD_TORRENT and Torrent_NoLink == 1 and not clientAgent in ['nzbget','sabnzbd']: #use default SickBeard settings here. + del params[param] + elif process_method: params[param] = process_method else: del params[param] diff --git a/autoProcess/migratecfg.py b/autoProcess/migratecfg.py index 9dc8c7c8..9d9d9841 100644 --- a/autoProcess/migratecfg.py +++ b/autoProcess/migratecfg.py @@ -31,6 +31,8 @@ def migrate(): value = "auto" if option == "fork" and value not in ["default", "failed", "failed-torrent", "auto"]: value = "auto" + if option == "Torrent_ForceLink": + continue if option == "outputDirectory": # move this to new location format value = os.path.split(os.path.normpath(value))[0] confignew.set("Torrent", option, value) diff --git a/autoProcessMedia.cfg.sample b/autoProcessMedia.cfg.sample index 97731862..ca174642 100644 --- a/autoProcessMedia.cfg.sample +++ b/autoProcessMedia.cfg.sample @@ -37,7 +37,7 @@ watch_dir = fork = auto delete_failed = 0 nzbExtractionBy = Downloader -Torrent_ForceLink = 1 +Torrent_NoLink = 0 process_method = From 288e001fb3b1f7b909e5f015e53be1f05a518d87 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 3 Apr 2014 13:27:43 +1030 Subject: [PATCH 5/9] update changelog. --- changelog.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 09efd408..2344c650 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,7 +7,9 @@ Allow Headphones to remove torrents and data after processing. Delete torrent if uselink = move Added forceClean for outputDir. Works in file permissions prevent CP/SB from moving files. Ignore .x264 from archive "part" checks. -Added dynamic timeout based on directory size. +Changed handling of TPB/Pistachitos SB forks. Default is to link/extract here. Disabled by Torrent_NoLink = 1. +Changed handling for HeadPhones Now that HeadPhones allows process directory to be defined. + Impacts NZBs Fix setting of Mylar config from NZBGet. @@ -16,6 +18,8 @@ Impacts All Changes to Couchpotato API for [nosql] added. Keeps aligned with current CouchPotato develop branch. Add Auto Detection of SickBeard Fork. Thanks @echel0n Added config class, re-coded migratecfg, misc bugfixes and code cleanup. Thanks @echel0n +Added dynamic timeout based on directory size. +Added process_Method for SickBeard. V9.2 05/03/2014 From 205f5d93837b0628124ba0a67874cba59f023455 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Fri, 4 Apr 2014 09:07:42 +1030 Subject: [PATCH 6/9] use category in autofork. fixes #306 --- TorrentToMedia.py | 18 +++++++++--------- autoProcess/autoProcessTV.py | 2 +- autoProcess/autoSickBeardFork.py | 5 ++++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index cdf976df..038996de 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -38,15 +38,15 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): Logger.debug("MAIN: Determined Directory: %s | Name: %s | Category: %s", inputDirectory, inputName, inputCategory) - sbFork, sbParams = autoFork() - - if inputCategory in sbCategory and sbFork in SICKBEARD_TORRENT and Torrent_NoLink == 1: - Logger.info("MAIN: Calling SickBeard's %s branch to post-process: %s",sbFork ,inputName) - result = autoProcessTV.processEpisode(inputDirectory, inputName, int(0)) - if result == 1: - Logger.info("MAIN: A problem was reported in the autoProcess* script.") - Logger.info("MAIN: All done.") - sys.exit() + if inputCategory in sbCategory: + sbFork, sbParams = autoFork(inputCategory) + if sbFork in SICKBEARD_TORRENT and Torrent_NoLink == 1: + Logger.info("MAIN: Calling SickBeard's %s branch to post-process: %s",sbFork ,inputName) + result = autoProcessTV.processEpisode(inputDirectory, inputName, int(0)) + if result == 1: + Logger.info("MAIN: A problem was reported in the autoProcess* script.") + Logger.info("MAIN: All done.") + sys.exit() outputDestination = "" for category in categories: diff --git a/autoProcess/autoProcessTV.py b/autoProcess/autoProcessTV.py index 70163467..cc97499e 100644 --- a/autoProcess/autoProcessTV.py +++ b/autoProcess/autoProcessTV.py @@ -117,7 +117,7 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent = "manual", dirName = SpecificPath # auto-detect fork type - fork, params = autoFork() + fork, params = autoFork(inputCategory) if fork not in SICKBEARD_TORRENT or (clientAgent in ['nzbget','sabnzbd'] and nzbExtractionBy != "Destination"): if nzbName: diff --git a/autoProcess/autoSickBeardFork.py b/autoProcess/autoSickBeardFork.py index c1aef3c9..b2d7decc 100644 --- a/autoProcess/autoSickBeardFork.py +++ b/autoProcess/autoSickBeardFork.py @@ -24,10 +24,13 @@ class AuthURLOpener(urllib.FancyURLopener): self.numTries = 0 return urllib.FancyURLopener.open(self, url) -def autoFork(): +def autoFork(inputCategory = None): # config settings section = "SickBeard" + if inputCategory != None and config().has_section(inputCategory): + section = inputCategory + host = config().get(section, "host") port = config().get(section, "port") username = config().get(section, "username") From 5165ee31bab4b00b86a86109f4386f5082fa8542 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Fri, 4 Apr 2014 09:39:26 +1030 Subject: [PATCH 7/9] log warning, prevent crash, and exit gracefully if no manual directories defined. --- autoProcess/nzbToMediaUtil.py | 15 +++++++++------ nzbToMedia.py | 2 +- nzbToSickBeard.py | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/autoProcess/nzbToMediaUtil.py b/autoProcess/nzbToMediaUtil.py index e849e3a8..6792629f 100644 --- a/autoProcess/nzbToMediaUtil.py +++ b/autoProcess/nzbToMediaUtil.py @@ -467,14 +467,17 @@ def get_dirnames(section, category): outputDirectory = "" # set dirName - dirNames = None + dirNames = [] if watch_dir != "": if os.path.exists(watch_dir): - dirNames = [os.path.join(watch_dir, o) for o in os.listdir(watch_dir) if - os.path.isdir(os.path.join(watch_dir, o))] - elif outputDirectory != "": + dirNames.extend([os.path.join(watch_dir, o) for o in os.listdir(watch_dir) if + os.path.isdir(os.path.join(watch_dir, o))]) + if outputDirectory != "": if os.path.exists(outputDirectory): - dirNames = [os.path.join(outputDirectory, o) for o in os.listdir(outputDirectory) if - os.path.isdir(os.path.join(outputDirectory, o))] + dirNames.extend([os.path.join(outputDirectory, o) for o in os.listdir(outputDirectory) if + os.path.isdir(os.path.join(outputDirectory, o))]) + + if not dirNames: + Logger.warn("No Directories identified to Scan.") return dirNames \ No newline at end of file diff --git a/nzbToMedia.py b/nzbToMedia.py index b8446a56..58a48b80 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -414,7 +414,7 @@ if inputCategory in cpsCategory: Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName) result = autoProcessMovie.process(nzbDir, inputName, status, clientAgent, download_id, inputCategory) elif inputCategory in sbCategory: - result = 0 + result = 1 if isinstance(nzbDir, list): for dirName in nzbDir: Logger.info("MAIN: Calling Sick-Beard to post-process: %s", inputName) diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index fef4a4a6..b694d7cc 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -229,13 +229,13 @@ elif len(sys.argv) >= SABNZB_0717_NO_OF_ARGUMENTS: clientAgent = "sabnzbd" result = autoProcessTV.processEpisode(sys.argv[1], sys.argv[2], sys.argv[7], clientAgent, sys.argv[5]) else: - result = 0 - sbCategory = (config().get("SickBeard", "sbCategory")).split(',') # tv - dirNames = get_dirnames("SickBeard", sbCategory[0]) - Logger.debug("MAIN: Invalid number of arguments received from client.") Logger.info("MAIN: Running autoProcessTV as a manual run...") + result = 1 + sbCategory = (config().get("SickBeard", "sbCategory")).split(',') # tv + dirNames = get_dirnames("SickBeard", sbCategory[0]) + for dirName in dirNames: Logger.info("MAIN: Calling Sick-Beard to post-process: %s", dirName) result = autoProcessTV.processEpisode(dirName, dirName, 0) From 9cff2032b0640e1412c374643ba7fad5e96b6844 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Fri, 4 Apr 2014 09:58:24 +1030 Subject: [PATCH 8/9] another manual run fix --- nzbToMedia.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nzbToMedia.py b/nzbToMedia.py index 58a48b80..f11511d6 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -405,6 +405,8 @@ else: # only CPS and SB supports this manual run for now. Logger.info("MAIN: Running autoProcessMovie as a manual run...") nzbDir, inputName, status, inputCategory, download_id = ('Manual Run', 'Manual Run', 0, cpsCategory[0], '') + Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName) + result = autoProcessMovie.process(nzbDir, inputName, status, clientAgent, download_id, inputCategory) Logger.info("MAIN: Running autoProcessTV as a manual run...") dirNames = get_dirnames("SickBeard", sbCategory[0]) @@ -414,12 +416,13 @@ if inputCategory in cpsCategory: Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName) result = autoProcessMovie.process(nzbDir, inputName, status, clientAgent, download_id, inputCategory) elif inputCategory in sbCategory: - result = 1 if isinstance(nzbDir, list): + result1 = 1 for dirName in nzbDir: Logger.info("MAIN: Calling Sick-Beard to post-process: %s", inputName) result = autoProcessTV.processEpisode(dirName, dirName, status, clientAgent, inputCategory) - if result !=0:break + if result1 !=0:break + result += result1 else: Logger.info("MAIN: Calling Sick-Beard to post-process: %s", inputName) result = autoProcessTV.processEpisode(nzbDir, inputName, status, clientAgent, inputCategory) From 30890428b97cf414f7d56108635fe898ddcb3a40 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Fri, 4 Apr 2014 15:55:24 +1030 Subject: [PATCH 9/9] keep these scripts independent --- DeleteSamples.py | 16 ++++++++++------ ResetDateTime.py | 17 +++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/DeleteSamples.py b/DeleteSamples.py index 4386af29..67e70550 100644 --- a/DeleteSamples.py +++ b/DeleteSamples.py @@ -31,8 +31,12 @@ ############################################################################## import os import sys -from nzbtomedia.nzbToMediaConfig import config +# NZBGet argv: all passed as environment variables. +# Exit codes used by NZBGet +POSTPROCESS_SUCCESS=93 +POSTPROCESS_ERROR=94 +POSTPROCESS_NONE=95 def is_sample(filePath, inputName, maxSampleSize, SampleIDs): # 200 MB in bytes @@ -58,13 +62,13 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 if os.environ['NZBOP_UNPACK'] != 'yes': print "Please enable option \"Unpack\" in nzbget configuration file, exiting." - sys.exit(config.NZBGET_POSTPROCESS_ERROR) + sys.exit(POSTPROCESS_ERROR) # 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(config.NZBGET_POSTPROCESS_NONE) + sys.exit(POSTPROCESS_NONE) if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': print "Par-repair failed, setting status \"failed\"." @@ -95,7 +99,7 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 # All checks done, now launching the script. if status == 1: - sys.exit(config.NZBGET_POSTPROCESS_NONE) + sys.exit(POSTPROCESS_NONE) mediaContainer = os.environ['NZBPO_MEDIAEXTENSIONS'].split(',') SampleIDs = os.environ['NZBPO_SAMPLEIDS'].split(',') @@ -112,8 +116,8 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 os.unlink(filePath) except: print "Error: unable to delete file", filePath - sys.exit(config.NZBGET_POSTPROCESS_ERROR) - sys.exit(config.NZBGET_POSTPROCESS_SUCCESS) + sys.exit(POSTPROCESS_ERROR) + sys.exit(POSTPROCESS_SUCCESS) else: print "This script can only be called from NZBGet (11.0 or later)." diff --git a/ResetDateTime.py b/ResetDateTime.py index 20ac62ca..5d7c01c4 100644 --- a/ResetDateTime.py +++ b/ResetDateTime.py @@ -17,7 +17,12 @@ # Check if the script is called from nzbget 11.0 or later import os import sys -from nzbtomedia.nzbToMediaConfig import config + +# NZBGet argv: all passed as environment variables. +# Exit codes used by NZBGet +POSTPROCESS_SUCCESS=93 +POSTPROCESS_ERROR=94 +POSTPROCESS_NONE=95 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)." @@ -27,13 +32,13 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 if os.environ['NZBOP_UNPACK'] != 'yes': print "Please enable option \"Unpack\" in nzbget configuration file, exiting." - sys.exit(config.NZBGET_POSTPROCESS_ERROR) + sys.exit(POSTPROCESS_ERROR) # 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(config.NZBGET_POSTPROCESS_NONE) + sys.exit(POSTPROCESS_NONE) if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': print "Par-repair failed, setting status \"failed\"." @@ -64,7 +69,7 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 # All checks done, now launching the script. if status == 1: - sys.exit(config.NZBGET_POSTPROCESS_NONE) + sys.exit(POSTPROCESS_NONE) directory = os.path.normpath(os.environ['NZBPP_DIRECTORY']) for dirpath, dirnames, filenames in os.walk(directory): @@ -76,8 +81,8 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 continue except: print "Error: unable to reset time for file", file - sys.exit(config.NZBGET_POSTPROCESS_ERROR) - sys.exit(config.NZBGET_POSTPROCESS_SUCCESS) + sys.exit(POSTPROCESS_ERROR) + sys.exit(POSTPROCESS_SUCCESS) else: print "This script can only be called from NZBGet (11.0 or later)."