diff --git a/README.md b/README.md index 437bf83b..260f08b2 100644 --- a/README.md +++ b/README.md @@ -237,8 +237,9 @@ If you are using NZBGet perform the following steps to configure postprocessing 2. In NZBGet go to "POSTPROCESSING SCRIPT" -> "PATHS" and change as needed: - i. Set the full path to python if it is not in your PATH. - + i. Set the full path to python if it is not in your PATH. (option is required) + These scripts now have -x permissions and should be as such on your system. Python needs to be in your system path. + PythonCmd=/usr/local/python/bin/python ii. Set the full path to sabToSickBeard.py for SickBeard's postprocessing. @@ -246,6 +247,7 @@ If you are using NZBGet perform the following steps to configure postprocessing NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py iii. Set the full path where completed movies should be placed before SickBeard's Renamer is called (option) + (v 9.0 only). For n 10.0 set this in the appropriate category settings in the Categories Section. TvDownloadDir= @@ -254,10 +256,11 @@ If you are using NZBGet perform the following steps to configure postprocessing NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py v. Set the full path where completed movies should be placed before CouchPotato's Renamer is called (option) + (v 9.0 only). For n 10.0 set this in the appropriate category settings in the Categories Section. MoviesDownloadDir= - vi. Set the full path to any dependency required for your Custom Postprocess script if it is not in your PATH. + vi. Set the full path to any dependency required for your Custom Postprocess script if it is not in your PATH.(option is required) CustomCmd=/usr/local/python/bin/python @@ -266,6 +269,7 @@ If you are using NZBGet perform the following steps to configure postprocessing CustomScript= viii.Set the full path where completed downloads should be placed before the Custom postprocess is called (option) + (v 9.0 only). For n 10.0 set this in the appropriate category settings in the Categories Section. CustomDownloadDir= diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 169c37c0..c77530d5 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -12,6 +12,13 @@ import autoProcessMovie import autoProcessTV from nzbToMediaEnv import * +Logger = logging.getLogger() +logFile = os.path.join(os.path.dirname(sys.argv[0]), "postprocess.log") +logging.config.fileConfig(os.path.join(os.path.dirname(sys.argv[0]), "logger.conf")) +fileHandler = logging.FileHandler(logFile, encoding='utf-8', delay=True) +fileHandler.formatter = logging.Formatter('%(asctime)s|%(levelname)-7.7s %(message)s', '%H:%M:%S') +fileHandler.level = logging.DEBUG +Logger.addHandler(fileHandler) def removeEmptyFolders(path): if not os.path.isdir(path): @@ -28,14 +35,15 @@ def removeEmptyFolders(path): # if folder empty, delete it files = os.listdir(path) if len(files) == 0: - print "INFO: Removing empty folder: %s" % (path) + Logger.info("Removing empty folder: %s", path) os.rmdir(path) -old_stdout = sys.stdout # backup the default stdout -log_file = open(os.path.join(os.path.dirname(sys.argv[0]), "postprocess.log"), "a+") -sys.stdout = log_file # create a local log file, and direct all "print" to the log. -print "INFO: TorrentToMedia %s" % VERSION + +#old_stdout = sys.stdout #backup the default stdout +#log_file = open(os.path.join(os.path.dirname(sys.argv[0]), "postprocess.log"),"a+") +#sys.stdout = log_file #create a local log file, and direct all "print" to the log. +Logger.info("TorrentToMedia %s", VERSION) if len(sys.argv) == 4: ##You can use the following parameters (UTORRENT): ## @@ -67,13 +75,13 @@ if len(sys.argv) == 4: ##Stopped - 13 ## We will pass in %D, %N, %L from uTorrent - print "INFO: Script called from utorrent" + Logger.info("Script called from utorrent") Directory = sys.argv[1] ## %D -- Example output: F:\path\to\dir\My.Series.S01E01.720p.HDTV.x264-2HD Name = sys.argv[2] ## %N -- Example output: My.Series.S01E01.720p.HDTV.x264-2HD Category = sys.argv[3] ## %L -- Example output: tvseries ## This is the label in uTorrent elif len(sys.argv) > 1: #Doesn't match Transmission (1) or uTorrent (4). - print "Error: The number of arguments passed is %s. Unable to determin the arguments to use; Exiting" % (len(sys.argv)) + Logger.error("The number of arguments passed is %s. Unable to determin the arguments to use; Exiting", len(sys.argv)) sys.exit(-1) else: @@ -87,15 +95,15 @@ else: try: Directory = os.getenv('TR_TORRENT_DIR') Name = os.getenv('TR_TORRENT_NAME') - print "INFO: Script called from Transmission" + Logger.info("Script called from Transmission") except: - print "Error: There was a problem loading variables from Transmission", "Exiting" + Logger.error("There was a problem loading variables from Transmission: Exiting") sys.exit(-1) - Category = '' # We dont have a category, so assume the last directory is the category for now. + Category = '' #We dont have a category, so assume the last directory is the category for now. -print "DEBUG: Received Directory: %s" % (Directory) -print "DEBUG: Received Torrent Name: %s" % (Name) -print "DEBUG: Received Category: %s" % (Category) +Logger.debug("Received Directory: %s", Directory) +Logger.debug("Received Torrent Name: %s", Name) +Logger.debug("Received Category: %s", Category) status = 0 packed = 0 @@ -105,10 +113,10 @@ video = 0 config = ConfigParser.ConfigParser() configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") -print "INFO: Loading config from %s" % (configFilename) +Logger.info("Loading config from %s", configFilename) if not os.path.isfile(configFilename): - print "ERROR: You need an autoProcessMedia.cfg file - did you rename and edit the .sample?" + Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?") sys.exit(-1) config.read(configFilename) @@ -120,32 +128,32 @@ Movie_Cat = config.get("CouchPotato", "category") useLink = int(config.get("Torrent", "uselink")) extractionTool = config.get("Torrent", "extractiontool") -DirBase = os.path.split(os.path.normpath(Directory)) # Test for blackhole sub-directory. +DirBase = os.path.split(os.path.normpath(Directory)) #Test for blackhole sub-directory. if DirBase[1] == Name: - print "INFO: Files appear to be in their own directory" + Logger.info("Files appear to be in their own directory") DirBase2 = os.path.split(os.path.normpath(DirBase[0])) - if DirBase2[1] == Movie_Cat or DirBase == TV_Cat: + if DirBase2[1] == Movie_Cat or DirBase2[1] == TV_Cat: if not Category: - print "INFO: Determined Category to be: %s" % (DirBase2[1]) + Logger.info("Determined Category to be: %s", DirBase2[1]) Category = DirBase2[1] -elif DirBase[1] == Movie_Cat or DirBase == TV_Cat: +elif DirBase[1] == Movie_Cat or DirBase[1] == TV_Cat: if os.path.isdir(os.path.join(Directory, Name)): - print "INFO: Found torrent directory %s in category directory %s" % (os.path.join(Directory, Name), Directory) + Logger.info("Found torrent directory %s in category directory %s", os.path.join(Directory, Name), Directory) Directory = os.path.join(Directory, Name) else: - print "INFO: The directory passed is the root directory for category %s" % (DirBase[1]) - print "WARNING: You should change settings to download torrents to their own directory" - print "INFO: We will try and determine which files to process, individually" + Logger.info("The directory passed is the root directory for category %s", DirBase[1]) + Logger.warn("You should change settings to download torrents to their own directory") + Logger.info("We will try and determine which files to process, individually") root = 1 if not Category: - print "INFO: Determined Category to be: %s" % (DirBase2[1]) + Logger.info("Determined Category to be: %s", DirBase[1]) Category = DirBase[1] -else: # no category found in directory. For Utorrent we can do a recursive scan. - print "INFO: The directory passed does not appear to include a category or the torrent name" - print "WARNING: You should change settings to download torrents to their own directory" - print "INFO: We will try and determine which files to process, individually" +else: # no category found in directory. For Utorrent we can do a recursive scan. + Logger.info("The directory passed does not appear to include a category or the torrent name") + Logger.warn("You should change settings to download torrents to their own directory") + Logger.info("We will try and determine which files to process, individually") root = 1 if Category == Movie_Cat: @@ -153,23 +161,23 @@ if Category == Movie_Cat: elif Category == TV_Cat: destination = os.path.join(TV_dest, Name) else: - print "INFO: Category of %s does not match either %s or %s: Exiting" % (Category, Movie_Cat, TV_Cat) + Logger.info("Category of %s does not match either %s or %s: Exiting", Category, Movie_Cat, TV_Cat) sys.exit(-1) test = ['.zip', '.rar', '.7z', '.gz', '.bz', '.tar', '.arj'] test2 = ['.mkv', '.avi', '.divx', '.xvid', '.mov', '.wmv', '.mp4', '.mpg', '.mpeg'] -print "DEBUG: scanning files in directory: %s" % (Directory) +Logger.debug("scanning files in directory: %s", Directory) f = [filenames for dirpath, dirnames, filenames in os.walk(Directory)] if root == 1: - print "DEBUG: Looking for %s in filenames" % (Name) + Logger.debug("Looking for %s in filenames", Name) for file in f[1]: if (Name in file) or (file in Name): if os.path.splitext(file)[1] in test: - print "INFO: Found a packed file %s" % (file) + Logger.info("Found a packed file %s", file) packed = 1 break elif os.path.splitext(file)[1] in test2: - print "INFO: Found a video file %s" % (file) + Logger.info("Found a video file %s", file) video = 1 break else: @@ -177,24 +185,24 @@ if root == 1: else: ext = [os.path.splitext(file)[1] for file in f[1]] if set(ext).intersection(set(test)): - print "INFO: Found compressed archives, extracting" + Logger.info("Found compressed archives, extracting") packed = 1 ## Check that files actully is .mkv / .avi etc, and not packed files or anything else elif set(ext).intersection(set(test2)): - print "INFO: Found media files, moving" + Logger.info("Found media files, moving") video = 1 else: - print "DEBUG: Found files with extensions %s." % (ext) - print "DEBUG: Looking for extensions %s or %s." % (test, test2) - print "INFO: Didn't find any compressed archives or media files to process, exiting" + Logger.debug("Found files with extensions %s.", ext) + Logger.debug("Looking for extensions %s or %s.", test, test2) + Logger.info("Didn't find any compressed archives or media files to process, exiting") sys.exit(-1) if useLink == 0 and packed == 0 and video == 1: ## copy if root == 0: #move all files in tier own directory - print "INFO: Copying all files from %s to %s." % (Directory, destination) + Logger.info("Copying all files from %s to %s.", Directory, destination) shutil.copytree(Directory, destination) else: #we only want to move files matching the torrent name when root directory is used. - print "INFO: Copying files that match the torrent name %s from %s to %s." % (Name, Directory, destination) + Logger.info("Copying files that match the torrent name %s from %s to %s.", Name, Directory, destination) for dirpath, dirnames, filenames in os.walk(Directory): for file in filenames: if (Name in file) or (file in Name): @@ -206,7 +214,7 @@ if useLink == 0 and packed == 0 and video == 1: ## copy shutil.copy(source, target) elif useLink == 1 and packed == 0 and video == 1: ## hardlink - print "INFO: Creating hard link for files from %s to %s." % (Directory, destination) + Logger.info("Creating hard link for files from %s to %s.", Directory, destination) os.mkdir(destination) for dirpath, dirnames, filenames in os.walk(Directory): for file in filenames: @@ -226,7 +234,7 @@ elif packed == 1: ## unpack cmd_7zip = [extractionTool, 'x -y'] ext_7zip = [".rar",".zip",".tar.gz","tgz",".tar.bz2",".tbz",".tar.lzma",".tlz",".7z",".xz"] EXTRACT_COMMANDS = dict.fromkeys(ext_7zip, cmd_7zip) - print "INFO: We are using Windows" + Logger.info("We are using Windows") ## Using linux? elif os.name == 'posix': @@ -243,11 +251,11 @@ elif packed == 1: ## unpack ".txz": ["tar", "--xz xf"], ".7z": ["7zr", "x"], } - print "INFO: We are using *nix" + Logger.info("We are using *nix") ## Need to add a check for which commands that can be utilized in *nix systems.. else: - print "ERROR: Unknown OS, exiting" + Logger.error("Unknown OS, exiting") files = [ f for f in os.listdir(Directory) if os.path.isfile(os.path.join(Directory,f)) ] for f in files: @@ -266,7 +274,7 @@ elif packed == 1: ## unpack if ext[1] in EXTRACT_COMMANDS: cmd = EXTRACT_COMMANDS[ext[1]] else: - print "ERROR: Unknown file type: %s" % (ext[1]) + Logger.debug("Unknown file type: %s", ext[1]) continue ## Create destination folder @@ -274,13 +282,13 @@ elif packed == 1: ## unpack try: os.makedirs(destination) except Exception, e: - print "ERROR: Not possible to create destination folder: %s" % (e) + Logger.error("Not possible to create destination folder: %s", e) continue - print"INFO: Extracting to %s" % (destination) + Logger.info("Extracting to %s", destination) ## Running.. - print "INFO: Extracting %s %s %s %s" % (cmd[0], cmd[1], fp, destination) + Logger.info("Extracting %s %s %s %s", cmd[0], cmd[1], fp, destination) pwd = os.getcwd() # Get our Present Working Directory os.chdir(destination) #not all unpack commands accept full paths, so just extract into this directory. if os.name == 'nt': #Windows needs quotes around directory structure @@ -289,11 +297,11 @@ elif packed == 1: ## unpack res = call(run) if res == 0: status = 0 - print "INFO: Extraction was successful for %s to %s" % (fp, destination) + Logger.info("Extraction was successful for %s to %s", fp, destination) else: - print "ERROR: Extraction failed for %s. 7zip result was %s" % (fp, res) + Logger.info("Extraction failed for %s. 7zip result was %s", fp, res) except: - print "ERROR: Extraction failed for %s. Could not call command %s %s" % (fp, run) + Logger.error("Extraction failed for %s. Could not call command %s %s", fp, run) else: try: if cmd[1] == "": #if calling unzip, we dont want to pass the "" @@ -302,11 +310,11 @@ elif packed == 1: ## unpack res = call([cmd[0], cmd[1], fp]) if res == 0: status = 0 - print "INFO: Extraction was successful for %s to %s" % (fp, destination) + Logger.info("Extraction was successful for %s to %s", fp, destination) else: - print "ERROR: Extraction failed for %s. 7zip result was %s" % (fp, res) + Logger.error("Extraction failed for %s. 7zip result was %s", fp, res) except: - print "ERROR: Extraction failed for %s. Could not call command %s %s %s %s" % (fp, cmd[0], cmd[1], fp) + Logger.error("Extraction failed for %s. Could not call command %s %s %s %s", fp, cmd[0], cmd[1], fp) os.chdir(pwd) # Go back to our Original Working Directory for dirpath, dirnames, filenames in os.walk(destination): #flatten out the directory to make postprocessing easier. @@ -316,15 +324,20 @@ for dirpath, dirnames, filenames in os.walk(destination): #flatten out the direc try: shutil.move(os.path.join(dirpath, filename), destination) except OSError: - print "INFO: Could not flatten %s " % (os.path.join(dirpath, filename)) + Logger.info("Could not flatten %s", os.path.join(dirpath, filename)) removeEmptyFolders(destination) #cleanup empty directories. status = int(status) +if status == 0: + Logger.info("calling autoProcess script for successful download") +else: + Logger.info("calling autoProcess script for failed download") ## Now we pass off to CouchPotato or SickBeard. +old_stdout = sys.stdout #backup the default stdout +sys.stdout = Logger.info #Capture the print from the autoProcess scripts. if Category == Movie_Cat: autoProcessMovie.process(destination, Name, status) elif Category == TV_Cat: autoProcessTV.processEpisode(destination, Name, status) - sys.stdout = old_stdout #reset our stdout -log_file.close() #close the log +#log_file.close() #close the log diff --git a/changelog.txt b/changelog.txt index 190c4cf2..1e1d2c2a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,12 @@ Change_LOG / History +V4.3 17/02/2013 + +Added Logger in TorrentToMedia.py +Added nzbget V10.0 script. +Delete sample files in nzbget postprocessing +Single Version for all files. + V4.2 12/02/2013 Fixes to TorrentToMedia diff --git a/logger.conf b/logger.conf new file mode 100644 index 00000000..03f0b033 --- /dev/null +++ b/logger.conf @@ -0,0 +1,24 @@ +# Logging configuration +[loggers] +keys = root + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = NOTSET +handlers = console +qualname = + +[handler_console] +class = StreamHandler +args = (sys.stdout,) +level = INFO +formatter = generic + +[formatter_generic] +format = %(asctime)s|%(levelname)-7.7s %(message)s +datefmt = %H:%M:%S diff --git a/nzbToMediaEnv.py b/nzbToMediaEnv.py index 922704e1..9cb31078 100644 --- a/nzbToMediaEnv.py +++ b/nzbToMediaEnv.py @@ -1,2 +1 @@ - -VERSION = 'V4.2' +VERSION = 'V4.3' diff --git a/nzbget-postprocessing-files/0.8.0/postprocess.conf b/nzbget-postprocessing-files/10.0/nzbget-postprocess.conf similarity index 74% rename from nzbget-postprocessing-files/0.8.0/postprocess.conf rename to nzbget-postprocessing-files/10.0/nzbget-postprocess.conf index 110489d6..9e56868b 100644 --- a/nzbget-postprocessing-files/0.8.0/postprocess.conf +++ b/nzbget-postprocessing-files/10.0/nzbget-postprocess.conf @@ -1,11 +1,10 @@ # # This file if part of nzbget # -# Template configuration file for postprocessing script "nzbget-postprocess.sh". +# Template configuration file for post-processing script "nzbget-postprocess.sh". # Please refer to "nzbget-postprocess.sh" for usage instructions. # -# Copyright (C) 2008-2012 Andrey Prygunkov -# Copyright (C) 2012 J�rgen Seif +# 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 @@ -26,26 +25,15 @@ ############################################################################## ### PATHS ### -# Set the full path to unrar if it is not in your PATH. -UnrarCmd=unrar - # Set the full path to python if it is not in your PATH. PythonCmd=/usr/local/python/bin/python # Set the full path to sabToSickBeard.py for SickBeard's postprocessing. NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py -# Set the full path where completed movies should be placed -# before SickBeard's Renamer is called -TvDownloadDir= - # Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py -# Set the full path where completed movies should be placed -# before CouchPotato's Renamer is called -MoviesDownloadDir= - # 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 @@ -53,24 +41,14 @@ CustomCmd=/usr/local/python/bin/python # Set the full path to the Custom Postprocess script. CustomScript= -# Set the full path where completed downloads should be placed -# before the Custom postprocess is called -CustomDownloadDir= - ############################################################################## ### OPTIONS ### -# Delete rar-files after unpacking (yes, no). -DeleteRarFiles=yes - -# Temporary directory for unpacking. -ExtractedDir=extracted - # Rename img-files to iso (yes, no). RenameIMG=yes # Joint TS-files (yes, no). -JoinTS=no +JoinTS=yes # Perform SickBeard's postprocessing (yes, no). SickBeard=yes @@ -80,17 +58,17 @@ SickBeardCategory=tv # Perform Couchpotato's postprocessing (yes, no). CouchPotato=yes - -# Category for Couchpotato's postprocessing (eg. movies) -CouchPotatoCategory=movies + +# Category for Couchpotato's postprocessing. +CouchPotatoCategory=movies # Perform Custom postprocessing (yes, no). Custom=yes - + # Category for Custom postprocessing (eg. movies) CustomCategory=music -# Clean up list. space seperated, in single quote, default '*.nzb *.sfv *.1' +# Clean up list. space seperated, in single quotes, default '*.nzb *.sfv *.1' FileCleanUp='*.nzb *.sfv *.1' # Toggle detailed output (yes, no). @@ -101,23 +79,16 @@ Debug=no # 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 "password" to value "123" for +# Example command line for setting parameter "PostProcess" to value "no" for # nzb-file with id=2: -# nzbget -E G O Password=123 2 +# nzbget -E G O PostProcess=no 2 # Perform postprocessing (yes, no). # # Set to "no" to skip postprocessing for this nzb-file. PostProcess=yes -# Password for encrypted posts. -# -# If the post requires a password for unpacking. -Password= - # Destination directory. -# -# NOTE: NZBGet must have write-access-rights for that directory. DestDir= ############################################################################## @@ -127,11 +98,11 @@ DestDir= # be sent via email. # This uses sendEmail as authored by Brandon Zehm -# Specify if you want emails to be sent for successful downloads (yes, no). -Email_successful=yes +# List Categories for successful download email, default 'tv movies' +Email_successful='tv movies' -# Specify if you want emails to be sent for failed downloads (yes, no). -Email_failed=yes +# List Categories for failed download email, default 'tv movies' +Email_failed='tv movies' # Set the full path and file name for sendEmail application. sendEmail=/usr/local/nzbget/var/sendEmail/sendEmail diff --git a/nzbget-postprocessing-files/0.8.0/postprocess.sh b/nzbget-postprocessing-files/10.0/nzbget-postprocess.sh old mode 100644 new mode 100755 similarity index 53% rename from nzbget-postprocessing-files/0.8.0/postprocess.sh rename to nzbget-postprocessing-files/10.0/nzbget-postprocess.sh index c85855fe..b2bd98f9 --- a/nzbget-postprocessing-files/0.8.0/postprocess.sh +++ b/nzbget-postprocessing-files/10.0/nzbget-postprocess.sh @@ -1,13 +1,12 @@ #!/bin/sh -# -*- coding: cp1252 -*- +# +# This file if part of nzbget # # Example postprocessing script for NZBGet # # Copyright (C) 2008 Peter Roubos # Copyright (C) 2008 Otmar Werner -# Copyright (C) 2008-2012 Andrei Prygunkov -# Copyright (C) 2012 Antoine Bertin -# Copyright (C) 2012 J�rgen Seif +# 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 @@ -21,45 +20,25 @@ # # 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ####################### Usage instructions ####################### -# o Script will unrar downloaded rar files, join ts-files and rename img-files -# to iso. +# o Script will cleanup, join ts-files and rename img-files to iso. # # o To use this script with nzbget set the option "PostProcess" in # nzbget configuration file to point to this script file. E.g.: # PostProcess=/home/user/nzbget/nzbget-postprocess.sh # # o The script needs a configuration file. An example configuration file -# is provided in file "postprocess-example.conf". Put the configuration file -# into the directory where nzbget's configuration file (nzbget.conf) or where -# this script itself is located. Then edit the configuration file in any -# text editor to adjust the settings. +# is provided in file "nzbget-postprocess.conf". Put the configuration file +# into the directory where nzbget's configuration file (nzbget.conf) is located. +# Then edit the configuration file in any text editor to adjust the settings. # -# o You can also edit the script's configuration via web-interface (requires -# NZBGetWeb 1.4 or later). Set the options "PostProcessConfigFile" and -# "PostProcessConfigTemplate" to point to "postprocess-example.conf" -# (including full path). The both options are under the section -# "CONFIGURATION OF POSTPROCESSING-SCRIPT" in NZBGetWeb. +# o You can also edit the script's configuration via web-interface. # -# o There are few options, which can be ajdusted for each nzb-file -# individually. To view/edit them in web-interface click on a spanner icon -# near the name of nzb-file. -# -# o The script supports the feature called "delayed par-check". -# That means it can try to unpack downloaded files without par-checking -# them fisrt. Only if unpack fails, the script schedules par-check, -# then unpacks again. -# To use delayed par-check set following options in nzbget configuration file: -# ParCheck=no -# ParRepair=yes -# LoadPars=one (or) LoadPars=all -# -# o If you want to par-check/repair all files before trying to unpack them, -# set option "ParCheck=yes". +# o There are few options, which can be ajdusted for each nzb-file individually. # ####################### End of Usage instructions ####################### @@ -67,27 +46,27 @@ # NZBGet passes following arguments to postprocess-programm as environment # variables: # NZBPP_DIRECTORY - path to destination dir for downloaded files; -# NZBPP_NZBFILENAME - name of processed nzb-file; -# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were -# found); +# NZBPP_NZBNAME - user-friendly name of processed nzb-file as it is displayed +# by the program. The file path and extension are removed. +# If download was renamed, this parameter reflects the new name; +# NZBPP_NZBFILENAME - name of processed nzb-file. It includes file extension and also +# may include full path; +# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string); # NZBPP_PARSTATUS - result of par-check: -# 0 = not checked: par-check disabled or nzb-file does +# 0 = not checked: par-check is disabled or nzb-file does # not contain any par-files; # 1 = checked and failed to repair; # 2 = checked and successfully repaired; -# 3 = checked and can be repaired but repair is disabled; -# NZBPP_NZBCOMPLETED - state of nzb-job: -# 0 = there are more collections in this nzb-file queued; -# 1 = this was the last collection in nzb-file; -# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file: -# 0 = no failed par-jobs; -# 1 = current par-job or any of the previous par-jobs for -# the same nzb-files failed; -# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string). +# 3 = checked and can be repaired but repair is disabled. +# NZBPP_UNPACKSTATUS - result of unpack: +# 0 = unpack is disabled or was skipped due to nzb-file +# properties or due to errors during par-check; +# 1 = unpack failed; +# 2 = unpack successful. # Name of script's configuration file -SCRIPT_CONFIG_FILE="postprocess.conf" +SCRIPT_CONFIG_FILE="nzbget-postprocess.conf" # Exit codes POSTPROCESS_PARCHECK_CURRENT=91 @@ -102,6 +81,7 @@ nzbToMedia() { PostProcessStatus=0 if [ -n "$1" ]; then PostProcessStatus=$1 ; fi if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: comparing '$NZBPP_CATEGORY' to '$CouchPotatoCategory' and '$SickBeardCategory'" ; fi + find "$NZBPP_DIRECTORY" -type f -size -200000k -iname \*sample\* -exec rm {} \; >/dev/null 2>&1 if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then script=$NzbToCouchPotato @@ -155,6 +135,19 @@ nzbToMedia() { fi } +replaceVarBy() { + if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'replaceVarBy'. Going to replace '${2}' in '${1}' by '${3}'" ; fi + + # If we're not using Bash use sed, as we need to support as much as systems possible, also those running sh/dash etc + if [ -n "${BASH_VERSION}" ]; then + REPLACEDRESULT="${1/${2}/${3}}" + else + REPLACEDRESULT=$(echo "${1}" | sed "s^${2}^${3}^g") + fi + + if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: replace result: ${REPLACEDRESULT}" ; fi +} + # Pass on postprocess exit codes to external scripts for handling failed downloads do_exit() { if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" ; fi @@ -162,41 +155,54 @@ do_exit() { if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then nzbStatus=1 ; fi script=none nzbToMedia $nzbStatus - Email_Subject="${Email_Subject//$NZBPP_NZBFILENAME}" - Email_Subject="${Email_Subject//$NZBPP_CATEGORY}" - Email_Subject="${Email_Subject/