mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-22 06:13:19 -07:00
hand merged upstream
This commit is contained in:
commit
7ee022cfa0
8 changed files with 207 additions and 338 deletions
|
@ -237,7 +237,8 @@ If you are using NZBGet perform the following steps to configure postprocessing
|
||||||
|
|
||||||
2. In NZBGet go to "POSTPROCESSING SCRIPT" -> "PATHS" and change as needed:
|
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
|
PythonCmd=/usr/local/python/bin/python
|
||||||
|
|
||||||
|
@ -246,6 +247,7 @@ If you are using NZBGet perform the following steps to configure postprocessing
|
||||||
NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py
|
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)
|
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=
|
TvDownloadDir=
|
||||||
|
|
||||||
|
@ -254,10 +256,11 @@ If you are using NZBGet perform the following steps to configure postprocessing
|
||||||
NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py
|
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. 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=
|
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
|
CustomCmd=/usr/local/python/bin/python
|
||||||
|
|
||||||
|
@ -266,6 +269,7 @@ If you are using NZBGet perform the following steps to configure postprocessing
|
||||||
CustomScript=
|
CustomScript=
|
||||||
|
|
||||||
viii.Set the full path where completed downloads should be placed before the Custom postprocess is called (option)
|
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=
|
CustomDownloadDir=
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,13 @@ import autoProcessMovie
|
||||||
import autoProcessTV
|
import autoProcessTV
|
||||||
from nzbToMediaEnv import *
|
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):
|
def removeEmptyFolders(path):
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
|
@ -28,14 +35,15 @@ def removeEmptyFolders(path):
|
||||||
# if folder empty, delete it
|
# if folder empty, delete it
|
||||||
files = os.listdir(path)
|
files = os.listdir(path)
|
||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
print "INFO: Removing empty folder: %s" % (path)
|
Logger.info("Removing empty folder: %s", path)
|
||||||
os.rmdir(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+")
|
#old_stdout = sys.stdout #backup the default stdout
|
||||||
sys.stdout = log_file # create a local log file, and direct all "print" to the log.
|
#log_file = open(os.path.join(os.path.dirname(sys.argv[0]), "postprocess.log"),"a+")
|
||||||
print "INFO: TorrentToMedia %s" % VERSION
|
#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:
|
if len(sys.argv) == 4:
|
||||||
##You can use the following parameters (UTORRENT):
|
##You can use the following parameters (UTORRENT):
|
||||||
##
|
##
|
||||||
|
@ -67,13 +75,13 @@ if len(sys.argv) == 4:
|
||||||
##Stopped - 13
|
##Stopped - 13
|
||||||
|
|
||||||
## We will pass in %D, %N, %L from uTorrent
|
## 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
|
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
|
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
|
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).
|
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)
|
sys.exit(-1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -87,15 +95,15 @@ else:
|
||||||
try:
|
try:
|
||||||
Directory = os.getenv('TR_TORRENT_DIR')
|
Directory = os.getenv('TR_TORRENT_DIR')
|
||||||
Name = os.getenv('TR_TORRENT_NAME')
|
Name = os.getenv('TR_TORRENT_NAME')
|
||||||
print "INFO: Script called from Transmission"
|
Logger.info("Script called from Transmission")
|
||||||
except:
|
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)
|
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)
|
Logger.debug("Received Directory: %s", Directory)
|
||||||
print "DEBUG: Received Torrent Name: %s" % (Name)
|
Logger.debug("Received Torrent Name: %s", Name)
|
||||||
print "DEBUG: Received Category: %s" % (Category)
|
Logger.debug("Received Category: %s", Category)
|
||||||
|
|
||||||
status = 0
|
status = 0
|
||||||
packed = 0
|
packed = 0
|
||||||
|
@ -105,10 +113,10 @@ video = 0
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
|
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):
|
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)
|
sys.exit(-1)
|
||||||
|
|
||||||
config.read(configFilename)
|
config.read(configFilename)
|
||||||
|
@ -122,30 +130,30 @@ 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:
|
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]))
|
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:
|
if not Category:
|
||||||
print "INFO: Determined Category to be: %s" % (DirBase2[1])
|
Logger.info("Determined Category to be: %s", DirBase2[1])
|
||||||
Category = 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)):
|
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)
|
Directory = os.path.join(Directory, Name)
|
||||||
else:
|
else:
|
||||||
print "INFO: The directory passed is the root directory for category %s" % (DirBase[1])
|
Logger.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"
|
Logger.warn("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("We will try and determine which files to process, individually")
|
||||||
root = 1
|
root = 1
|
||||||
if not Category:
|
if not Category:
|
||||||
print "INFO: Determined Category to be: %s" % (DirBase2[1])
|
Logger.info("Determined Category to be: %s", DirBase[1])
|
||||||
Category = DirBase[1]
|
Category = DirBase[1]
|
||||||
|
|
||||||
else: # no category found in directory. For Utorrent we can do a recursive scan.
|
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"
|
Logger.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"
|
Logger.warn("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("We will try and determine which files to process, individually")
|
||||||
root = 1
|
root = 1
|
||||||
|
|
||||||
if Category == Movie_Cat:
|
if Category == Movie_Cat:
|
||||||
|
@ -153,23 +161,23 @@ if Category == Movie_Cat:
|
||||||
elif Category == TV_Cat:
|
elif Category == TV_Cat:
|
||||||
destination = os.path.join(TV_dest, Name)
|
destination = os.path.join(TV_dest, Name)
|
||||||
else:
|
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)
|
sys.exit(-1)
|
||||||
|
|
||||||
test = ['.zip', '.rar', '.7z', '.gz', '.bz', '.tar', '.arj']
|
test = ['.zip', '.rar', '.7z', '.gz', '.bz', '.tar', '.arj']
|
||||||
test2 = ['.mkv', '.avi', '.divx', '.xvid', '.mov', '.wmv', '.mp4', '.mpg', '.mpeg']
|
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)]
|
f = [filenames for dirpath, dirnames, filenames in os.walk(Directory)]
|
||||||
if root == 1:
|
if root == 1:
|
||||||
print "DEBUG: Looking for %s in filenames" % (Name)
|
Logger.debug("Looking for %s in filenames", Name)
|
||||||
for file in f[1]:
|
for file in f[1]:
|
||||||
if (Name in file) or (file in Name):
|
if (Name in file) or (file in Name):
|
||||||
if os.path.splitext(file)[1] in test:
|
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
|
packed = 1
|
||||||
break
|
break
|
||||||
elif os.path.splitext(file)[1] in test2:
|
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
|
video = 1
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -177,24 +185,24 @@ if root == 1:
|
||||||
else:
|
else:
|
||||||
ext = [os.path.splitext(file)[1] for file in f[1]]
|
ext = [os.path.splitext(file)[1] for file in f[1]]
|
||||||
if set(ext).intersection(set(test)):
|
if set(ext).intersection(set(test)):
|
||||||
print "INFO: Found compressed archives, extracting"
|
Logger.info("Found compressed archives, extracting")
|
||||||
packed = 1
|
packed = 1
|
||||||
## Check that files actully is .mkv / .avi etc, and not packed files or anything else
|
## Check that files actully is .mkv / .avi etc, and not packed files or anything else
|
||||||
elif set(ext).intersection(set(test2)):
|
elif set(ext).intersection(set(test2)):
|
||||||
print "INFO: Found media files, moving"
|
Logger.info("Found media files, moving")
|
||||||
video = 1
|
video = 1
|
||||||
else:
|
else:
|
||||||
print "DEBUG: Found files with extensions %s." % (ext)
|
Logger.debug("Found files with extensions %s.", ext)
|
||||||
print "DEBUG: Looking for extensions %s or %s." % (test, test2)
|
Logger.debug("Looking for extensions %s or %s.", test, test2)
|
||||||
print "INFO: Didn't find any compressed archives or media files to process, exiting"
|
Logger.info("Didn't find any compressed archives or media files to process, exiting")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
if useLink == 0 and packed == 0 and video == 1: ## copy
|
if useLink == 0 and packed == 0 and video == 1: ## copy
|
||||||
if root == 0: #move all files in tier own directory
|
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)
|
shutil.copytree(Directory, destination)
|
||||||
else: #we only want to move files matching the torrent name when root directory is used.
|
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 dirpath, dirnames, filenames in os.walk(Directory):
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
if (Name in file) or (file in Name):
|
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)
|
shutil.copy(source, target)
|
||||||
|
|
||||||
elif useLink == 1 and packed == 0 and video == 1: ## hardlink
|
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)
|
os.mkdir(destination)
|
||||||
for dirpath, dirnames, filenames in os.walk(Directory):
|
for dirpath, dirnames, filenames in os.walk(Directory):
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
|
@ -226,7 +234,7 @@ elif packed == 1: ## unpack
|
||||||
cmd_7zip = [extractionTool, 'x -y']
|
cmd_7zip = [extractionTool, 'x -y']
|
||||||
ext_7zip = [".rar",".zip",".tar.gz","tgz",".tar.bz2",".tbz",".tar.lzma",".tlz",".7z",".xz"]
|
ext_7zip = [".rar",".zip",".tar.gz","tgz",".tar.bz2",".tbz",".tar.lzma",".tlz",".7z",".xz"]
|
||||||
EXTRACT_COMMANDS = dict.fromkeys(ext_7zip, cmd_7zip)
|
EXTRACT_COMMANDS = dict.fromkeys(ext_7zip, cmd_7zip)
|
||||||
print "INFO: We are using Windows"
|
Logger.info("We are using Windows")
|
||||||
|
|
||||||
## Using linux?
|
## Using linux?
|
||||||
elif os.name == 'posix':
|
elif os.name == 'posix':
|
||||||
|
@ -243,11 +251,11 @@ elif packed == 1: ## unpack
|
||||||
".txz": ["tar", "--xz xf"],
|
".txz": ["tar", "--xz xf"],
|
||||||
".7z": ["7zr", "x"],
|
".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..
|
## Need to add a check for which commands that can be utilized in *nix systems..
|
||||||
else:
|
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)) ]
|
files = [ f for f in os.listdir(Directory) if os.path.isfile(os.path.join(Directory,f)) ]
|
||||||
for f in files:
|
for f in files:
|
||||||
|
@ -266,7 +274,7 @@ elif packed == 1: ## unpack
|
||||||
if ext[1] in EXTRACT_COMMANDS:
|
if ext[1] in EXTRACT_COMMANDS:
|
||||||
cmd = EXTRACT_COMMANDS[ext[1]]
|
cmd = EXTRACT_COMMANDS[ext[1]]
|
||||||
else:
|
else:
|
||||||
print "ERROR: Unknown file type: %s" % (ext[1])
|
Logger.debug("Unknown file type: %s", ext[1])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
## Create destination folder
|
## Create destination folder
|
||||||
|
@ -274,13 +282,13 @@ elif packed == 1: ## unpack
|
||||||
try:
|
try:
|
||||||
os.makedirs(destination)
|
os.makedirs(destination)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "ERROR: Not possible to create destination folder: %s" % (e)
|
Logger.error("Not possible to create destination folder: %s", e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print"INFO: Extracting to %s" % (destination)
|
Logger.info("Extracting to %s", destination)
|
||||||
|
|
||||||
## Running..
|
## 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
|
pwd = os.getcwd() # Get our Present Working Directory
|
||||||
os.chdir(destination) #not all unpack commands accept full paths, so just extract into this 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
|
if os.name == 'nt': #Windows needs quotes around directory structure
|
||||||
|
@ -289,11 +297,11 @@ elif packed == 1: ## unpack
|
||||||
res = call(run)
|
res = call(run)
|
||||||
if res == 0:
|
if res == 0:
|
||||||
status = 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:
|
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:
|
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:
|
else:
|
||||||
try:
|
try:
|
||||||
if cmd[1] == "": #if calling unzip, we dont want to pass the ""
|
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])
|
res = call([cmd[0], cmd[1], fp])
|
||||||
if res == 0:
|
if res == 0:
|
||||||
status = 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:
|
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:
|
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
|
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.
|
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:
|
try:
|
||||||
shutil.move(os.path.join(dirpath, filename), destination)
|
shutil.move(os.path.join(dirpath, filename), destination)
|
||||||
except OSError:
|
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.
|
removeEmptyFolders(destination) #cleanup empty directories.
|
||||||
|
|
||||||
status = int(status)
|
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.
|
## 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:
|
if Category == Movie_Cat:
|
||||||
autoProcessMovie.process(destination, Name, status)
|
autoProcessMovie.process(destination, Name, status)
|
||||||
elif Category == TV_Cat:
|
elif Category == TV_Cat:
|
||||||
autoProcessTV.processEpisode(destination, Name, status)
|
autoProcessTV.processEpisode(destination, Name, status)
|
||||||
|
|
||||||
sys.stdout = old_stdout #reset our stdout
|
sys.stdout = old_stdout #reset our stdout
|
||||||
log_file.close() #close the log
|
#log_file.close() #close the log
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
Change_LOG / History
|
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
|
V4.2 12/02/2013
|
||||||
|
|
||||||
Fixes to TorrentToMedia
|
Fixes to TorrentToMedia
|
||||||
|
|
24
logger.conf
Normal file
24
logger.conf
Normal file
|
@ -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
|
|
@ -1,2 +1 @@
|
||||||
|
VERSION = 'V4.3'
|
||||||
VERSION = 'V4.2'
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#
|
#
|
||||||
# This file if part of nzbget
|
# 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.
|
# Please refer to "nzbget-postprocess.sh" for usage instructions.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008-2012 Andrey Prygunkov <hugbug@users.sourceforge.net>
|
# Copyright (C) 2008-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
|
||||||
# Copyright (C) 2012 J<>rgen Seif <thor78@gmx.at>
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,26 +25,15 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
### PATHS ###
|
### 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.
|
# Set the full path to python if it is not in your PATH.
|
||||||
PythonCmd=/usr/local/python/bin/python
|
PythonCmd=/usr/local/python/bin/python
|
||||||
|
|
||||||
# Set the full path to sabToSickBeard.py for SickBeard's postprocessing.
|
# Set the full path to sabToSickBeard.py for SickBeard's postprocessing.
|
||||||
NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py
|
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
|
# Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing
|
||||||
NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py
|
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
|
# Set the full path to any dependency required for your Custom
|
||||||
# Postprocess script if it is not in your PATH.
|
# Postprocess script if it is not in your PATH.
|
||||||
CustomCmd=/usr/local/python/bin/python
|
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.
|
# Set the full path to the Custom Postprocess script.
|
||||||
CustomScript=
|
CustomScript=
|
||||||
|
|
||||||
# Set the full path where completed downloads should be placed
|
|
||||||
# before the Custom postprocess is called
|
|
||||||
CustomDownloadDir=
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
### OPTIONS ###
|
### OPTIONS ###
|
||||||
|
|
||||||
# Delete rar-files after unpacking (yes, no).
|
|
||||||
DeleteRarFiles=yes
|
|
||||||
|
|
||||||
# Temporary directory for unpacking.
|
|
||||||
ExtractedDir=extracted
|
|
||||||
|
|
||||||
# Rename img-files to iso (yes, no).
|
# Rename img-files to iso (yes, no).
|
||||||
RenameIMG=yes
|
RenameIMG=yes
|
||||||
|
|
||||||
# Joint TS-files (yes, no).
|
# Joint TS-files (yes, no).
|
||||||
JoinTS=no
|
JoinTS=yes
|
||||||
|
|
||||||
# Perform SickBeard's postprocessing (yes, no).
|
# Perform SickBeard's postprocessing (yes, no).
|
||||||
SickBeard=yes
|
SickBeard=yes
|
||||||
|
@ -81,7 +59,7 @@ SickBeardCategory=tv
|
||||||
# Perform Couchpotato's postprocessing (yes, no).
|
# Perform Couchpotato's postprocessing (yes, no).
|
||||||
CouchPotato=yes
|
CouchPotato=yes
|
||||||
|
|
||||||
# Category for Couchpotato's postprocessing (eg. movies)
|
# Category for Couchpotato's postprocessing.
|
||||||
CouchPotatoCategory=movies
|
CouchPotatoCategory=movies
|
||||||
|
|
||||||
# Perform Custom postprocessing (yes, no).
|
# Perform Custom postprocessing (yes, no).
|
||||||
|
@ -90,7 +68,7 @@ Custom=yes
|
||||||
# Category for Custom postprocessing (eg. movies)
|
# Category for Custom postprocessing (eg. movies)
|
||||||
CustomCategory=music
|
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'
|
FileCleanUp='*.nzb *.sfv *.1'
|
||||||
|
|
||||||
# Toggle detailed output (yes, no).
|
# Toggle detailed output (yes, no).
|
||||||
|
@ -101,23 +79,16 @@ Debug=no
|
||||||
|
|
||||||
# This section defines parameters, which can be set for each nzb-file
|
# This section defines parameters, which can be set for each nzb-file
|
||||||
# individually using either web-interface or command line.
|
# 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:
|
# nzb-file with id=2:
|
||||||
# nzbget -E G O Password=123 2
|
# nzbget -E G O PostProcess=no 2
|
||||||
|
|
||||||
# Perform postprocessing (yes, no).
|
# Perform postprocessing (yes, no).
|
||||||
#
|
#
|
||||||
# Set to "no" to skip postprocessing for this nzb-file.
|
# Set to "no" to skip postprocessing for this nzb-file.
|
||||||
PostProcess=yes
|
PostProcess=yes
|
||||||
|
|
||||||
# Password for encrypted posts.
|
|
||||||
#
|
|
||||||
# If the post requires a password for unpacking.
|
|
||||||
Password=
|
|
||||||
|
|
||||||
# Destination directory.
|
# Destination directory.
|
||||||
#
|
|
||||||
# NOTE: NZBGet must have write-access-rights for that directory.
|
|
||||||
DestDir=
|
DestDir=
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
@ -127,11 +98,11 @@ DestDir=
|
||||||
# be sent via email.
|
# be sent via email.
|
||||||
# This uses sendEmail as authored by Brandon Zehm <caspian@dotconf.net>
|
# This uses sendEmail as authored by Brandon Zehm <caspian@dotconf.net>
|
||||||
|
|
||||||
# Specify if you want emails to be sent for successful downloads (yes, no).
|
# List Categories for successful download email, default 'tv movies'
|
||||||
Email_successful=yes
|
Email_successful='tv movies'
|
||||||
|
|
||||||
# Specify if you want emails to be sent for failed downloads (yes, no).
|
# List Categories for failed download email, default 'tv movies'
|
||||||
Email_failed=yes
|
Email_failed='tv movies'
|
||||||
|
|
||||||
# Set the full path and file name for sendEmail application.
|
# Set the full path and file name for sendEmail application.
|
||||||
sendEmail=/usr/local/nzbget/var/sendEmail/sendEmail
|
sendEmail=/usr/local/nzbget/var/sendEmail/sendEmail
|
308
nzbget-postprocessing-files/0.8.0/postprocess.sh → nzbget-postprocessing-files/10.0/nzbget-postprocess.sh
Normal file → Executable file
308
nzbget-postprocessing-files/0.8.0/postprocess.sh → nzbget-postprocessing-files/10.0/nzbget-postprocess.sh
Normal file → Executable file
|
@ -1,13 +1,12 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# -*- coding: cp1252 -*-
|
#
|
||||||
|
# This file if part of nzbget
|
||||||
#
|
#
|
||||||
# Example postprocessing script for NZBGet
|
# Example postprocessing script for NZBGet
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
|
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
|
||||||
# Copyright (C) 2008 Otmar Werner
|
# Copyright (C) 2008 Otmar Werner
|
||||||
# Copyright (C) 2008-2012 Andrei Prygunkov <hugbug@users.sourceforge.net>
|
# Copyright (C) 2008-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
|
||||||
# Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
|
|
||||||
# Copyright (C) 2012 J<>rgen Seif <thor78@gmx.at>
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# 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
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# 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 #######################
|
####################### Usage instructions #######################
|
||||||
# o Script will unrar downloaded rar files, join ts-files and rename img-files
|
# o Script will cleanup, join ts-files and rename img-files to iso.
|
||||||
# to iso.
|
|
||||||
#
|
#
|
||||||
# o To use this script with nzbget set the option "PostProcess" in
|
# o To use this script with nzbget set the option "PostProcess" in
|
||||||
# nzbget configuration file to point to this script file. E.g.:
|
# nzbget configuration file to point to this script file. E.g.:
|
||||||
# PostProcess=/home/user/nzbget/nzbget-postprocess.sh
|
# PostProcess=/home/user/nzbget/nzbget-postprocess.sh
|
||||||
#
|
#
|
||||||
# o The script needs a configuration file. An example configuration file
|
# o The script needs a configuration file. An example configuration file
|
||||||
# is provided in file "postprocess-example.conf". Put the configuration file
|
# is provided in file "nzbget-postprocess.conf". Put the configuration file
|
||||||
# into the directory where nzbget's configuration file (nzbget.conf) or where
|
# into the directory where nzbget's configuration file (nzbget.conf) is located.
|
||||||
# this script itself is located. Then edit the configuration file in any
|
# Then edit the configuration file in any text editor to adjust the settings.
|
||||||
# text editor to adjust the settings.
|
|
||||||
#
|
#
|
||||||
# o You can also edit the script's configuration via web-interface (requires
|
# o You can also edit the script's configuration via web-interface.
|
||||||
# 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 There are few options, which can be ajdusted for each nzb-file
|
# o There are few options, which can be ajdusted for each nzb-file individually.
|
||||||
# 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".
|
|
||||||
#
|
#
|
||||||
####################### End of Usage instructions #######################
|
####################### End of Usage instructions #######################
|
||||||
|
|
||||||
|
@ -67,27 +46,27 @@
|
||||||
# NZBGet passes following arguments to postprocess-programm as environment
|
# NZBGet passes following arguments to postprocess-programm as environment
|
||||||
# variables:
|
# variables:
|
||||||
# NZBPP_DIRECTORY - path to destination dir for downloaded files;
|
# NZBPP_DIRECTORY - path to destination dir for downloaded files;
|
||||||
# NZBPP_NZBFILENAME - name of processed nzb-file;
|
# NZBPP_NZBNAME - user-friendly name of processed nzb-file as it is displayed
|
||||||
# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were
|
# by the program. The file path and extension are removed.
|
||||||
# found);
|
# 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:
|
# 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;
|
# not contain any par-files;
|
||||||
# 1 = checked and failed to repair;
|
# 1 = checked and failed to repair;
|
||||||
# 2 = checked and successfully repaired;
|
# 2 = checked and successfully repaired;
|
||||||
# 3 = checked and can be repaired but repair is disabled;
|
# 3 = checked and can be repaired but repair is disabled.
|
||||||
# NZBPP_NZBCOMPLETED - state of nzb-job:
|
# NZBPP_UNPACKSTATUS - result of unpack:
|
||||||
# 0 = there are more collections in this nzb-file queued;
|
# 0 = unpack is disabled or was skipped due to nzb-file
|
||||||
# 1 = this was the last collection in nzb-file;
|
# properties or due to errors during par-check;
|
||||||
# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file:
|
# 1 = unpack failed;
|
||||||
# 0 = no failed par-jobs;
|
# 2 = unpack successful.
|
||||||
# 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).
|
|
||||||
|
|
||||||
|
|
||||||
# Name of script's configuration file
|
# Name of script's configuration file
|
||||||
SCRIPT_CONFIG_FILE="postprocess.conf"
|
SCRIPT_CONFIG_FILE="nzbget-postprocess.conf"
|
||||||
|
|
||||||
# Exit codes
|
# Exit codes
|
||||||
POSTPROCESS_PARCHECK_CURRENT=91
|
POSTPROCESS_PARCHECK_CURRENT=91
|
||||||
|
@ -102,6 +81,7 @@ nzbToMedia() {
|
||||||
PostProcessStatus=0
|
PostProcessStatus=0
|
||||||
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
|
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
|
||||||
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: comparing '$NZBPP_CATEGORY' to '$CouchPotatoCategory' and '$SickBeardCategory'" ; 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 [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
|
||||||
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
|
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
|
||||||
script=$NzbToCouchPotato
|
script=$NzbToCouchPotato
|
||||||
|
@ -155,6 +135,19 @@ nzbToMedia() {
|
||||||
fi
|
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
|
# Pass on postprocess exit codes to external scripts for handling failed downloads
|
||||||
do_exit() {
|
do_exit() {
|
||||||
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" ; fi
|
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" ; fi
|
||||||
|
@ -162,33 +155,46 @@ do_exit() {
|
||||||
if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then nzbStatus=1 ; fi
|
if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then nzbStatus=1 ; fi
|
||||||
script=none
|
script=none
|
||||||
nzbToMedia $nzbStatus
|
nzbToMedia $nzbStatus
|
||||||
Email_Subject="${Email_Subject/<name>/$NZBPP_NZBFILENAME}"
|
echo "[DETAIL] after calling nzbToMedia"
|
||||||
Email_Subject="${Email_Subject/<cat>/$NZBPP_CATEGORY}"
|
replaceVarBy "${Email_Subject}" "<name>" "${NZBPP_NZBFILENAME}"
|
||||||
Email_Subject="${Email_Subject/<script>/$script}"
|
replaceVarBy "${REPLACEDRESULT}" "<cat>" "${NZBPP_CATEGORY}"
|
||||||
Email_Message="${Email_Message/<name>/$NZBPP_NZBFILENAME}"
|
replaceVarBy "${REPLACEDRESULT}" "<script>" "${script}"
|
||||||
Email_Message="${Email_Message/<cat>/$NZBPP_CATEGORY}"
|
Email_Subject="${REPLACEDRESULT}"
|
||||||
Email_Message="${Email_Message/<script>/$script}"
|
replaceVarBy "${Email_Message}" "<name>" "${NZBPP_NZBFILENAME}"
|
||||||
if [ "$Email_successful" = "yes" -a "$nzbStatus" = 0 ]; then
|
replaceVarBy "${REPLACEDRESULT}" "<cat>" "${NZBPP_CATEGORY}"
|
||||||
|
replaceVarBy "${REPLACEDRESULT}" "<script>" "${script}"
|
||||||
|
Email_Message="${REPLACEDRESULT}"
|
||||||
|
for item in $Email_successful; do
|
||||||
|
if [ "${NZBPP_CATEGORY}" = "$item" -a "$nzbStatus" = 0 ]; then
|
||||||
User=""
|
User=""
|
||||||
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
|
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
|
||||||
Email_Subject="${Email_Subject/<status>/completed}"
|
replaceVarBy "${Email_Subject}" "<status>" "completed"
|
||||||
Email_Message="${Email_Message/<status>/completed}"
|
Email_Subject="${REPLACEDRESULT}"
|
||||||
|
replaceVarBy "${Email_Message}" "<status>" "completed"
|
||||||
|
Email_Message="${REPLACEDRESULT}"
|
||||||
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
|
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
|
||||||
fi
|
fi; done
|
||||||
if [ "$Email_failed" = "yes" -a "$nzbStatus" != 0 ]; then
|
for item in $Email_failed; do
|
||||||
|
if [ "${NZBPP_CATEGORY}" = "$item" -a "$nzbStatus" != 0 ]; then
|
||||||
User=""
|
User=""
|
||||||
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
|
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
|
||||||
Email_Subject="${Email_Subject/<status>/failed}"
|
replaceVarBy "${Email_Subject}" "<status>" "failed"
|
||||||
Email_Message="${Email_Message/<status>/failed}"
|
Email_Subject="${REPLACEDRESULT}"
|
||||||
|
replaceVarBy "${Email_Message}" "<status>" "failed"
|
||||||
|
Email_Message="${REPLACEDRESULT}"
|
||||||
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
|
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
|
||||||
fi
|
fi; done
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if the script is called from nzbget
|
# Check if the script is called from nzbget 10.0 or later
|
||||||
if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then
|
if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then
|
||||||
echo "*** NZBGet post-process script ***"
|
echo "*** NZBGet post-processing script ***"
|
||||||
echo "This script is supposed to be called from nzbget (0.7.0 or later)."
|
echo "This script is supposed to be called from nzbget (10.0 or later)."
|
||||||
|
exit $POSTPROCESS_ERROR
|
||||||
|
fi
|
||||||
|
if [ "$NZBOP_UNPACK" = "" ]; then
|
||||||
|
echo "[ERROR] This script requires nzbget version at least 10.0-testing-r555 or 10.0-stable."
|
||||||
exit $POSTPROCESS_ERROR
|
exit $POSTPROCESS_ERROR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -196,7 +202,7 @@ fi
|
||||||
# (for current nzb-file) via web-interface or via command line with
|
# (for current nzb-file) via web-interface or via command line with
|
||||||
# "nzbget -E G O PostProcess=no <ID>"
|
# "nzbget -E G O PostProcess=no <ID>"
|
||||||
if [ "$NZBPR_PostProcess" = "no" ]; then
|
if [ "$NZBPR_PostProcess" = "no" ]; then
|
||||||
echo "[WARNING] Post-Process: Postprocessing disabled for this nzb-file, exiting"
|
echo "[WARNING] Post-Process: Post-processing disabled for this nzb-file, exiting"
|
||||||
exit $POSTPROCESS_NONE
|
exit $POSTPROCESS_NONE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -226,35 +232,25 @@ if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then
|
||||||
BadConfig=1
|
BadConfig=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$NZBOP_LOADPARS" = "none" ]; then
|
|
||||||
echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file"
|
|
||||||
BadConfig=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$NZBOP_PARREPAIR" = "no" ]; then
|
|
||||||
echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file"
|
|
||||||
BadConfig=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$BadConfig" -eq 1 ]; then
|
if [ "$BadConfig" -eq 1 ]; then
|
||||||
echo "[ERROR] Post-Process: Exiting because of not compatible nzbget configuration"
|
echo "[ERROR] Post-Process: Exiting due to incompatible nzbget configuration"
|
||||||
exit $POSTPROCESS_ERROR
|
exit $POSTPROCESS_ERROR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if all collections in nzb-file were downloaded
|
|
||||||
if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then
|
|
||||||
echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting"
|
|
||||||
exit $POSTPROCESS_SUCCESS
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check par status
|
# Check par status
|
||||||
if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then
|
if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 ]; then
|
||||||
if [ "$NZBPP_PARSTATUS" -eq 3 ]; then
|
if [ "$NZBPP_PARSTATUS" -eq 3 ]; then
|
||||||
echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting"
|
echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting"
|
||||||
else
|
else
|
||||||
echo "[WARNING] Post-Process: Par-check failed, exiting"
|
echo "[WARNING] Post-Process: Par-check failed, exiting"
|
||||||
fi
|
fi
|
||||||
do_exit $POSTPROCESS_ERROR
|
do_exit $POSTPROCESS_NONE
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check unpack status
|
||||||
|
if [ "$NZBPP_UNPACKSTATUS" -ne 2 ]; then
|
||||||
|
echo "[WARNING] Post-Process: Unpack failed or disabled, exiting"
|
||||||
|
do_exit $POSTPROCESS_NONE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if destination directory exists (important for reprocessing of history items)
|
# Check if destination directory exists (important for reprocessing of history items)
|
||||||
|
@ -265,96 +261,8 @@ fi
|
||||||
|
|
||||||
cd "$NZBPP_DIRECTORY"
|
cd "$NZBPP_DIRECTORY"
|
||||||
|
|
||||||
# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged
|
|
||||||
# exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair
|
|
||||||
if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then
|
|
||||||
if [ -f "_brokenlog.txt" ]; then
|
|
||||||
if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then
|
|
||||||
echo "[INFO] Post-Process: Brokenlog found, requesting par-repair"
|
|
||||||
exit $POSTPROCESS_PARCHECK_ALL
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# All checks done, now processing the files
|
# All checks done, now processing the files
|
||||||
|
|
||||||
# Flag indicates that something was unrared
|
|
||||||
Unrared=0
|
|
||||||
|
|
||||||
# Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing
|
|
||||||
if (ls *.rar >/dev/null 2>&1); then
|
|
||||||
|
|
||||||
# Check if unrar exists
|
|
||||||
$UnrarCmd >/dev/null 2>&1
|
|
||||||
if [ "$?" -eq 127 ]; then
|
|
||||||
echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration"
|
|
||||||
do_exit $POSTPROCESS_ERROR
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Make a temporary directory to store the unrarred files
|
|
||||||
ExtractedDirExists=0
|
|
||||||
if [ -d $ExtractedDir ]; then
|
|
||||||
ExtractedDirExists=1
|
|
||||||
else
|
|
||||||
mkdir $ExtractedDir
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[INFO] Post-Process: Unraring"
|
|
||||||
rarpasswordparam=""
|
|
||||||
if [ "$NZBPR_Password" != "" ]; then
|
|
||||||
rarpasswordparam="-p$NZBPR_Password"
|
|
||||||
fi
|
|
||||||
|
|
||||||
$UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./$ExtractedDir/
|
|
||||||
if [ "$?" -eq 3 ]; then
|
|
||||||
echo "[ERROR] Post-Process: Unrar failed"
|
|
||||||
if [ "$ExtractedDirExists" -eq 0 ]; then
|
|
||||||
rm -R $ExtractedDir
|
|
||||||
fi
|
|
||||||
# for delayed par-check/-repair at least one par-file must be already downloaded
|
|
||||||
if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then
|
|
||||||
echo "[INFO] Post-Process: Requesting par-repair"
|
|
||||||
exit $POSTPROCESS_PARCHECK_ALL
|
|
||||||
fi
|
|
||||||
do_exit $POSTPROCESS_ERROR
|
|
||||||
fi
|
|
||||||
Unrared=1
|
|
||||||
|
|
||||||
# Remove the rar files
|
|
||||||
if [ "$DeleteRarFiles" = "yes" ]; then
|
|
||||||
echo "[INFO] Post-Process: Deleting rar-files"
|
|
||||||
rm *.r[0-9][0-9] >/dev/null 2>&1
|
|
||||||
rm *.rar >/dev/null 2>&1
|
|
||||||
rm *.s[0-9][0-9] >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Go to the temp directory and try to unrar again.
|
|
||||||
# If there are any rars inside the extracted rars then these will no also be unrarred
|
|
||||||
cd $ExtractedDir
|
|
||||||
if (ls *.rar >/dev/null 2>&1); then
|
|
||||||
echo "[INFO] Post-Process: Unraring (second pass)"
|
|
||||||
$UnrarCmd x -y -p- -o+ "*.rar"
|
|
||||||
|
|
||||||
if [ "$?" -eq 3 ]; then
|
|
||||||
echo "[INFO] Post-Process: Unrar (second pass) failed"
|
|
||||||
do_exit $POSTPROCESS_ERROR
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Delete the Rar files
|
|
||||||
if [ "$DeleteRarFiles" = "yes" ]; then
|
|
||||||
echo "[INFO] Post-Process: Deleting rar-files (second pass)"
|
|
||||||
rm *.r[0-9][0-9] >/dev/null 2>&1
|
|
||||||
rm *.rar >/dev/null 2>&1
|
|
||||||
rm *.s[0-9][0-9] >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Move everything back to the Download folder
|
|
||||||
mv * ..
|
|
||||||
cd ..
|
|
||||||
rmdir $ExtractedDir
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If download contains only nzb-files move them into nzb-directory
|
# If download contains only nzb-files move them into nzb-directory
|
||||||
# for further download
|
# for further download
|
||||||
# Check if command "wc" exists
|
# Check if command "wc" exists
|
||||||
|
@ -375,10 +283,7 @@ chmod -R a+rw .
|
||||||
for word in $FileCleanUp ; do rm $word >/dev/null 2>&1 ; done
|
for word in $FileCleanUp ; do rm $word >/dev/null 2>&1 ; done
|
||||||
# Removed by default
|
# Removed by default
|
||||||
rm _brokenlog.txt >/dev/null 2>&1
|
rm _brokenlog.txt >/dev/null 2>&1
|
||||||
if [ "$Unrared" -eq 1 ]; then
|
|
||||||
# Delete par2-file only if there were files for unpacking.
|
|
||||||
rm *.[pP][aA][rR]2 >/dev/null 2>&1
|
rm *.[pP][aA][rR]2 >/dev/null 2>&1
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$JoinTS" = "yes" ]; then
|
if [ "$JoinTS" = "yes" ]; then
|
||||||
# Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts
|
# Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts
|
||||||
|
@ -404,61 +309,6 @@ if [ "$RenameIMG" = "yes" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
############################
|
|
||||||
### BEGIN CUSTOMIZATIONS ###
|
|
||||||
############################
|
|
||||||
|
|
||||||
# Move categories to /share/your_directory and remove download destination directory
|
|
||||||
# Test for category and ensure the passed directory exists as a directory.
|
|
||||||
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -d "$TvDownloadDir" ]; then
|
|
||||||
echo "[INFO] Post-Process: Moving TV shows to $TvDownloadDir"
|
|
||||||
cp -R "$NZBPP_DIRECTORY" "$TvDownloadDir"
|
|
||||||
if [ "$?" -ne 0 ]; then
|
|
||||||
echo "[ERROR] Post-Process: Moving to $TvDownloadDir"
|
|
||||||
exit $POSTPROCESS_ERROR
|
|
||||||
else
|
|
||||||
rm -fr *
|
|
||||||
cd ..
|
|
||||||
rmdir "$NZBPP_DIRECTORY"
|
|
||||||
NZBPP_DIRECTORY="$TvDownloadDir"
|
|
||||||
cd "$NZBPP_DIRECTORY"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
# Test for category and ensure the passed directory exists as a directory.
|
|
||||||
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -d "$MoviesDownloadDir" ]; then
|
|
||||||
echo "[INFO] Post-Process: Moving Movies to $MoviesDownloadDir"
|
|
||||||
cp -R "$NZBPP_DIRECTORY" "$MoviesDownloadDir"
|
|
||||||
if [ "$?" -ne 0 ]; then
|
|
||||||
echo "[ERROR] Post-Process: Moving to $MoviesDownloadDir"
|
|
||||||
exit $POSTPROCESS_ERROR
|
|
||||||
else
|
|
||||||
rm -fr *
|
|
||||||
cd ..
|
|
||||||
rmdir "$NZBPP_DIRECTORY"
|
|
||||||
NZBPP_DIRECTORY="$MoviesDownloadDir"
|
|
||||||
cd "$NZBPP_DIRECTORY"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
# Test for category and ensure the passed directory exists as a directory.
|
|
||||||
if [ "$NZBPP_CATEGORY" = "$CustomCategory" -a -d "$CustomDownloadDir" ]; then
|
|
||||||
echo "[INFO] Post-Process: Moving $CustomCategory to $CustomDownloadDir"
|
|
||||||
cp -R "$NZBPP_DIRECTORY" "$CustomDownloadDir"
|
|
||||||
if [ "$?" -ne 0 ]; then
|
|
||||||
echo "[ERROR] Post-Process: Moving to $CustomDownloadDir"
|
|
||||||
exit $POSTPROCESS_ERROR
|
|
||||||
else
|
|
||||||
rm -fr *
|
|
||||||
cd ..
|
|
||||||
rmdir "$NZBPP_DIRECTORY"
|
|
||||||
NZBPP_DIRECTORY="$CustomDownloadDir"
|
|
||||||
cd "$NZBPP_DIRECTORY"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
##########################
|
|
||||||
### END CUSTOMIZATIONS ###
|
|
||||||
##########################
|
|
||||||
|
|
||||||
# Check if destination directory was set in postprocessing parameters
|
# Check if destination directory was set in postprocessing parameters
|
||||||
# (for current nzb-file) via web-interface or via command line with
|
# (for current nzb-file) via web-interface or via command line with
|
||||||
# "nzbget -E G O DestDir=/new/path <ID>"
|
# "nzbget -E G O DestDir=/new/path <ID>"
|
||||||
|
@ -468,7 +318,7 @@ if [ "$NZBPR_DestDir" != "" ]; then
|
||||||
cd ..
|
cd ..
|
||||||
rmdir $NZBPP_DIRECTORY
|
rmdir $NZBPP_DIRECTORY
|
||||||
NZBPP_DIRECTORY=$NZBPR_DestDir
|
NZBPP_DIRECTORY=$NZBPR_DestDir
|
||||||
cd "$NZBPP_DIRECTORY"
|
cd $NZBPP_DIRECTORY
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# All OK, requesting cleaning up of download queue
|
# All OK, requesting cleaning up of download queue
|
|
@ -102,6 +102,7 @@ nzbToMedia() {
|
||||||
PostProcessStatus=0
|
PostProcessStatus=0
|
||||||
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
|
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
|
||||||
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: comparing '$NZBPP_CATEGORY' to '$CouchPotatoCategory' and '$SickBeardCategory'" ; 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 [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
|
||||||
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
|
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
|
||||||
script=$NzbToCouchPotato
|
script=$NzbToCouchPotato
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue