Added Customizable Extarct Directories

As provided by schumi2004 (on QNAP forums), modified by hugbug (on
SourceForge) and then edited here to allow writing of the parameters to
the .conf files.
This commit is contained in:
Clinton Hall 2012-11-30 15:54:20 +10:30
commit 23fbe0bbc9
4 changed files with 775 additions and 679 deletions

View file

@ -8,10 +8,18 @@ UnrarCmd=unrar
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.
SabToSickBeard=/usr/local/nzbget/var/sabToSickBeard.py NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py
# Set the full path where completed movies should be placed
# before CouchPotato's Renamer is called
TV_DL_DIR=/usr/local/nzbget/complete/tv
# 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
MOVIES_DL_DIR=/usr/local/nzbget/complete/movies
############################################################################## ##############################################################################

View file

@ -1,342 +1,378 @@
#!/bin/sh #!/bin/sh
# #
# Example postprocessing script for NZBGet # This file if part of nzbget
# #
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com> # Example postprocessing script for NZBGet
# Copyright (C) 2008 Otmar Werner #
# Copyright (C) 2008-2009 Andrei Prygounkov <hugbug@users.sourceforge.net> # Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
# Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com> # Copyright (C) 2008 Otmar Werner
# Copyright (C) 2012 Jürgen Seif <thor78@gmx.at> # Copyright (C) 2008-2012 Andrey Prygunkov <hugbug@users.sourceforge.net>
# # Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
# 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 # This program is free software; you can redistribute it and/or modify
# the Free Software Foundation; either version 2 of the License, or # it under the terms of the GNU General Public License as published by
# (at your option) any later version. # the Free Software Foundation; either version 2 of the License, or
# # (at your option) any later version.
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of # This program is distributed in the hope that it will be useful,
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# # GNU General Public License for more details.
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software # You should have received a copy of the GNU General Public License
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # along with this program; if not, write to the Free Software
# # 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 ####################### Usage instructions #######################
# to iso. # o Script will unrar downloaded rar files, 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.: # o To use this script with nzbget set the option "PostProcess" in
# PostProcess=/home/user/nzbget/nzbget-postprocess.sh # 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 # o The script needs a configuration file. An example configuration file
# into the directory where nzbget's configuration file (nzbget.conf) or where # is provided in file "postprocess-example.conf". Put the configuration file
# this script itself is located. Then edit the configuration file in any # into the directory where nzbget's configuration file (nzbget.conf) or where
# text editor to adjust the settings. # this script itself 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 # o You can also edit the script's configuration via web-interface (requires
# "PostProcessConfigTemplate" to point to "postprocess-example.conf" # NZBGetWeb 1.4 or later). Set the options "PostProcessConfigFile" and
# (including full path). The both options are under the section # "PostProcessConfigTemplate" to point to "postprocess-example.conf"
# "CONFIGURATION OF POSTPROCESSING-SCRIPT" in NZBGetWeb. # (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 #
# individually. To view/edit them in web-interface click on a spanner icon # o There are few options, which can be ajdusted for each nzb-file
# near the name of 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 # o The script supports the feature called "delayed par-check".
# them fisrt. Only if unpack fails, the script schedules par-check, # That means it can try to unpack downloaded files without par-checking
# then unpacks again. # them fisrt. Only if unpack fails, the script schedules par-check,
# To use delayed par-check set following options in nzbget configuration file: # then unpacks again.
# ParCheck=no # To use delayed par-check set following options in nzbget configuration file:
# ParRepair=yes # ParCheck=no
# LoadPars=one (or) LoadPars=all # 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 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 #######################
# 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_NZBFILENAME - name of processed nzb-file;
# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were # NZBPP_PARFILENAME - name of par-file or empty string (if no collections were
# found); # found);
# 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 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_NZBCOMPLETED - state of nzb-job:
# 0 = there are more collections in this nzb-file queued; # 0 = there are more collections in this nzb-file queued;
# 1 = this was the last collection in nzb-file; # 1 = this was the last collection in nzb-file;
# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file: # NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file:
# 0 = no failed par-jobs; # 0 = no failed par-jobs;
# 1 = current par-job or any of the previous par-jobs for # 1 = current par-job or any of the previous par-jobs for
# the same nzb-files failed; # the same nzb-files failed;
# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string). # 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="postprocess.conf"
# Exit codes # Exit codes
POSTPROCESS_PARCHECK_CURRENT=91 POSTPROCESS_PARCHECK_CURRENT=91
POSTPROCESS_PARCHECK_ALL=92 POSTPROCESS_PARCHECK_ALL=92
POSTPROCESS_SUCCESS=93 POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94 POSTPROCESS_ERROR=94
POSTPROCESS_NONE=95 POSTPROCESS_NONE=95
# Check if the script is called from nzbget
# Check if the script is called from nzbget if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then
if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then echo "*** NZBGet post-process script ***"
echo "*** NZBGet post-process 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 (0.7.0 or later)." exit $POSTPROCESS_ERROR
exit $POSTPROCESS_ERROR fi
fi
# Check if postprocessing was disabled in postprocessing parameters
# Check if postprocessing was disabled 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 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: Postprocessing disabled for this nzb-file, exiting" exit $POSTPROCESS_NONE
exit $POSTPROCESS_NONE fi
fi
echo "[INFO] Post-Process: Post-process script successfully started"
echo "[INFO] Post-Process: Post-process script successfully started"
# Determine the location of configuration file (it must be stored in
# Determine the location of configuration file (it must be stored in # the directory with nzbget.conf or in this script's directory).
# the directory with nzbget.conf or in this script's directory). ConfigDir="${NZBOP_CONFIGFILE%/*}"
ConfigDir="${NZBOP_CONFIGFILE%/*}" ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE"
ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" if [ ! -f "$ScriptConfigFile" ]; then
if [ ! -f "$ScriptConfigFile" ]; then ConfigDir="${0%/*}"
ConfigDir="${0%/*}" ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE"
ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" fi
fi if [ ! -f "$ScriptConfigFile" ]; then
if [ ! -f "$ScriptConfigFile" ]; then echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting"
echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" exit $POSTPROCESS_ERROR
exit $POSTPROCESS_ERROR fi
fi
# Readg configuration file
# Readg configuration file while read line; do eval "$line"; done < $ScriptConfigFile
while read line; do eval "$line"; done < $ScriptConfigFile
# Check nzbget.conf options
# Check nzbget.conf options BadConfig=0
BadConfig=0
if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then
if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file"
echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file" BadConfig=1
BadConfig=1 fi
fi
if [ "$NZBOP_LOADPARS" = "none" ]; then
if [ "$NZBOP_LOADPARS" = "none" ]; then echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file"
echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file" BadConfig=1
BadConfig=1 fi
fi
if [ "$NZBOP_PARREPAIR" = "no" ]; then
if [ "$NZBOP_PARREPAIR" = "no" ]; then echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file"
echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file" BadConfig=1
BadConfig=1 fi
fi
if [ "$BadConfig" -eq 1 ]; then
if [ "$BadConfig" -eq 1 ]; then echo "[ERROR] Post-Process: Existing because of not compatible nzbget configuration"
echo "[ERROR] Post-Process: Existing because of not compatible nzbget configuration" exit $POSTPROCESS_ERROR
exit $POSTPROCESS_ERROR fi
fi
# Check if all collections in nzb-file were downloaded
# Check if all collections in nzb-file were downloaded if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then
if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting"
echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting" exit $POSTPROCESS_SUCCESS
exit $POSTPROCESS_SUCCESS fi
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 -o "$NZBPP_PARFAILED" -eq 1 ]; 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 exit $POSTPROCESS_ERROR
exit $POSTPROCESS_ERROR fi
fi
# Check if destination directory exists (important for reprocessing of history items)
# Check if destination directory exists (important for reprocessing of history items) if [ ! -d "$NZBPP_DIRECTORY" ]; then
if [ ! -d "$NZBPP_DIRECTORY" ]; then echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist"
echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist" exit $POSTPROCESS_ERROR
exit $POSTPROCESS_ERROR fi
fi
cd "$NZBPP_DIRECTORY"
cd "$NZBPP_DIRECTORY"
# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged
# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged # exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair
# exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then
if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then if [ -f "_brokenlog.txt" ]; then
if [ -f "_brokenlog.txt" ]; then if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then
if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then echo "[INFO] Post-Process: Brokenlog found, requesting par-repair"
echo "[INFO] Post-Process: Brokenlog found, requesting par-repair" exit $POSTPROCESS_PARCHECK_ALL
exit $POSTPROCESS_PARCHECK_ALL fi
fi fi
fi fi
fi
# All checks done, now processing the files
# All checks done, now processing the files
# Flag indicates that something was unrared
# Flag indicates that something was unrared Unrared=0
Unrared=0
# Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing
# 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
if (ls *.rar >/dev/null 2>&1); then
# Check if unrar exists
# Check if unrar exists $UnrarCmd >/dev/null 2>&1
$UnrarCmd >/dev/null 2>&1 if [ "$?" -eq 127 ]; then
if [ "$?" -eq 127 ]; then echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration"
echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration" exit $POSTPROCESS_ERROR
exit $POSTPROCESS_ERROR fi
fi
# Make a temporary directory to store the unrarred files
# Make a temporary directory to store the unrarred files ExtractedDirExists=0
ExtractedDirExists=0 if [ -d $ExtractedDir ]; then
if [ -d $ExtractedDir ]; then ExtractedDirExists=1
ExtractedDirExists=1 else
else mkdir $ExtractedDir
mkdir $ExtractedDir fi
fi
echo "[INFO] Post-Process: Unraring"
echo "[INFO] Post-Process: Unraring" rarpasswordparam=""
rarpasswordparam="" if [ "$NZBPR_Password" != "" ]; then
if [ "$NZBPR_Password" != "" ]; then rarpasswordparam="-p$NZBPR_Password"
rarpasswordparam="-p$NZBPR_Password" fi
fi
$UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./$ExtractedDir/
$UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./$ExtractedDir/ if [ "$?" -eq 3 ]; then
if [ "$?" -eq 3 ]; then echo "[ERROR] Post-Process: Unrar failed"
echo "[ERROR] Post-Process: Unrar failed" if [ "$ExtractedDirExists" -eq 0 ]; then
if [ "$ExtractedDirExists" -eq 0 ]; then rm -R $ExtractedDir
rm -R $ExtractedDir fi
fi # for delayed par-check/-repair at least one par-file must be already downloaded
# 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
if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then echo "[INFO] Post-Process: Requesting par-repair"
echo "[INFO] Post-Process: Requesting par-repair" exit $POSTPROCESS_PARCHECK_ALL
exit $POSTPROCESS_PARCHECK_ALL fi
fi exit $POSTPROCESS_ERROR
exit $POSTPROCESS_ERROR fi
fi Unrared=1
Unrared=1
# Remove the rar files
# Remove the rar files if [ "$DeleteRarFiles" = "yes" ]; then
if [ "$DeleteRarFiles" = "yes" ]; then echo "[INFO] Post-Process: Deleting rar-files"
echo "[INFO] Post-Process: Deleting rar-files" rm *.r[0-9][0-9] >/dev/null 2>&1
rm *.r[0-9][0-9] >/dev/null 2>&1 rm *.rar >/dev/null 2>&1
rm *.rar >/dev/null 2>&1 rm *.s[0-9][0-9] >/dev/null 2>&1
rm *.s[0-9][0-9] >/dev/null 2>&1 fi
fi
# Go to the temp directory and try to unrar again.
# 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
# If there are any rars inside the extracted rars then these will no also be unrarred cd $ExtractedDir
cd $ExtractedDir if (ls *.rar >/dev/null 2>&1); then
if (ls *.rar >/dev/null 2>&1); then echo "[INFO] Post-Process: Unraring (second pass)"
echo "[INFO] Post-Process: Unraring (second pass)" $UnrarCmd x -y -p- -o+ "*.rar"
$UnrarCmd x -y -p- -o+ "*.rar"
if [ "$?" -eq 3 ]; then
if [ "$?" -eq 3 ]; then echo "[INFO] Post-Process: Unrar (second pass) failed"
echo "[INFO] Post-Process: Unrar (second pass) failed" exit $POSTPROCESS_ERROR
exit $POSTPROCESS_ERROR fi
fi
# Delete the Rar files
# Delete the Rar files if [ "$DeleteRarFiles" = "yes" ]; then
if [ "$DeleteRarFiles" = "yes" ]; then echo "[INFO] Post-Process: Deleting rar-files (second pass)"
echo "[INFO] Post-Process: Deleting rar-files (second pass)" rm *.r[0-9][0-9] >/dev/null 2>&1
rm *.r[0-9][0-9] >/dev/null 2>&1 rm *.rar >/dev/null 2>&1
rm *.rar >/dev/null 2>&1 rm *.s[0-9][0-9] >/dev/null 2>&1
rm *.s[0-9][0-9] >/dev/null 2>&1 fi
fi fi
fi
# Move everything back to the Download folder
# Move everything back to the Download folder mv * ..
mv * .. cd ..
cd .. rmdir $ExtractedDir
rmdir $ExtractedDir fi
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 wc -l . >/dev/null 2>&1
wc -l . >/dev/null 2>&1 if [ "$?" -ne 127 ]; then
if [ "$?" -ne 127 ]; then AllFilesCount=`ls -1 2>/dev/null | wc -l`
AllFilesCount=`ls -1 2>/dev/null | wc -l` NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l`
NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l` if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then
if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download"
echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download" mv *.nzb $NZBOP_NZBDIR
mv *.nzb $NZBOP_NZBDIR fi
fi fi
fi
# Clean up
# Clean up echo "[INFO] Post-Process: Cleaning up"
echo "[INFO] Post-Process: Cleaning up" chmod -R a+rw .
chmod -R a+rw . rm *.nzb >/dev/null 2>&1
rm *.nzb >/dev/null 2>&1 rm *.sfv >/dev/null 2>&1
rm *.sfv >/dev/null 2>&1 rm *.1 >/dev/null 2>&1
rm *.1 >/dev/null 2>&1 rm _brokenlog.txt >/dev/null 2>&1
rm _brokenlog.txt >/dev/null 2>&1 if [ "$Unrared" -eq 1 ]; then
if [ "$Unrared" -eq 1 ]; then # Delete par2-file only if there were files for unpacking.
# 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
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 # They will be joined together to a file called xxxx.0001.ts
# They will be joined together to a file called xxxx.0001.ts if (ls *.ts >/dev/null 2>&1); then
if (ls *.ts >/dev/null 2>&1); then echo "[INFO] Post-Process: Joining ts-files"
echo "[INFO] Post-Process: Joining ts-files" tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'`
tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'` cat *0???.ts > ./$tsname
cat *0???.ts > ./$tsname fi
fi
# Remove all the split .ts files
# Remove all the split .ts files echo "[INFO] Post-Process: Deleting source ts-files"
echo "[INFO] Post-Process: Deleting source ts-files" rm *0???.ts >/dev/null 2>&1
rm *0???.ts >/dev/null 2>&1 fi
fi
if [ "$RenameIMG" = "yes" ]; then
if [ "$RenameIMG" = "yes" ]; then # Rename img file to iso
# Rename img file to iso # It will be renamed to .img.iso so you can see that it has been renamed
# It will be renamed to .img.iso so you can see that it has been renamed if (ls *.img >/dev/null 2>&1); then
if (ls *.img >/dev/null 2>&1); then echo "[INFO] Post-Process: Renaming img-files to iso"
echo "[INFO] Post-Process: Renaming img-files to iso" imgname=`find . -name "*.img" |awk -F/ '{print $NF}'`
imgname=`find . -name "*.img" |awk -F/ '{print $NF}'` mv $imgname $imgname.iso
mv $imgname $imgname.iso fi
fi fi
fi
############################
if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$SabToSickBeard" ]; then ### BEGIN CUSTOMIZATIONS ###
# Call SickBeard's postprocessing script ############################
echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
$PythonCmd $SabToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 # Move categories to /share/yourdirectory and remove download destination directory
fi if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then
echo "[INFO] Post-Process: Moving TV shows to $TV_DL_DIR"
if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then cp -R "$NZBPP_DIRECTORY" "$TV_DL_DIR" >/dev/null 2>&1
# Call Couchpotato's postprocessing script if [ "$?" -ne 0 ]; then
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" echo "[ERROR] Post-Process: Moving to $TV_DL_DIR"
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 exit $POSTPROCESS_ERROR
fi else
rm -fr *
# Check if destination directory was set in postprocessing parameters cd ..
# (for current nzb-file) via web-interface or via command line with rmdir "$NZBPP_DIRECTORY"
# "nzbget -E G O DestDir=/new/path <ID>" NZBPP_DIRECTORY="$TV_DL_DIR"
if [ "$NZBPR_DestDir" != "" ]; then fi
mkdir $NZBPR_DestDir fi
mv * $NZBPR_DestDir >/dev/null 2>&1
cd .. if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
rmdir $NZBPP_DIRECTORY echo "[INFO] Post-Process: Moving Movies to $MOVIES_DL_DIR"
fi cp -R "$NZBPP_DIRECTORY" "$MOVIES_DL_DIR" >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
# All OK, requesting cleaning up of download queue echo "[ERROR] Post-Process: Moving to $MOVIES_DL_DIR"
exit $POSTPROCESS_SUCCESS exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$MOVIES_DL_DIR"
fi
fi
##########################
### END CUSTOMIZATIONS ###
##########################
if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$NzbToSickBeard" ]; then
# Call SickBeard's postprocessing script
echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1
fi
if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then
# Call CouchPotato's postprocessing script
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script"
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1
fi
# Check if destination directory was set in postprocessing parameters
# (for current nzb-file) via web-interface or via command line with
# "nzbget -E G O DestDir=/new/path <ID>"
if [ "$NZBPR_DestDir" != "" ]; then
mkdir $NZBPR_DestDir
mv * $NZBPR_DestDir >/dev/null 2>&1
cd ..
rmdir $NZBPP_DIRECTORY
fi
# All OK, requesting cleaning up of download queue
exit $POSTPROCESS_SUCCESS

View file

@ -1,334 +1,378 @@
#!/bin/sh #!/bin/sh
# #
# This file if part of nzbget # 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 Andrey Prygunkov <hugbug@users.sourceforge.net> # Copyright (C) 2008-2012 Andrey Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2012 Jürgen Seif <thor78@gmx.at> # Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
# #
# 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
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 unrar downloaded rar files, 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 "nzbget-postprocess.conf". Put the configuration file # is provided in file "postprocess-example.conf". Put the configuration file
# into the directory where nzbget's configuration file (nzbget.conf) is located. # into the directory where nzbget's configuration file (nzbget.conf) or where
# Then edit the configuration file in any text editor to adjust the settings. # this script itself 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. #
# # o You can also edit the script's configuration via web-interface (requires
# o There are few options, which can be ajdusted for each nzb-file individually. # NZBGetWeb 1.4 or later). Set the options "PostProcessConfigFile" and
# # "PostProcessConfigTemplate" to point to "postprocess-example.conf"
# o The script supports the feature called "delayed par-check". # (including full path). The both options are under the section
# That means it can try to unpack downloaded files without par-checking # "CONFIGURATION OF POSTPROCESSING-SCRIPT" in NZBGetWeb.
# them fisrt. Only if unpack fails, the script schedules par-check, #
# then unpacks again. # o There are few options, which can be ajdusted for each nzb-file
# To use delayed par-check set following options in nzbget configuration file: # individually. To view/edit them in web-interface click on a spanner icon
# ParCheck=no # near the name of nzb-file.
# ParRepair=yes #
# LoadPars=one (or) LoadPars=all # o The script supports the feature called "delayed par-check".
# # That means it can try to unpack downloaded files without par-checking
# o If you want to par-check/repair all files before trying to unpack them, # them fisrt. Only if unpack fails, the script schedules par-check,
# set option "ParCheck=yes". # then unpacks again.
# # To use delayed par-check set following options in nzbget configuration file:
####################### End of Usage instructions ####################### # ParCheck=no
# ParRepair=yes
# LoadPars=one (or) LoadPars=all
# NZBGet passes following arguments to postprocess-programm as environment #
# variables: # o If you want to par-check/repair all files before trying to unpack them,
# NZBPP_DIRECTORY - path to destination dir for downloaded files; # set option "ParCheck=yes".
# NZBPP_NZBFILENAME - name of processed nzb-file; #
# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were ####################### End of Usage instructions #######################
# found);
# NZBPP_PARSTATUS - result of par-check:
# 0 = not checked: par-check disabled or nzb-file does # NZBGet passes following arguments to postprocess-programm as environment
# not contain any par-files; # variables:
# 1 = checked and failed to repair; # NZBPP_DIRECTORY - path to destination dir for downloaded files;
# 2 = checked and successfully repaired; # NZBPP_NZBFILENAME - name of processed nzb-file;
# 3 = checked and can be repaired but repair is disabled; # NZBPP_PARFILENAME - name of par-file or empty string (if no collections were
# NZBPP_NZBCOMPLETED - state of nzb-job: # found);
# 0 = there are more collections in this nzb-file queued; # NZBPP_PARSTATUS - result of par-check:
# 1 = this was the last collection in nzb-file; # 0 = not checked: par-check disabled or nzb-file does
# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file: # not contain any par-files;
# 0 = no failed par-jobs; # 1 = checked and failed to repair;
# 1 = current par-job or any of the previous par-jobs for # 2 = checked and successfully repaired;
# the same nzb-files failed; # 3 = checked and can be repaired but repair is disabled;
# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string). # 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;
# Name of script's configuration file # NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file:
SCRIPT_CONFIG_FILE="nzbget-postprocess.conf" # 0 = no failed par-jobs;
# 1 = current par-job or any of the previous par-jobs for
# Exit codes # the same nzb-files failed;
POSTPROCESS_PARCHECK_CURRENT=91 # NZBPP_CATEGORY - category assigned to nzb-file (can be empty string).
POSTPROCESS_PARCHECK_ALL=92
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94 # Name of script's configuration file
POSTPROCESS_NONE=95 SCRIPT_CONFIG_FILE="nzbget-postprocess.conf"
# Check if the script is called from nzbget # Exit codes
if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then POSTPROCESS_PARCHECK_CURRENT=91
echo "*** NZBGet post-process script ***" POSTPROCESS_PARCHECK_ALL=92
echo "This script is supposed to be called from nzbget (0.7.0 or later)." POSTPROCESS_SUCCESS=93
exit $POSTPROCESS_ERROR POSTPROCESS_ERROR=94
fi POSTPROCESS_NONE=95
# Check if postprocessing was disabled in postprocessing parameters # Check if the script is called from nzbget
# (for current nzb-file) via web-interface or via command line with if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then
# "nzbget -E G O PostProcess=no <ID>" echo "*** NZBGet post-process script ***"
if [ "$NZBPR_PostProcess" = "no" ]; then echo "This script is supposed to be called from nzbget (0.7.0 or later)."
echo "[WARNING] Post-Process: Postprocessing disabled for this nzb-file, exiting" exit $POSTPROCESS_ERROR
exit $POSTPROCESS_NONE fi
fi
# Check if postprocessing was disabled in postprocessing parameters
echo "[INFO] Post-Process: Post-process script successfully started" # (for current nzb-file) via web-interface or via command line with
# "nzbget -E G O PostProcess=no <ID>"
# Determine the location of configuration file (it must be stored in if [ "$NZBPR_PostProcess" = "no" ]; then
# the directory with nzbget.conf or in this script's directory). echo "[WARNING] Post-Process: Postprocessing disabled for this nzb-file, exiting"
ConfigDir="${NZBOP_CONFIGFILE%/*}" exit $POSTPROCESS_NONE
ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" fi
if [ ! -f "$ScriptConfigFile" ]; then
ConfigDir="${0%/*}" echo "[INFO] Post-Process: Post-process script successfully started"
ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE"
fi # Determine the location of configuration file (it must be stored in
if [ ! -f "$ScriptConfigFile" ]; then # the directory with nzbget.conf or in this script's directory).
echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" ConfigDir="${NZBOP_CONFIGFILE%/*}"
exit $POSTPROCESS_ERROR ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE"
fi if [ ! -f "$ScriptConfigFile" ]; then
ConfigDir="${0%/*}"
# Readg configuration file ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE"
while read line; do eval "$line"; done < $ScriptConfigFile fi
if [ ! -f "$ScriptConfigFile" ]; then
# Check nzbget.conf options echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting"
BadConfig=0 exit $POSTPROCESS_ERROR
fi
if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then
echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file" # Readg configuration file
BadConfig=1 while read line; do eval "$line"; done < $ScriptConfigFile
fi
# Check nzbget.conf options
if [ "$NZBOP_LOADPARS" = "none" ]; then BadConfig=0
echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file"
BadConfig=1 if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then
fi echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file"
BadConfig=1
if [ "$NZBOP_PARREPAIR" = "no" ]; then fi
echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file"
BadConfig=1 if [ "$NZBOP_LOADPARS" = "none" ]; then
fi echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file"
BadConfig=1
if [ "$BadConfig" -eq 1 ]; then fi
echo "[ERROR] Post-Process: Exiting because of not compatible nzbget configuration"
exit $POSTPROCESS_ERROR if [ "$NZBOP_PARREPAIR" = "no" ]; then
fi echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file"
BadConfig=1
# Check if all collections in nzb-file were downloaded fi
if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then
echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting" if [ "$BadConfig" -eq 1 ]; then
exit $POSTPROCESS_SUCCESS echo "[ERROR] Post-Process: Exiting because of not compatible nzbget configuration"
fi exit $POSTPROCESS_ERROR
fi
# Check par status
if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then # Check if all collections in nzb-file were downloaded
if [ "$NZBPP_PARSTATUS" -eq 3 ]; then if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then
echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting"
else exit $POSTPROCESS_SUCCESS
echo "[WARNING] Post-Process: Par-check failed, exiting" fi
fi
exit $POSTPROCESS_ERROR # Check par status
fi if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then
if [ "$NZBPP_PARSTATUS" -eq 3 ]; then
# Check if destination directory exists (important for reprocessing of history items) echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting"
if [ ! -d "$NZBPP_DIRECTORY" ]; then else
echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist" echo "[WARNING] Post-Process: Par-check failed, exiting"
exit $POSTPROCESS_ERROR fi
fi exit $POSTPROCESS_ERROR
fi
cd "$NZBPP_DIRECTORY"
# Check if destination directory exists (important for reprocessing of history items)
# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged if [ ! -d "$NZBPP_DIRECTORY" ]; then
# exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist"
if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then exit $POSTPROCESS_ERROR
if [ -f "_brokenlog.txt" ]; then fi
if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then
echo "[INFO] Post-Process: Brokenlog found, requesting par-repair" cd "$NZBPP_DIRECTORY"
exit $POSTPROCESS_PARCHECK_ALL
fi # If not just repaired and file "_brokenlog.txt" exists, the collection is damaged
fi # exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair
fi if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then
if [ -f "_brokenlog.txt" ]; then
# All checks done, now processing the files if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then
echo "[INFO] Post-Process: Brokenlog found, requesting par-repair"
# Flag indicates that something was unrared exit $POSTPROCESS_PARCHECK_ALL
Unrared=0 fi
fi
# Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing fi
if (ls *.rar >/dev/null 2>&1); then
# All checks done, now processing the files
# Check if unrar exists
$UnrarCmd >/dev/null 2>&1 # Flag indicates that something was unrared
if [ "$?" -eq 127 ]; then Unrared=0
echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration"
exit $POSTPROCESS_ERROR # Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing
fi if (ls *.rar >/dev/null 2>&1); then
# Make a temporary directory to store the unrarred files # Check if unrar exists
ExtractedDirExists=0 $UnrarCmd >/dev/null 2>&1
if [ -d extracted ]; then if [ "$?" -eq 127 ]; then
ExtractedDirExists=1 echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration"
else exit $POSTPROCESS_ERROR
mkdir extracted fi
fi
# Make a temporary directory to store the unrarred files
echo "[INFO] Post-Process: Unraring" ExtractedDirExists=0
rarpasswordparam="" if [ -d extracted ]; then
if [ "$NZBPR_Password" != "" ]; then ExtractedDirExists=1
rarpasswordparam="-p$NZBPR_Password" else
fi mkdir extracted
fi
$UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./extracted/
if [ "$?" -ne 0 ]; then echo "[INFO] Post-Process: Unraring"
echo "[ERROR] Post-Process: Unrar failed" rarpasswordparam=""
if [ "$ExtractedDirExists" -eq 0 ]; then if [ "$NZBPR_Password" != "" ]; then
rm -R extracted rarpasswordparam="-p$NZBPR_Password"
fi 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 $UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./extracted/
echo "[INFO] Post-Process: Requesting par-repair" if [ "$?" -ne 0 ]; then
exit $POSTPROCESS_PARCHECK_ALL echo "[ERROR] Post-Process: Unrar failed"
fi if [ "$ExtractedDirExists" -eq 0 ]; then
exit $POSTPROCESS_ERROR rm -R extracted
fi fi
Unrared=1 # 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
# Remove the rar files echo "[INFO] Post-Process: Requesting par-repair"
if [ "$DeleteRarFiles" = "yes" ]; then exit $POSTPROCESS_PARCHECK_ALL
echo "[INFO] Post-Process: Deleting rar-files" fi
rm *.r[0-9][0-9] >/dev/null 2>&1 exit $POSTPROCESS_ERROR
rm *.rar >/dev/null 2>&1 fi
rm *.s[0-9][0-9] >/dev/null 2>&1 Unrared=1
fi
# Remove the rar files
# Go to the temp directory and try to unrar again. if [ "$DeleteRarFiles" = "yes" ]; then
# If there are any rars inside the extracted rars then these will no also be unrarred echo "[INFO] Post-Process: Deleting rar-files"
cd extracted rm *.r[0-9][0-9] >/dev/null 2>&1
if (ls *.rar >/dev/null 2>&1); then rm *.rar >/dev/null 2>&1
echo "[INFO] Post-Process: Unraring (second pass)" rm *.s[0-9][0-9] >/dev/null 2>&1
$UnrarCmd x -y -p- -o+ "*.rar" fi
if [ "$?" -ne 0 ]; then # Go to the temp directory and try to unrar again.
echo "[INFO] Post-Process: Unrar (second pass) failed" # If there are any rars inside the extracted rars then these will no also be unrarred
exit $POSTPROCESS_ERROR cd extracted
fi if (ls *.rar >/dev/null 2>&1); then
echo "[INFO] Post-Process: Unraring (second pass)"
# Delete the Rar files $UnrarCmd x -y -p- -o+ "*.rar"
if [ "$DeleteRarFiles" = "yes" ]; then
echo "[INFO] Post-Process: Deleting rar-files (second pass)" if [ "$?" -ne 0 ]; then
rm *.r[0-9][0-9] >/dev/null 2>&1 echo "[INFO] Post-Process: Unrar (second pass) failed"
rm *.rar >/dev/null 2>&1 exit $POSTPROCESS_ERROR
rm *.s[0-9][0-9] >/dev/null 2>&1 fi
fi
fi # Delete the Rar files
if [ "$DeleteRarFiles" = "yes" ]; then
# Move everything back to the Download folder echo "[INFO] Post-Process: Deleting rar-files (second pass)"
mv * .. rm *.r[0-9][0-9] >/dev/null 2>&1
cd .. rm *.rar >/dev/null 2>&1
rmdir extracted rm *.s[0-9][0-9] >/dev/null 2>&1
fi fi
fi
# If download contains only nzb-files move them into nzb-directory
# for further download # Move everything back to the Download folder
# Check if command "wc" exists mv * ..
wc -l . >/dev/null 2>&1 cd ..
if [ "$?" -ne 127 ]; then rmdir extracted
AllFilesCount=`ls -1 2>/dev/null | wc -l` fi
NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l`
if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then # If download contains only nzb-files move them into nzb-directory
echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download" # for further download
mv *.nzb $NZBOP_NZBDIR # Check if command "wc" exists
fi wc -l . >/dev/null 2>&1
fi if [ "$?" -ne 127 ]; then
AllFilesCount=`ls -1 2>/dev/null | wc -l`
# Clean up NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l`
echo "[INFO] Post-Process: Cleaning up" if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then
chmod -R a+rw . echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download"
rm *.nzb >/dev/null 2>&1 mv *.nzb $NZBOP_NZBDIR
rm *.sfv >/dev/null 2>&1 fi
rm *.1 >/dev/null 2>&1 fi
rm _brokenlog.txt >/dev/null 2>&1
if [ "$Unrared" -eq 1 ]; then # Clean up
# Delete par2-file only if there were files for unpacking. echo "[INFO] Post-Process: Cleaning up"
rm *.[pP][aA][rR]2 >/dev/null 2>&1 chmod -R a+rw .
fi rm *.nzb >/dev/null 2>&1
rm *.sfv >/dev/null 2>&1
if [ "$JoinTS" = "yes" ]; then rm *.1 >/dev/null 2>&1
# Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts rm _brokenlog.txt >/dev/null 2>&1
# They will be joined together to a file called xxxx.0001.ts if [ "$Unrared" -eq 1 ]; then
if (ls *.ts >/dev/null 2>&1); then # Delete par2-file only if there were files for unpacking.
echo "[INFO] Post-Process: Joining ts-files" rm *.[pP][aA][rR]2 >/dev/null 2>&1
tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'` fi
cat *0???.ts > ./$tsname
fi if [ "$JoinTS" = "yes" ]; then
# Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts
# Remove all the split .ts files # They will be joined together to a file called xxxx.0001.ts
echo "[INFO] Post-Process: Deleting source ts-files" if (ls *.ts >/dev/null 2>&1); then
rm *0???.ts >/dev/null 2>&1 echo "[INFO] Post-Process: Joining ts-files"
fi tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'`
cat *0???.ts > ./$tsname
if [ "$RenameIMG" = "yes" ]; then fi
# Rename img file to iso
# It will be renamed to .img.iso so you can see that it has been renamed # Remove all the split .ts files
if (ls *.img >/dev/null 2>&1); then echo "[INFO] Post-Process: Deleting source ts-files"
echo "[INFO] Post-Process: Renaming img-files to iso" rm *0???.ts >/dev/null 2>&1
imgname=`find . -name "*.img" |awk -F/ '{print $NF}'` fi
mv $imgname $imgname.iso
fi if [ "$RenameIMG" = "yes" ]; then
fi # Rename img file to iso
# It will be renamed to .img.iso so you can see that it has been renamed
if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$SabToSickBeard" ]; then if (ls *.img >/dev/null 2>&1); then
# Call SickBeard's postprocessing script echo "[INFO] Post-Process: Renaming img-files to iso"
echo "[INFO] Post-Process: Running SickBeard's postprocessing script" imgname=`find . -name "*.img" |awk -F/ '{print $NF}'`
$PythonCmd $SabToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 mv $imgname $imgname.iso
fi fi
fi
if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then
# Call Couchpotato's postprocessing script ############################
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" ### BEGIN CUSTOMIZATIONS ###
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 ############################
fi
# Move categories to /share/yourdirectory and remove download destination directory
# Check if destination directory was set in postprocessing parameters if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then
# (for current nzb-file) via web-interface or via command line with echo "[INFO] Post-Process: Moving TV shows to $TV_DL_DIR"
# "nzbget -E G O DestDir=/new/path <ID>" cp -R "$NZBPP_DIRECTORY" "$TV_DL_DIR" >/dev/null 2>&1
if [ "$NZBPR_DestDir" != "" ]; then if [ "$?" -ne 0 ]; then
mkdir $NZBPR_DestDir echo "[ERROR] Post-Process: Moving to $TV_DL_DIR"
mv * $NZBPR_DestDir >/dev/null 2>&1 exit $POSTPROCESS_ERROR
cd .. else
rmdir $NZBPP_DIRECTORY rm -fr *
fi cd ..
rmdir "$NZBPP_DIRECTORY"
# All OK, requesting cleaning up of download queue NZBPP_DIRECTORY="$TV_DL_DIR"
exit $POSTPROCESS_SUCCESS fi
fi
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
echo "[INFO] Post-Process: Moving Movies to $MOVIES_DL_DIR"
cp -R "$NZBPP_DIRECTORY" "$MOVIES_DL_DIR" >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $MOVIES_DL_DIR"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$MOVIES_DL_DIR"
fi
fi
##########################
### END CUSTOMIZATIONS ###
##########################
if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$NzbToSickBeard" ]; then
# Call SickBeard's postprocessing script
echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1
fi
if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then
# Call CouchPotato's postprocessing script
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script"
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1
fi
# Check if destination directory was set in postprocessing parameters
# (for current nzb-file) via web-interface or via command line with
# "nzbget -E G O DestDir=/new/path <ID>"
if [ "$NZBPR_DestDir" != "" ]; then
mkdir $NZBPR_DestDir
mv * $NZBPR_DestDir >/dev/null 2>&1
cd ..
rmdir $NZBPP_DIRECTORY
fi
# All OK, requesting cleaning up of download queue
exit $POSTPROCESS_SUCCESS

View file

@ -33,10 +33,18 @@ UnrarCmd=unrar
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.
SabToSickBeard=/opt/share/nzbget/scripts/sabToSickBeard.py NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py
# Set the full path where completed movies should be placed
# before CouchPotato's Renamer is called
TV_DL_DIR=/usr/local/nzbget/complete/tv
# Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing # Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing
NzbToCouchPotato=/opt/share/nzbget/scripts/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
MOVIES_DL_DIR=/usr/local/nzbget/complete/movies
############################################################################## ##############################################################################
### OPTIONS ### ### OPTIONS ###