NZBGet v11.0 now stable

This commit is contained in:
clinton-hall 2013-07-03 07:52:24 +09:30
commit 66edc921de
12 changed files with 176 additions and 1681 deletions

View file

@ -1 +1,3 @@
Current Stable Release: NZBGet V10.0
Current stable release is NZBGet V11.0
NZBGet V11+ calls multiple scripts directly. This current configuration is no-longer used and the entire nzbget-postprocessing-files folder will be deleted once all nzbget packages are updated.
Please see http://nzbget.sourceforge.net/forum/viewtopic.php?f=3&t=740 for details of the new scripts concept.

View file

@ -1,175 +0,0 @@
#
# This file if part of nzbget
#
# Template configuration file for post-processing script "nzbget-postprocess.sh".
# Please refer to "nzbget-postprocess.sh" for usage instructions.
#
# Copyright (C) 2008-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
#
# 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
# 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
# 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
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
##############################################################################
### PATHS ###
# Set the full path to python if it is not in your PATH.
PythonCmd=/usr/local/python/bin/python
# Set the full path to nzbToSickBeard.py for SickBeard's postprocessing.
NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py
# Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing
NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py
# Set the full path to nzbToHeadPhones.py for HeadPhones's postprocessing.
NzbToHeadPhones=/usr/local/nzbget/var/nzbToHeadPhones.py
# Set the full path to nzbToMylar.py for Mylar's postprocessing.
NzbToMylar=/usr/local/nzbget/var/nzbToMylar.py
# Set the full path to nzbToGamez.py for Gamez's postprocessing.
NzbToGamez=/usr/local/nzbget/var/nzbToGamez.py
# Set the full path to any dependency required for your Custom
# Postprocess script if it is not in your PATH.
CustomCmd=/usr/local/python/bin/python
# Set the full path to the Custom Postprocess script.
CustomScript=
# Set the full path to location to move failed downloads to.
Failed_Directory=/usr/local/downloads/failed
##############################################################################
### OPTIONS ###
# Rename img-files to iso (yes, no).
RenameIMG=yes
# Joint TS-files (yes, no).
JoinTS=yes
# Perform SickBeard's postprocessing (yes, no).
SickBeard=yes
# Category for SickBeard's postprocessing.
SickBeardCategory=tv
# Perform Couchpotato's postprocessing (yes, no).
CouchPotato=yes
# Category for Couchpotato's postprocessing.
CouchPotatoCategory=movies
# Perform HeadPhones' postprocessing (yes, no).
HeadPhones=yes
# Category for HeadPhones' postprocessing.
HeadPhonesCategory=music
# Perform Mylar's postprocessing (yes, no).
Mylar=yes
# Category for Mylar's postprocessing.
MylarCategory=comics
# Perform Gamez's postprocessing (yes, no).
Gamez=yes
# Category for Gamez's postprocessing.
GamezCategory=games
# Perform Custom postprocessing (yes, no).
Custom=yes
# Category for Custom postprocessing (eg. pictures)
CustomCategory=pictures
# Clean up list. space seperated, in single quotes, default '*.nzb *.sfv *.1'
FileCleanUp='*.nzb *.sfv *.1'
# Remove all files when download fails (yes, no).
Delete_Failed=no
# Toggle detailed output (yes, no).
Debug=no
##############################################################################
### POSTPROCESSING-PARAMETERS ###
# This section defines parameters, which can be set for each nzb-file
# individually using either web-interface or command line.
# Example command line for setting parameter "PostProcess" to value "no" for
# nzb-file with id=2:
# nzbget -E G O PostProcess=no 2
# Perform postprocessing (yes, no).
#
# Set to "no" to skip postprocessing for this nzb-file.
PostProcess=yes
# Destination directory.
DestDir=
##############################################################################
### EMAIL-PARAMETERS ###
# This section defines parameters, which can be set to allow notifications to
# be sent via email.
# This uses sendEmail as authored by Brandon Zehm <caspian@dotconf.net>
# List Categories for successful download email, default 'tv movies'
Email_successful='tv movies music comics games pictures'
# List Categories for failed download email, default 'tv movies'
Email_failed='tv movies music comics games pictures'
# Set the full path and file name for sendEmail application.
sendEmail=/usr/local/nzbget/var/sendEmail/sendEmail
# Enter the email address you want this email to be sent from.
Email_From=
# Enter the email address you want this email to be sent to.
Email_To=
# Enter smtp server and port. eg smtp.live.com:25
Email_Server=
# Server uses tsl (auto, yes, no).
Tls=auto
# Enter your smtp server user name (if required)
Email_User=
# Enter your smtp server password (if required)
Email_Pass=
# Enter your email subject, in single quotes.
# Use the following tags between the less than and greater than symbols.
# Use status to add 'completed'/'failed'.
# Use name to add the nzb name.
# Use cat to add the download categoty.
# Use script to name the external script used.
Email_Subject='The download of <name> has <status>.'
# Enter your email message, in single quotes.
# Use the same substitutes as described above.
# Use <br> for new line.
Email_Message='The download of <name> has <status>. <br>This has been processed by the script <script> for category <cat>.'
# Append the potprocessing log to the email (yes, no).
Add_Log=no

View file

@ -1,441 +0,0 @@
#!/bin/sh
#
# This file if part of nzbget
#
# Example postprocessing script for NZBGet
#
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
# Copyright (C) 2008 Otmar Werner
# Copyright (C) 2008-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
#
# 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
# 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
# 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
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
####################### Usage instructions #######################
# o Script will cleanup, join ts-files and rename img-files to iso.
#
# o To use this script with nzbget set the option "PostProcess" in
# nzbget configuration file to point to this script file. E.g.:
# PostProcess=/home/user/nzbget/nzbget-postprocess.sh
#
# o The script needs a configuration file. An example configuration file
# is provided in file "nzbget-postprocess.conf". Put the configuration file
# into the directory where nzbget's configuration file (nzbget.conf) is located.
# Then edit the configuration file in any text editor to adjust the settings.
#
# o You can also edit the script's configuration via web-interface.
#
# o There are few options, which can be ajdusted for each nzb-file individually.
#
####################### End of Usage instructions #######################
# NZBGet passes following arguments to postprocess-programm as environment
# variables:
# NZBPP_DIRECTORY - path to destination dir for downloaded files;
# NZBPP_NZBNAME - user-friendly name of processed nzb-file as it is displayed
# by the program. The file path and extension are removed.
# If download was renamed, this parameter reflects the new name;
# NZBPP_NZBFILENAME - name of processed nzb-file. It includes file extension and also
# may include full path;
# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string);
# NZBPP_PARSTATUS - result of par-check:
# 0 = not checked: par-check is disabled or nzb-file does
# not contain any par-files;
# 1 = checked and failed to repair;
# 2 = checked and successfully repaired;
# 3 = checked and can be repaired but repair is disabled.
# NZBPP_UNPACKSTATUS - result of unpack:
# 0 = unpack is disabled or was skipped due to nzb-file
# properties or due to errors during par-check;
# 1 = unpack failed;
# 2 = unpack successful.
# Name of script's configuration file
SCRIPT_CONFIG_FILE="nzbget-postprocess.conf"
# Exit codes
POSTPROCESS_PARCHECK_CURRENT=91
POSTPROCESS_PARCHECK_ALL=92
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_NONE=95
# Postprocessing function for nzbToCouchPotato and nzbToSickBeard
nzbToMedia() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing external postprocessing with argument $1" | tee -a $tmplog; fi
PostProcessStatus=0
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: comparing '$NZBPP_CATEGORY' to '$CouchPotatoCategory' and '$SickBeardCategory'" | tee -a $tmplog; fi
find "$NZBPP_DIRECTORY" -type f -size -200000k -iname \*sample\* -exec rm {} \; >/dev/null 2>&1
download_id=""
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
script=$NzbToCouchPotato
if [ $NZBPR_couchpotato ]; then
download_id=$NZBPR_couchpotato
fi
# Call Couchpotato's postprocessing script
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" | tee -a $tmplog
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: CouchPotato-Script-Path=$NzbToCouchPotato" | tee -a $tmplog
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV1=$NZBPP_DIRECTORY" | tee -a $tmplog
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV2=$NZBPP_NZBFILENAME" | tee -a $tmplog
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV3=$PostProcessStatus" | tee -a $tmplog
fi
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" "$NZBPP_CATEGORY" "$download_id" | while read line ; do if [ "$line" != "" ] ; then replaceLogLine "${line}" ; fi ; done
else
if [ "$CouchPotato" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as it is disabled by user ('$CouchPotato')" | tee -a $tmplog; fi
if [ ! -e "$NzbToCouchPotato" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as the specified script ('$NzbToCouchPotato') does not exist" | tee -a $tmplog; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then
if [ "$SickBeard" = "yes" -a -e "$NzbToSickBeard" ]; then
script=$NzbToSickBeard
# Call SickBeard's postprocessing script
echo "[INFO] Post-Process: Running SickBeard's postprocessing script" | tee -a $tmplog
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: SickBeard-Script-Path=$NzbToSickBeard" | tee -a $tmplog
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV1=$NZBPP_DIRECTORY" | tee -a $tmplog
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV2=$NZBPP_NZBFILENAME" | tee -a $tmplog
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV3=$PostProcessStatus" | tee -a $tmplog
fi
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" "$NZBPP_CATEGORY" "$download_id" | while read line ; do if [ "$line" != "" ] ; then replaceLogLine "${line}" ; fi ; done
else
if [ "$SickBeard" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as it is disabled by user ('$SickBeard')" | tee -a $tmplog; fi
if [ ! -e "$NzbToSickBeard" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as the specified script ('$NzbToSickBeard') does not exist" | tee -a $tmplog; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$HeadPhonesCategory" ]; then
if [ "$HeadPhones" = "yes" -a -e "$NzbToHeadPhones" ]; then
script=$NzbToHeadPhones
# Call HeadPhones' postprocessing script
echo "[INFO] Post-Process: Running HeadPhones' postprocessing script" | tee -a $tmplog
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: HeadPhones-Script-Path=$NzbToHeadPhones" | tee -a $tmplog
echo "[DETAIL] Post-Process: HeadPhones-Script-ARGV1=$NZBPP_DIRECTORY" | tee -a $tmplog
echo "[DETAIL] Post-Process: HeadPhones-Script-ARGV2=$NZBPP_NZBFILENAME" | tee -a $tmplog
echo "[DETAIL] Post-Process: HeadPhones-Script-ARGV3=$PostProcessStatus" | tee -a $tmplog
fi
$PythonCmd $NzbToHeadPhones "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" "$NZBPP_CATEGORY" "$download_id" | while read line ; do if [ "$line" != "" ] ; then replaceLogLine "${line}" ; fi ; done
else
if [ "$HeadPhones" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run HeadPhones' postprocessing script as it is disabled by user ('$HeadPhones')" | tee -a $tmplog; fi
if [ ! -e "$NzbToHeadPhones" ]; then echo "[DETAIL] Post-Process: Ignored to run HeadPhones' postprocessing script as the specified script ('$NzbToHeadPhones') does not exist" | tee -a $tmplog; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$MylarCategory" ]; then
if [ "$Mylar" = "yes" -a -e "$NzbToMylar" ]; then
script=$NzbToMylar
# Call Mylar's postprocessing script
echo "[INFO] Post-Process: Running Mylar's postprocessing script" | tee -a $tmplog
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: Mylar-Script-Path=$NzbToMylar" | tee -a $tmplog
echo "[DETAIL] Post-Process: Mylar-Script-ARGV1=$NZBPP_DIRECTORY" | tee -a $tmplog
echo "[DETAIL] Post-Process: Mylar-Script-ARGV2=$NZBPP_NZBFILENAME" | tee -a $tmplog
echo "[DETAIL] Post-Process: Mylar-Script-ARGV3=$PostProcessStatus" | tee -a $tmplog
fi
$PythonCmd $NzbToMylar "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" "$NZBPP_CATEGORY" "$download_id" | while read line ; do if [ "$line" != "" ] ; then replaceLogLine "${line}" ; fi ; done
else
if [ "$Mylar" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run Mylar's postprocessing script as it is disabled by user ('$Mylar')" | tee -a $tmplog; fi
if [ ! -e "$NzbToMylar" ]; then echo "[DETAIL] Post-Process: Ignored to run Mylar's postprocessing script as the specified script ('$NzbToMylar') does not exist" | tee -a $tmplog; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$GamezCategory" ]; then
if [ "$Gamez" = "yes" -a -e "$NzbToGamez" ]; then
script=$NzbToGamez
# Call Gamez's postprocessing script
echo "[INFO] Post-Process: Running Gamez's postprocessing script" | tee -a $tmplog
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: Gamez-Script-Path=$NzbToGamez" | tee -a $tmplog
echo "[DETAIL] Post-Process: Gamez-Script-ARGV1=$NZBPP_DIRECTORY" | tee -a $tmplog
echo "[DETAIL] Post-Process: Gamez-Script-ARGV2=$NZBPP_NZBFILENAME" | tee -a $tmplog
echo "[DETAIL] Post-Process: Gamez-Script-ARGV3=$PostProcessStatus" | tee -a $tmplog
fi
$PythonCmd $NzbToGamez "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" "$NZBPP_CATEGORY" "$download_id" | while read line ; do if [ "$line" != "" ] ; then replaceLogLine "${line}" ; fi ; done
else
if [ "$Gamez" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run Gamez's postprocessing script as it is disabled by user ('$Gamez')" | tee -a $tmplog; fi
if [ ! -e "$NzbToGamez" ]; then echo "[DETAIL] Post-Process: Ignored to run Gamez's postprocessing script as the specified script ('$NzbToGamez') does not exist" | tee -a $tmplog; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$CustomCategory" ]; then
if [ "$Custom" = "yes" -a -e "$CustomScript" ]; then
script=$CustomScript
# Call Custom postprocessing script
echo "[INFO] Post-Process: Running the Custom postprocessing script" | tee -a $tmplog
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: Custom-Script-Path=$CustomScript" | tee -a $tmplog
echo "[DETAIL] Post-Process: Custom-Script-ARGV1=$NZBPP_DIRECTORY" | tee -a $tmplog
echo "[DETAIL] Post-Process: Custom-Script-ARGV2=$NZBPP_NZBFILENAME" | tee -a $tmplog
echo "[DETAIL] Post-Process: Custom-Script-ARGV3=$PostProcessStatus" | tee -a $tmplog
fi
$CustomCmd $CustomScript "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" "$NZBPP_CATEGORY" "$download_id" | while read line ; do if [ "$line" != "" ] ; then replaceLogLine "${line}" ; fi ; done
else
if [ "$Custom" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as it is disabled by user ('$Custom')" | tee -a $tmplog; fi
if [ ! -e "$CustomScript" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as the specified script ('$CustomScript') does not exist" | tee -a $tmplog; fi
fi
fi
}
replaceVarBy() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'replaceVarBy'. Going to replace '${2}' in '${1}' by '${3}'" | tee -a $tmplog; 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}" | tee -a $tmplog; fi
}
replaceLogLine() {
# This converts the output logigng from nzbTo* script to a compatible format with NZBGet
# 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
newline="${1/*DEBUG/[DETAIL]}"
newline="${newline/*INFO/[INFO]}"
newline="${newline/*WARNING/[WARNING]}"
newline="${newline/*ERROR/[ERROR]}"
else
newline=$(echo "${1}" | sed "s^.*DEBUG^[DETAIL]^")
newline=$(echo $newline | sed "s^.*INFO^[INFO]^")
newline=$(echo $newline | sed "s^.*WARNING^[WARNING]^")
newline=$(echo $newline | sed "s^.*ERROR^[ERROR]^")
fi
echo "$newline" | tee -a $tmplog
}
# Pass on postprocess exit codes to external scripts for handling failed downloads
do_exit() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" | tee -a $tmplog; fi
nzbStatus=0
if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then
if [ "$Delete_Failed" = "yes" -a "$NZBPP_DIRECTORY" != "$ConfigDir" -a -d "$NZBPP_DIRECTORY" -a ! -d "$NZBPP_DIRECTORY/.git" ]; then
cd ..
rm -rf $NZBPP_DIRECTORY >/dev/null 2>&1
elif [ "$NZBPP_DIRECTORY" != "$ConfigDir" -a "$Failed_Directory" != "" -a -d "$NZBPP_DIRECTORY" -a ! -d "$NZBPP_DIRECTORY/.git" ]; then
cd ..
mkdir $Failed_Directory
mkdir $Failed_Directory/$NZBPP_CATEGORY
mkdir $Failed_Directory/$NZBPP_CATEGORY/$NZBPP_NZBNAME
mv $NZBPP_DIRECTORY $Failed_Directory/$NZBPP_CATEGORY/$NZBPP_NZBNAME >/dev/null 2>&1
NZBPP_DIRECTORY=$Failed_Directory/$NZBPP_CATEGORY/$NZBPP_NZBNAME
cd $NZBPP_DIRECTORY
fi
nzbStatus=1
fi
script=none
nzbToMedia $nzbStatus
echo "[DETAIL] after calling nzbToMedia" | tee -a $tmplog
replaceVarBy "${Email_Subject}" "<name>" "${NZBPP_NZBFILENAME}"
replaceVarBy "${REPLACEDRESULT}" "<cat>" "${NZBPP_CATEGORY}"
replaceVarBy "${REPLACEDRESULT}" "<script>" "${script}"
Email_Subject="${REPLACEDRESULT}"
replaceVarBy "${Email_Message}" "<name>" "${NZBPP_NZBFILENAME}"
replaceVarBy "${REPLACEDRESULT}" "<cat>" "${NZBPP_CATEGORY}"
replaceVarBy "${REPLACEDRESULT}" "<script>" "${script}"
Email_Message="${REPLACEDRESULT}"
for item in $Email_successful; do
if [ "${NZBPP_CATEGORY}" = "$item" -o "$item" = "all" ] && [ "$nzbStatus" = 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
replaceVarBy "${Email_Subject}" "<status>" "completed"
Email_Subject="${REPLACEDRESULT}"
replaceVarBy "${Email_Message}" "<status>" "completed"
Email_Message="${REPLACEDRESULT}"
if [ "${Add_Log}" = "yes" ]; then
Email_Message="$Email_Message <br>Log Result"
while read line; do Email_Message="$Email_Message <br>$line"; done < $tmplog
fi
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" -o "tls=$Tls" -o "message-content-type=html" $User -u "$Email_Subject" -m "$Email_Message"
fi; done
for item in $Email_failed; do
if [ "${NZBPP_CATEGORY}" = "$item" -o "$item" = "all" ] && [ "$nzbStatus" != 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
replaceVarBy "${Email_Subject}" "<status>" "failed"
Email_Subject="${REPLACEDRESULT}"
replaceVarBy "${Email_Message}" "<status>" "failed"
Email_Message="${REPLACEDRESULT}"
if [ "${Add_Log}" = "yes" ]; then
Email_Message="$Email_Message <br>nLog Result"
while read line; do Email_Message="$Email_Message <br>$line"; done < $tmplog
fi
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" -o "tls=$Tls" -o "message-content-type=html" $User -u "$Email_Subject" -m "$Email_Message"
fi; done
exit $1
}
# Check if the script is called from nzbget 10.0 or later
if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then
echo "*** NZBGet post-processing script ***"
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
fi
# Check if postprocessing was disabled in postprocessing parameters
# (for current nzb-file) via web-interface or via command line with
# "nzbget -E G O PostProcess=no <ID>"
if [ "$NZBPR_PostProcess" = "no" ]; then
echo "[WARNING] Post-Process: Post-processing disabled for this nzb-file, exiting"
exit $POSTPROCESS_NONE
fi
ConfigDir="${NZBOP_CONFIGFILE%/*}"
tmplog="$ConfigDir/tmp.log"
echo "[INFO] Post-Process: Post-processing script successfully started" | tee $tmplog
cd "$NZBPP_DIRECTORY" || (echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY isn't accessible" | tee $tmplog && do_exit $POSTPROCESS_ERROR)
# Determine the location of configuration file (it must be stored in
# the directory with nzbget.conf).
ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE"
if [ ! -f "$ScriptConfigFile" ]; then
echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" | tee -a $tmplog
exit $POSTPROCESS_ERROR
fi
# Readg configuration file
while read line; do eval "$line"; done < $ScriptConfigFile
# Check nzbget.conf options
BadConfig=0
if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then
echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file" | tee -a $tmplog
BadConfig=1
fi
if [ "$NZBOP_UNPACK" != "yes" ]; then
echo "[ERROR] Post-Process: Please enable option \"Unpack\" in nzbget configuration file" | tee -a $tmplog
BadConfig=1
fi
if [ "$BadConfig" -eq 1 ]; then
echo "[ERROR] Post-Process: Exiting due to incompatible nzbget configuration" | tee -a $tmplog
exit $POSTPROCESS_ERROR
fi
# Check par status
if [ "$NZBPP_PARSTATUS" -eq 3 ]; then
echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" | tee -a $tmplog
do_exit $POSTPROCESS_NONE
fi
if [ "$NZBPP_PARSTATUS" -eq 1 ]; then
echo "[WARNING] Post-Process: Par-check failed, exiting" | tee -a $tmplog
do_exit $POSTPROCESS_NONE
fi
# Check unpack status
if [ "$NZBPP_UNPACKSTATUS" -eq 1 ]; then
echo "[WARNING] Post-Process: Unpack failed, exiting" | tee -a $tmplog
do_exit $POSTPROCESS_NONE
fi
if [ "$NZBPP_UNPACKSTATUS" -eq 0 -a "$NZBPP_PARSTATUS" -ne 2 ]; then
# Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check
if (ls *.rar *.7z *.7z.??? >/dev/null 2>&1); then
echo "[WARNING] Post-Process: Archive files exist but unpack skipped, exiting" | tee -a $tmplog
exit $POSTPROCESS_NONE
fi
if (ls *.par2 >/dev/null 2>&1); then
echo "[WARNING] Post-Process: Unpack skipped and par-check skipped (although par2-files exist), exiting" | tee -a $tmplog
exit $POSTPROCESS_NONE
fi
if [ -f "_brokenlog.txt" ]; then
echo "[WARNING] Post-Process: _brokenlog.txt exists, download is probably damaged, exiting" | tee -a $tmplog
exit $POSTPROCESS_NONE
fi
echo "[INFO] Post-Process: Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful" | tee -a $tmplog
fi
# Check if destination directory exists (important for reprocessing of history items)
if [ ! -d "$NZBPP_DIRECTORY" ]; then
echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist" | tee -a $tmplog
do_exit $POSTPROCESS_ERROR
fi
# All checks done, now processing the files
# If download contains only nzb-files move them into nzb-directory
# for further download
# Check if command "wc" exists
wc -l . >/dev/null 2>&1
if [ "$?" -ne 127 ]; then
AllFilesCount=`ls -1 2>/dev/null | wc -l`
NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l`
if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then
echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download" | tee -a $tmplog
mv *.nzb $NZBOP_NZBDIR
fi
fi
# Clean up
echo "[INFO] Post-Process: Cleaning up" | tee -a $tmplog
chmod -R a+rw .
# Clean up list, space seperated array from GUI
for word in $FileCleanUp ; do rm $word >/dev/null 2>&1 ; done
# Removed by default
rm _brokenlog.txt >/dev/null 2>&1
rm *.[pP][aA][rR]2 >/dev/null 2>&1
if [ "$JoinTS" = "yes" ]; then
# 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
if (ls *.ts >/dev/null 2>&1); then
echo "[INFO] Post-Process: Joining ts-files" | tee -a $tmplog
tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'`
cat *0???.ts > ./$tsname
# Remove all the split .ts files
echo "[INFO] Post-Process: Deleting source ts-files" | tee -a $tmplog
rm *0???.ts >/dev/null 2>&1
fi
fi
if [ "$RenameIMG" = "yes" ]; then
# Rename img file to iso
# It will be renamed to .img.iso so you can see that it has been renamed
if (ls *.img >/dev/null 2>&1); then
echo "[INFO] Post-Process: Renaming img-files to iso" | tee -a $tmplog
imgname=`find . -name "*.img" |awk -F/ '{print $NF}'`
mv $imgname $imgname.iso
fi
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
NZBPP_DIRECTORY=$NZBPR_DestDir
cd $NZBPP_DIRECTORY
fi
# All OK, requesting cleaning up of download queue
do_exit $POSTPROCESS_SUCCESS

View file

@ -1 +1 @@
Previous Stable Release: NZBGet V9.1
Current Stable Release: NZBGet V10.0

View file

@ -1,11 +1,10 @@
#
# This file if part of nzbget
#
# Template configuration file for postprocessing script "nzbget-postprocess.sh".
# Template configuration file for post-processing script "nzbget-postprocess.sh".
# Please refer to "nzbget-postprocess.sh" for usage instructions.
#
# Copyright (C) 2008-2012 Andrey Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2012 J<>rgen Seif <thor78@gmx.at>
# Copyright (C) 2008-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -26,25 +25,23 @@
##############################################################################
### PATHS ###
# Set the full path to unrar if it is not in your PATH.
UnrarCmd=unrar
# Set the full path to python if it is not in your PATH.
PythonCmd=/usr/local/python/bin/python
# Set the full path to sabToSickBeard.py for SickBeard's postprocessing.
# Set the full path to nzbToSickBeard.py for SickBeard's postprocessing.
NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py
# Set the full path where completed TV episodes should be placed
# before SickBeard's Renamer is called
TvDownloadDir=
# Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing
NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py
# Set the full path where completed movies should be placed
# before CouchPotato's Renamer is called
MoviesDownloadDir=
# Set the full path to nzbToHeadPhones.py for HeadPhones's postprocessing.
NzbToHeadPhones=/usr/local/nzbget/var/nzbToHeadPhones.py
# Set the full path to nzbToMylar.py for Mylar's postprocessing.
NzbToMylar=/usr/local/nzbget/var/nzbToMylar.py
# Set the full path to nzbToGamez.py for Gamez's postprocessing.
NzbToGamez=/usr/local/nzbget/var/nzbToGamez.py
# Set the full path to any dependency required for your Custom
# Postprocess script if it is not in your PATH.
@ -53,24 +50,17 @@ CustomCmd=/usr/local/python/bin/python
# Set the full path to the Custom Postprocess script.
CustomScript=
# Set the full path where completed downloads should be placed
# before the Custom postprocess is called
CustomDownloadDir=
# Set the full path to location to move failed downloads to.
Failed_Directory=/usr/local/downloads/failed
##############################################################################
### OPTIONS ###
# Delete rar-files after unpacking (yes, no).
DeleteRarFiles=yes
# Rename img-files to iso (yes, no).
RenameIMG=yes
# Joint TS-files (yes, no).
JoinTS=no
JoinTS=yes
# Perform SickBeard's postprocessing (yes, no).
SickBeard=yes
@ -84,11 +74,29 @@ CouchPotato=yes
# Category for Couchpotato's postprocessing.
CouchPotatoCategory=movies
# Perform HeadPhones' postprocessing (yes, no).
HeadPhones=yes
# Category for HeadPhones' postprocessing.
HeadPhonesCategory=music
# Perform Mylar's postprocessing (yes, no).
Mylar=yes
# Category for Mylar's postprocessing.
MylarCategory=comics
# Perform Gamez's postprocessing (yes, no).
Gamez=yes
# Category for Gamez's postprocessing.
GamezCategory=games
# Perform Custom postprocessing (yes, no).
Custom=yes
# Category for Custom postprocessing (eg. movies)
CustomCategory=music
# Category for Custom postprocessing (eg. pictures)
CustomCategory=pictures
# Clean up list. space seperated, in single quotes, default '*.nzb *.sfv *.1'
FileCleanUp='*.nzb *.sfv *.1'
@ -104,23 +112,16 @@ Debug=no
# This section defines parameters, which can be set for each nzb-file
# individually using either web-interface or command line.
# Example command line for setting parameter "password" to value "123" for
# Example command line for setting parameter "PostProcess" to value "no" for
# nzb-file with id=2:
# nzbget -E G O Password=123 2
# nzbget -E G O PostProcess=no 2
# Perform postprocessing (yes, no).
#
# Set to "no" to skip postprocessing for this nzb-file.
PostProcess=yes
# Password for encrypted posts.
#
# If the post requires a password for unpacking.
Password=
# Destination directory.
#
# NOTE: NZBGet must have write-access-rights for that directory.
DestDir=
##############################################################################
@ -131,10 +132,10 @@ DestDir=
# This uses sendEmail as authored by Brandon Zehm <caspian@dotconf.net>
# List Categories for successful download email, default 'tv movies'
Email_successful='tv movies'
Email_successful='tv movies music comics games pictures'
# List Categories for failed download email, default 'tv movies'
Email_failed='tv movies'
Email_failed='tv movies music comics games pictures'
# Set the full path and file name for sendEmail application.
sendEmail=/usr/local/nzbget/var/sendEmail/sendEmail

View file

@ -1,13 +1,12 @@
#!/bin/sh
# -*- coding: cp1252 -*-
#
# This file if part of nzbget
#
# Example postprocessing script for NZBGet
#
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
# Copyright (C) 2008 Otmar Werner
# Copyright (C) 2008-2012 Andrei Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
# Copyright (C) 2012 J<>rgen Seif <thor78@gmx.at>
# Copyright (C) 2008-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -21,45 +20,25 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
####################### Usage instructions #######################
# o Script will unrar downloaded rar files, join ts-files and rename img-files
# to iso.
# o Script will cleanup, join ts-files and rename img-files to iso.
#
# o To use this script with nzbget set the option "PostProcess" in
# nzbget configuration file to point to this script file. E.g.:
# PostProcess=/home/user/nzbget/nzbget-postprocess.sh
#
# o The script needs a configuration file. An example configuration file
# is provided in file "postprocess-example.conf". Put the configuration file
# into the directory where nzbget's configuration file (nzbget.conf) or where
# this script itself is located. Then edit the configuration file in any
# text editor to adjust the settings.
# is provided in file "nzbget-postprocess.conf". Put the configuration file
# into the directory where nzbget's configuration file (nzbget.conf) is located.
# Then edit the configuration file in any text editor to adjust the settings.
#
# o You can also edit the script's configuration via web-interface (requires
# NZBGetWeb 1.4 or later). Set the options "PostProcessConfigFile" and
# "PostProcessConfigTemplate" to point to "postprocess-example.conf"
# (including full path). The both options are under the section
# "CONFIGURATION OF POSTPROCESSING-SCRIPT" in NZBGetWeb.
# o You can also edit the script's configuration via web-interface.
#
# o There are few options, which can be ajdusted for each nzb-file
# individually. To view/edit them in web-interface click on a spanner icon
# near the name of nzb-file.
#
# o The script supports the feature called "delayed par-check".
# That means it can try to unpack downloaded files without par-checking
# them fisrt. Only if unpack fails, the script schedules par-check,
# then unpacks again.
# To use delayed par-check set following options in nzbget configuration file:
# ParCheck=no
# ParRepair=yes
# LoadPars=one (or) LoadPars=all
#
# o If you want to par-check/repair all files before trying to unpack them,
# set option "ParCheck=yes".
# o There are few options, which can be ajdusted for each nzb-file individually.
#
####################### End of Usage instructions #######################
@ -67,23 +46,23 @@
# NZBGet passes following arguments to postprocess-programm as environment
# variables:
# NZBPP_DIRECTORY - path to destination dir for downloaded files;
# NZBPP_NZBFILENAME - name of processed nzb-file;
# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were
# found);
# NZBPP_NZBNAME - user-friendly name of processed nzb-file as it is displayed
# by the program. The file path and extension are removed.
# If download was renamed, this parameter reflects the new name;
# NZBPP_NZBFILENAME - name of processed nzb-file. It includes file extension and also
# may include full path;
# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string);
# NZBPP_PARSTATUS - result of par-check:
# 0 = not checked: par-check disabled or nzb-file does
# 0 = not checked: par-check is disabled or nzb-file does
# not contain any par-files;
# 1 = checked and failed to repair;
# 2 = checked and successfully repaired;
# 3 = checked and can be repaired but repair is disabled;
# NZBPP_NZBCOMPLETED - state of nzb-job:
# 0 = there are more collections in this nzb-file queued;
# 1 = this was the last collection in nzb-file;
# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file:
# 0 = no failed par-jobs;
# 1 = current par-job or any of the previous par-jobs for
# the same nzb-files failed;
# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string).
# 3 = checked and can be repaired but repair is disabled.
# NZBPP_UNPACKSTATUS - result of unpack:
# 0 = unpack is disabled or was skipped due to nzb-file
# properties or due to errors during par-check;
# 1 = unpack failed;
# 2 = unpack successful.
# Name of script's configuration file
@ -141,6 +120,57 @@ nzbToMedia() {
if [ ! -e "$NzbToSickBeard" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as the specified script ('$NzbToSickBeard') does not exist" | tee -a $tmplog; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$HeadPhonesCategory" ]; then
if [ "$HeadPhones" = "yes" -a -e "$NzbToHeadPhones" ]; then
script=$NzbToHeadPhones
# Call HeadPhones' postprocessing script
echo "[INFO] Post-Process: Running HeadPhones' postprocessing script" | tee -a $tmplog
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: HeadPhones-Script-Path=$NzbToHeadPhones" | tee -a $tmplog
echo "[DETAIL] Post-Process: HeadPhones-Script-ARGV1=$NZBPP_DIRECTORY" | tee -a $tmplog
echo "[DETAIL] Post-Process: HeadPhones-Script-ARGV2=$NZBPP_NZBFILENAME" | tee -a $tmplog
echo "[DETAIL] Post-Process: HeadPhones-Script-ARGV3=$PostProcessStatus" | tee -a $tmplog
fi
$PythonCmd $NzbToHeadPhones "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" "$NZBPP_CATEGORY" "$download_id" | while read line ; do if [ "$line" != "" ] ; then replaceLogLine "${line}" ; fi ; done
else
if [ "$HeadPhones" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run HeadPhones' postprocessing script as it is disabled by user ('$HeadPhones')" | tee -a $tmplog; fi
if [ ! -e "$NzbToHeadPhones" ]; then echo "[DETAIL] Post-Process: Ignored to run HeadPhones' postprocessing script as the specified script ('$NzbToHeadPhones') does not exist" | tee -a $tmplog; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$MylarCategory" ]; then
if [ "$Mylar" = "yes" -a -e "$NzbToMylar" ]; then
script=$NzbToMylar
# Call Mylar's postprocessing script
echo "[INFO] Post-Process: Running Mylar's postprocessing script" | tee -a $tmplog
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: Mylar-Script-Path=$NzbToMylar" | tee -a $tmplog
echo "[DETAIL] Post-Process: Mylar-Script-ARGV1=$NZBPP_DIRECTORY" | tee -a $tmplog
echo "[DETAIL] Post-Process: Mylar-Script-ARGV2=$NZBPP_NZBFILENAME" | tee -a $tmplog
echo "[DETAIL] Post-Process: Mylar-Script-ARGV3=$PostProcessStatus" | tee -a $tmplog
fi
$PythonCmd $NzbToMylar "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" "$NZBPP_CATEGORY" "$download_id" | while read line ; do if [ "$line" != "" ] ; then replaceLogLine "${line}" ; fi ; done
else
if [ "$Mylar" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run Mylar's postprocessing script as it is disabled by user ('$Mylar')" | tee -a $tmplog; fi
if [ ! -e "$NzbToMylar" ]; then echo "[DETAIL] Post-Process: Ignored to run Mylar's postprocessing script as the specified script ('$NzbToMylar') does not exist" | tee -a $tmplog; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$GamezCategory" ]; then
if [ "$Gamez" = "yes" -a -e "$NzbToGamez" ]; then
script=$NzbToGamez
# Call Gamez's postprocessing script
echo "[INFO] Post-Process: Running Gamez's postprocessing script" | tee -a $tmplog
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: Gamez-Script-Path=$NzbToGamez" | tee -a $tmplog
echo "[DETAIL] Post-Process: Gamez-Script-ARGV1=$NZBPP_DIRECTORY" | tee -a $tmplog
echo "[DETAIL] Post-Process: Gamez-Script-ARGV2=$NZBPP_NZBFILENAME" | tee -a $tmplog
echo "[DETAIL] Post-Process: Gamez-Script-ARGV3=$PostProcessStatus" | tee -a $tmplog
fi
$PythonCmd $NzbToGamez "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" "$NZBPP_CATEGORY" "$download_id" | while read line ; do if [ "$line" != "" ] ; then replaceLogLine "${line}" ; fi ; done
else
if [ "$Gamez" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run Gamez's postprocessing script as it is disabled by user ('$Gamez')" | tee -a $tmplog; fi
if [ ! -e "$NzbToGamez" ]; then echo "[DETAIL] Post-Process: Ignored to run Gamez's postprocessing script as the specified script ('$NzbToGamez') does not exist" | tee -a $tmplog; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$CustomCategory" ]; then
if [ "$Custom" = "yes" -a -e "$CustomScript" ]; then
script=$CustomScript
@ -202,8 +232,9 @@ do_exit() {
cd ..
mkdir $Failed_Directory
mkdir $Failed_Directory/$NZBPP_CATEGORY
mv $NZBPP_DIRECTORY $Failed_Directory/$NZBPP_CATEGORY >/dev/null 2>&1
NZBPP_DIRECTORY=$Failed_Directory
mkdir $Failed_Directory/$NZBPP_CATEGORY/$NZBPP_NZBNAME
mv $NZBPP_DIRECTORY $Failed_Directory/$NZBPP_CATEGORY/$NZBPP_NZBNAME >/dev/null 2>&1
NZBPP_DIRECTORY=$Failed_Directory/$NZBPP_CATEGORY/$NZBPP_NZBNAME
cd $NZBPP_DIRECTORY
fi
nzbStatus=1
@ -220,7 +251,7 @@ do_exit() {
replaceVarBy "${REPLACEDRESULT}" "<script>" "${script}"
Email_Message="${REPLACEDRESULT}"
for item in $Email_successful; do
if [ "${NZBPP_CATEGORY}" = "$item" -a "$nzbStatus" = 0 ]; then
if [ "${NZBPP_CATEGORY}" = "$item" -o "$item" = "all" ] && [ "$nzbStatus" = 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
replaceVarBy "${Email_Subject}" "<status>" "completed"
@ -234,7 +265,7 @@ do_exit() {
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" -o "tls=$Tls" -o "message-content-type=html" $User -u "$Email_Subject" -m "$Email_Message"
fi; done
for item in $Email_failed; do
if [ "${NZBPP_CATEGORY}" = "$item" -a "$nzbStatus" != 0 ]; then
if [ "${NZBPP_CATEGORY}" = "$item" -o "$item" = "all" ] && [ "$nzbStatus" != 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
replaceVarBy "${Email_Subject}" "<status>" "failed"
@ -250,10 +281,14 @@ do_exit() {
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
echo "*** NZBGet post-process script ***"
echo "This script is supposed to be called from nzbget (0.7.0 or later)."
echo "*** NZBGet post-processing script ***"
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
fi
@ -261,22 +296,19 @@ fi
# (for current nzb-file) via web-interface or via command line with
# "nzbget -E G O PostProcess=no <ID>"
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
fi
ConfigDir="${NZBOP_CONFIGFILE%/*}"
tmplog="$ConfigDir/tmp.log"
echo "[INFO] Post-Process: Post-process script successfully started" | tee $tmplog
echo "[INFO] Post-Process: Post-processing script successfully started" | tee $tmplog
cd "$NZBPP_DIRECTORY" || (echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY isn't accessible" | tee $tmplog && do_exit $POSTPROCESS_ERROR)
# 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).
ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE"
if [ ! -f "$ScriptConfigFile" ]; then
ConfigDir="${0%/*}"
ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE"
fi
if [ ! -f "$ScriptConfigFile" ]; then
echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" | tee -a $tmplog
exit $POSTPROCESS_ERROR
@ -293,35 +325,50 @@ if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then
BadConfig=1
fi
if [ "$NZBOP_LOADPARS" = "none" ]; then
echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file" | tee -a $tmplog
BadConfig=1
fi
if [ "$NZBOP_PARREPAIR" = "no" ]; then
echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file" | tee -a $tmplog
if [ "$NZBOP_UNPACK" != "yes" ]; then
echo "[ERROR] Post-Process: Please enable option \"Unpack\" in nzbget configuration file" | tee -a $tmplog
BadConfig=1
fi
if [ "$BadConfig" -eq 1 ]; then
echo "[ERROR] Post-Process: Exiting because of not compatible nzbget configuration" | tee -a $tmplog
echo "[ERROR] Post-Process: Exiting due to incompatible nzbget configuration" | tee -a $tmplog
exit $POSTPROCESS_ERROR
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" | tee -a $tmplog
exit $POSTPROCESS_SUCCESS
# Check par status
if [ "$NZBPP_PARSTATUS" -eq 3 ]; then
echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" | tee -a $tmplog
do_exit $POSTPROCESS_NONE
fi
if [ "$NZBPP_PARSTATUS" -eq 1 ]; then
echo "[WARNING] Post-Process: Par-check failed, exiting" | tee -a $tmplog
do_exit $POSTPROCESS_NONE
fi
# Check par status
if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then
if [ "$NZBPP_PARSTATUS" -eq 3 ]; then
echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" | tee -a $tmplog
else
echo "[WARNING] Post-Process: Par-check failed, exiting" | tee -a $tmplog
# Check unpack status
if [ "$NZBPP_UNPACKSTATUS" -eq 1 ]; then
echo "[WARNING] Post-Process: Unpack failed, exiting" | tee -a $tmplog
do_exit $POSTPROCESS_NONE
fi
if [ "$NZBPP_UNPACKSTATUS" -eq 0 -a "$NZBPP_PARSTATUS" -ne 2 ]; then
# Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check
if (ls *.rar *.7z *.7z.??? >/dev/null 2>&1); then
echo "[WARNING] Post-Process: Archive files exist but unpack skipped, exiting" | tee -a $tmplog
exit $POSTPROCESS_NONE
fi
do_exit $POSTPROCESS_ERROR
if (ls *.par2 >/dev/null 2>&1); then
echo "[WARNING] Post-Process: Unpack skipped and par-check skipped (although par2-files exist), exiting" | tee -a $tmplog
exit $POSTPROCESS_NONE
fi
if [ -f "_brokenlog.txt" ]; then
echo "[WARNING] Post-Process: _brokenlog.txt exists, download is probably damaged, exiting" | tee -a $tmplog
exit $POSTPROCESS_NONE
fi
echo "[INFO] Post-Process: Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful" | tee -a $tmplog
fi
# Check if destination directory exists (important for reprocessing of history items)
@ -330,109 +377,8 @@ if [ ! -d "$NZBPP_DIRECTORY" ]; then
do_exit $POSTPROCESS_ERROR
fi
cd "$NZBPP_DIRECTORY" || (echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY isn't accessible" | tee $tmplog && do_exit $POSTPROCESS_ERROR)
# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged
# exiting with exiting 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" | tee -a $tmplog
exit $POSTPROCESS_PARCHECK_ALL
fi
fi
fi
# 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" | tee -a $tmplog
do_exit $POSTPROCESS_ERROR
fi
# Make a temporary directory to store the unrarred files
ExtractedDirExists=0
if [ -d extracted ]; then
ExtractedDirExists=1
else
mkdir extracted
fi
echo "[INFO] Post-Process: Unraring" | tee -a $tmplog
rarpasswordparam=""
if [ "$NZBPR_Password" != "" ]; then
rarpasswordparam="-p$NZBPR_Password"
fi
$UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./extracted/
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Unrar failed" | tee -a $tmplog
if [ "$ExtractedDirExists" -eq 0 ]; then
rm -R extracted
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" | tee -a $tmplog
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" | tee -a $tmplog
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 extracted
if (ls *.rar >/dev/null 2>&1); then
echo "[INFO] Post-Process: Unraring (second pass)" | tee -a $tmplog
$UnrarCmd x -y -p- -o+ "*.rar"
if [ "$?" -ne 0 ]; then
echo "[INFO] Post-Process: Unrar (second pass) failed" | tee -a $tmplog
do_exit $POSTPROCESS_ERROR
fi
# Delete the Rar files
if [ "$DeleteRarFiles" = "yes" ]; then
echo "[INFO] Post-Process: Deleting rar-files (second pass)" | tee -a $tmplog
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 extracted
fi
# If there were nothing to unrar and the download was not par-checked,
# we don't know if it's OK. To be sure we force par-check.
# In particular that helps with downloads containing renamed rar-files.
# The par-repair will rename files to correct names, then we can unpack.
if [ "$Unrared" -eq 0 -a "$NZBPP_PARSTATUS" -eq 0 ]; then
if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then
echo "[INFO] Post-Process: No rar-files found, requesting par-check" | tee -a $tmplog
exit $POSTPROCESS_PARCHECK_ALL
fi
fi
# If download contains only nzb-files move them into nzb-directory
# for further download
# Check if command "wc" exists
@ -453,81 +399,32 @@ chmod -R a+rw .
for word in $FileCleanUp ; do rm $word >/dev/null 2>&1 ; done
# Removed by default
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
fi
rm *.[pP][aA][rR]2 >/dev/null 2>&1
if [ "$JoinTS" = "yes" ]; then
# 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
if (ls *.ts >/dev/null 2>&1); then
echo "[INFO] Post-Process: Joining ts-files" | tee -a $tmplog
echo "[INFO] Post-Process: Joining ts-files" | tee -a $tmplog
tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'`
cat *0???.ts > ./$tsname
fi
# Remove all the split .ts files
echo "[INFO] Post-Process: Deleting source ts-files" | tee -a $tmplog
rm *0???.ts >/dev/null 2>&1
# Remove all the split .ts files
echo "[INFO] Post-Process: Deleting source ts-files" | tee -a $tmplog
rm *0???.ts >/dev/null 2>&1
fi
fi
if [ "$RenameIMG" = "yes" ]; then
# Rename img file to iso
# It will be renamed to .img.iso so you can see that it has been renamed
if (ls *.img >/dev/null 2>&1); then
echo "[INFO] Post-Process: Renaming img-files to iso" | tee -a $tmplog
echo "[INFO] Post-Process: Renaming img-files to iso" | tee -a $tmplog
imgname=`find . -name "*.img" |awk -F/ '{print $NF}'`
mv $imgname $imgname.iso
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" | tee -a $tmplog
mv $NZBPP_DIRECTORY $TvDownloadDir
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $TvDownloadDir" | tee -a $tmplog
exit $POSTPROCESS_ERROR
else
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" | tee -a $tmplog
mv $NZBPP_DIRECTORY $MoviesDownloadDir
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $MoviesDownloadDir" | tee -a $tmplog
exit $POSTPROCESS_ERROR
else
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" | tee -a $tmplog
mv $NZBPP_DIRECTORY $CustomDownloadDir
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $CustomDownloadDir" | tee -a $tmplog
exit $POSTPROCESS_ERROR
else
NZBPP_DIRECTORY=$CustomDownloadDir
cd "$NZBPP_DIRECTORY"
fi
fi
##########################
### END CUSTOMIZATIONS ###
##########################
# 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>"

View file

@ -1,4 +0,0 @@
Currently testing NZBGet V11
NZBGet V11+ calls multiple scripts directly. This current configuration is no-longer used and the entire nzbget-postprocessing-files folder will be deleted once NZBGet V11 is stable.
Please see http://nzbget.sourceforge.net/forum/viewtopic.php?f=3&t=740 for details of the new scripts concept.

View file

@ -1,18 +0,0 @@
Compile with pyinstaller using options -F -w
To compile for windows, add the following files into the same folder.
Transcoder.py
Linktastic\linktastic.py folder (not used, but imported in nzbToMediaUtil.py)
nzbToMediaUtil.py
migratecfg.py
nzbToMediaEnv.py
nzbToMediaSceneExceptions.py
Autoprocess files

View file

@ -1,106 +0,0 @@
[CouchPotato]
cpsCategory = movie
apikey = ac8a2260b147487c9c88a00fc9dde601
host = localhost
port = 5050
username = clinton
password = dlo3822
ssl = 0
web_root =
delay = 65
method = renamer
delete_failed = 0
[SickBeard]
sbCategory = TV
host = localhost
port = 8081
username =
password =
web_root =
ssl = 0
watch_dir = C:\TV\new
failed_fork = 0
delete_failed = 0
[HeadPhones]
hpCategory = music
apikey =
host = localhost
port = 8181
username =
password =
ssl = 0
web_root =
delay = 65
[Mylar]
mlCategory = comics
host = localhost
port = 8090
username =
password =
web_root =
ssl = 0
[Gamez]
gzCategory = movie
apikey =
host = localhost
port = 8085
username =
password =
ssl = 0
web_root =
[Torrent]
clientAgent = utorrent
useLink = 1
minSampleSize = 200
outputDirectory = C:\TV
categories = music_videos,pictures,software
uTorrentWEBui = http://localhost:8090/gui/
uTorrentUSR = your username
uTorrentPWD = your password
deleteOriginal = 0
[Extensions]
compressedExtensions = .zip,.rar,.7z,.gz,.bz,.tar,.arj
mediaExtensions = .mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso
metaExtensions = .nfo,.sub,.srt,.jpg,.gif
[Transcoder]
transcode = 0
duplicate = 1
ignoreExtensions = .avi
outputVideoExtension = .mp4
outputVideoCodec = libx264
outputVideoFramerate = 24
outputVideoBitrate = 800k
outputAudioCodec = libmp3lame
outputAudioBitrate = 128k
[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

View file

@ -1,23 +0,0 @@
# 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 = [%(levelname)-7.7s] %(message)s

View file

@ -1,144 +0,0 @@
#
# This file if part of nzbget
#
# Template configuration file for post-processing script "nzbget-postprocess.sh".
# Please refer to "nzbget-postprocess.sh" for usage instructions.
#
# Copyright (C) 2008-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
#
# 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
# 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
# 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
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
##############################################################################
### PATHS ###
# Set the full path to location to move failed downloads to.
Failed_Directory=/usr/local/downloads/failed
##############################################################################
### OPTIONS ###
# Rename img-files to iso (yes, no).
RenameIMG=yes
# Joint TS-files (yes, no).
JoinTS=yes
# Perform SickBeard's postprocessing (yes, no).
SickBeard=yes
# Category for SickBeard's postprocessing.
SickBeardCategory=tv
# Perform Couchpotato's postprocessing (yes, no).
CouchPotato=yes
# Category for Couchpotato's postprocessing.
CouchPotatoCategory=movies
# Perform HeadPhones' postprocessing (yes, no).
HeadPhones=yes
# Category for HeadPhones' postprocessing.
HeadPhonesCategory=music
# Perform Mylar's postprocessing (yes, no).
Mylar=yes
# Category for Mylar's postprocessing.
MylarCategory=comics
# Perform Gamez's postprocessing (yes, no).
Gamez=yes
# Category for Gamez's postprocessing.
GamezCategory=games
# Clean up list. space seperated, in single quotes, default '.nzb .sfv .1'
FileCleanUp='.nzb .sfv .1'
# Remove all files when download fails (yes, no).
Delete_Failed=no
# Toggle detailed output (yes, no).
Debug=no
##############################################################################
### POSTPROCESSING-PARAMETERS ###
# This section defines parameters, which can be set for each nzb-file
# individually using either web-interface or command line.
# Example command line for setting parameter "PostProcess" to value "no" for
# nzb-file with id=2:
# nzbget -E G O PostProcess=no 2
# Perform postprocessing (yes, no).
#
# Set to "no" to skip postprocessing for this nzb-file.
PostProcess=yes
# Destination directory.
DestDir=
##############################################################################
### EMAIL-PARAMETERS ###
# This section defines parameters, which can be set to allow notifications to
# be sent via email.
# This uses sendEmail as authored by Brandon Zehm <caspian@dotconf.net>
# List Categories for successful download email, default 'tv movies'
Email_successful='tv movies music comics games pictures'
# List Categories for failed download email, default 'tv movies'
Email_failed='tv movies music comics games pictures'
# Set the full path and file name for sendEmail application.
sendEmail=/usr/local/nzbget/var/sendEmail/sendEmail
# Enter the email address you want this email to be sent from.
Email_From=
# Enter the email address you want this email to be sent to.
Email_To=
# Enter smtp server and port. eg smtp.live.com:25
Email_Server=
# Server uses tsl (auto, yes, no).
Tls=auto
# Enter your smtp server user name (if required)
Email_User=
# Enter your smtp server password (if required)
Email_Pass=
# Enter your email subject, in single quotes.
# Use the following tags between the less than and greater than symbols.
# Use status to add 'completed'/'failed'.
# Use name to add the nzb name.
# Use cat to add the download categoty.
# Use script to name the external script used.
Email_Subject='The download of <name> has <status>.'
# Enter your email message, in single quotes.
# Use the same substitutes as described above.
# Use \r\n for new line.
Email_Message='The download of <name> has <status>. \r\n This has been processed by the script <script> for category <cat>.'
# Append the potprocessing log to the email (yes, no).
Add_Log=no

View file

@ -1,494 +0,0 @@
#!/usr/bin/env python
#
# This file if part of nzbget
#
# Example postprocessing script for NZBGet
#
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
# Copyright (C) 2008 Otmar Werner
# Copyright (C) 2008-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
#
# 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
# 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
# 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
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
####################### Usage instructions #######################
# o Script will cleanup, join ts-files and rename img-files to iso.
#
# o To use this script with nzbget set the option "PostProcess" in
# nzbget configuration file to point to this script file. E.g.:
# PostProcess=/home/user/nzbget/nzbget-postprocess.sh
#
# o The script needs a configuration file. An example configuration file
# is provided in file "nzbget-postprocess.conf". Put the configuration file
# into the directory where nzbget's configuration file (nzbget.conf) is located.
# Then edit the configuration file in any text editor to adjust the settings.
#
# o You can also edit the script's configuration via web-interface.
#
# o There are few options, which can be ajdusted for each nzb-file individually.
#
####################### End of Usage instructions #######################
import os
import logging
import logging.config
import sys
import shutil
from configobj import ConfigObj
from subprocess import call
from glob import iglob
import migratecfg
import autoProcessComics
import autoProcessGames
import autoProcessMusic
import autoProcessTV
import autoProcessMovie
# Postprocessing function for nzbToCouchPotato and nzbToSickBeard
def nzbToMedia(nzbStatus):
script = ""
result = ""
if Debug == "yes":
Logger.debug("Post-Process: Executing external postprocessing with argument %s", nzbStatus)
PostProcessStatus = nzbStatus
# 200 MB in bytes
SIZE_CUTOFF = 200 * 1024 * 1024
# Ignore 'sample' in files unless 'sample' in Torrent Name
for dirpath, dirnames, filenames in os.walk(NZBPP_DIRECTORY):
for file in filenames:
filePath = os.path.join(dirpath, file)
if ('sample' in filePath.lower()) and (not 'sample' in NZBPP_NZBNAME) and (os.path.getsize(filePath) < SIZE_CUTOFF):
Logger.info("Post-Process: Deleting sample file %s", filePath)
os.unlink(filePath)
if NZBPP_CATEGORY == CouchPotatoCategory:
if CouchPotato == "yes":
script = "autoProcessMovie"
# Call Couchpotato's postprocessing script
Logger.info("Post-Process: Running CouchPotato's postprocessing script")
if Debug == "yes":
Logger.debug("Post-Process: CouchPotato-Script-ARGV1= %s", NZBPP_DIRECTORY)
Logger.debug("Post-Process: CouchPotato-Script-ARGV2= %s", NZBPP_NZBFILENAME)
Logger.debug("Post-Process: CouchPotato-Script-ARGV3= %s", PostProcessStatus)
result = autoProcessMovie.process(NZBPP_DIRECTORY, NZBPP_NZBFILENAME, PostProcessStatus, clientAgent, download_id)
else:
Logger.debug("Post-Process: Ignored to run CouchPotato's postprocessing script as it is disabled by user")
if NZBPP_CATEGORY == SickBeardCategory:
if SickBeard == "yes":
script = "autoProcessTv"
# Call SickBeard's postprocessing script
Logger.info("Post-Process: Running SickBeard's postprocessing script")
if Debug == "yes":
Logger.debug("Post-Process: SickBeard-Script-ARGV1= %s", NZBPP_DIRECTORY)
Logger.debug("Post-Process: SickBeard-Script-ARGV2= %s", NZBPP_NZBFILENAME)
Logger.debug("Post-Process: SickBeard-Script-ARGV3= %s", PostProcessStatus)
result = autoProcessTV.processEpisode(NZBPP_DIRECTORY, NZBPP_NZBFILENAME, PostProcessStatus)
else:
Logger.debug("Post-Process: Ignored to run SickBeard's postprocessing script as it is disabled by user")
if NZBPP_CATEGORY == HeadPhonesCategory:
if HeadPhones == "yes":
script = "autoProcessMusic"
# Call HeadPhones' postprocessing script
Logger.info("Post-Process: Running HeadPhones' postprocessing script")
if Debug == "yes":
Logger.debug("Post-Process: HeadPhones-Script-ARGV1= %s", NZBPP_DIRECTORY)
Logger.debug("Post-Process: HeadPhones-Script-ARGV2= %s", NZBPP_NZBFILENAME)
Logger.debug("Post-Process: HeadPhones-Script-ARGV3= %s", PostProcessStatus)
result = autoProcessMusic.process(NZBPP_DIRECTORY, NZBPP_NZBFILENAME, PostProcessStatus)
else:
Logger.debug("Post-Process: Ignored to run HeadPhones' postprocessing script as it is disabled by user")
if NZBPP_CATEGORY == MylarCategory:
if Mylar == "yes":
script = "autoProcessComics"
# Call Mylar's postprocessing script
Logger.info("Post-Process: Running Mylar's postprocessing script")
if Debug == "yes":
Logger.debug("Post-Process: Mylar-Script-ARGV1= %s", NZBPP_DIRECTORY)
Logger.debug("Post-Process: Mylar-Script-ARGV2= %s", NZBPP_NZBFILENAME)
Logger.debug("Post-Process: Mylar-Script-ARGV3= %s", PostProcessStatus)
result = autoProcessComics.processEpisode(NZBPP_DIRECTORY, NZBPP_NZBFILENAME, PostProcessStatus)
else:
Logger.debug("Post-Process: Ignored to run Mylar's postprocessing script as it is disabled by user")
if NZBPP_CATEGORY == GamezCategory:
if Gamez == "yes":
script = "autoProcessGames"
# Call Gamez's postprocessing script
Logger.info("Post-Process: Running Gamez's postprocessing script")
if Debug == "yes":
Logger.debug("Post-Process: Gamez-Script-ARGV1= %s", NZBPP_DIRECTORY)
Logger.debug("Post-Process: Gamez-Script-ARGV2= %s", NZBPP_NZBFILENAME)
Logger.debug("Post-Process: Gamez-Script-ARGV3= %s", PostProcessStatus)
result = autoProcessGames.process(NZBPP_DIRECTORY, NZBPP_NZBFILENAME, PostProcessStatus)
else:
Logger.debug("Post-Process: Ignored to run Gamez's postprocessing script as it is disabled by user")
return script, result
# Pass on postprocess exit codes to external scripts for handling failed downloads
def do_exit(Process_Code):
if Debug == "yes":
Logger.debug("Post-Process: Executing function 'do_exit' with argument %s", Process_Code)
nzbStatus = 0
if Process_Code != POSTPROCESS_SUCCESS:
if Delete_Failed == "yes":
os.chdir(os.path.split(NZBPP_DIRECTORY)[0])
shutil.rmtree(NZBPP_DIRECTORY)
else:
os.mkdir(Failed_Directory)
os.chdir(Failed_Directory)
for dirpath, dirnames, filenames in os.walk(NZBPP_DIRECTORY):
for file in filenames:
filePath = os.path.join(dirpath, file)
newPath = os.path,join(Failed_Directory, file)
shutil.move(filePath, newPath)
shutil.rmtree(NZBPP_DIRECTORY)
NZBPP_DIRECTORY = Failed_Directory
os.chdir(NZBPP_DIRECTORY)
nzbStatus=1
script = "none"
Email_Message2 = Email_Message
script, result = nzbToMedia(nzbStatus)
Logger.debug("after calling nzbToMedia")
Email_Subject.replace("<name>", NZBPP_NZBFILENAME)
Email_Subject.replace("<cat>", NZBPP_CATEGORY)
Email_Subject.replace("<script>", script)
Email_Message2.replace("<name>", NZBPP_NZBFILENAME)
Email_Message2.replace("<cat>", NZBPP_CATEGORY)
Email_Message2.replace("<script>", script)
if NZBPP_CATEGORY in Email_successful and nzbStatus == 0:
Email_Subject.replace("<status>", "completed")
Email_Message2.replace("<status>", "completed")
if Add_Log == "yes":
Email_Message2 = Email_Message2 + "\r\nLog Result"
f = open(logFile2)
lines = f.readlines()
for line in lines:
if line != "":
Email_Message2 = Email_Message2 + "\r\n" + line
f.close()
command = [sendEmail, "-f", Email_From, "-t", Email_To, "-s", Email_Server, "-o", "tls=" + Tls]
if Email_User != "" and Email_Pass != "":
command.append("-xu")
command.append(Email_User)
command.append("-xp")
command.append(Email_Pass)
command.append("-u")
command.append(Email_Subject)
command.append("-m")
command.append(Email_Message2)
call(command)
if NZBPP_CATEGORY in Email_failed and nzbStatus != 0:
Email_Subject.replace("<status>", "failed")
Email_Message.replace("<status>", "failed")
if Add_Log == "yes":
Email_Message2 = Email_Message2 + "\r\nLog Result"
f = open(logFile2)
lines = f.readlines()
for line in lines:
if line != "":
Email_Message2 = Email_Message2 + "\r\n" + line
f.close()
command = [sendEmail, "-f", Email_From, "-t", Email_To, "-s", Email_Server, "-o", "tls=" + Tls]
if Email_User != "" and Email_Pass != "":
command.append("-xu")
command.append(Email_User)
command.append("-xp")
command.append(Email_Pass)
command.append("-u")
command.append(Email_Subject)
command.append("-m")
command.append(Email_Message2)
call(command)
exit(Process_Code)
if os.path.isfile(os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg.sample")):
migratecfg.migrate()
logFile = os.path.join(os.path.dirname(sys.argv[0]), "postprocess.log")
logging.config.fileConfig(os.path.join(os.path.dirname(sys.argv[0]), "logging.cfg"))
fileHandler = logging.handlers.RotatingFileHandler(logFile, mode='a', maxBytes=20000, backupCount=1, encoding='utf-8', delay=True)
fileHandler.formatter = logging.Formatter('%(asctime)s|%(levelname)-7.7s %(message)s', '%H:%M:%S')
fileHandler.level = logging.DEBUG
logging.getLogger().addHandler(fileHandler)
logFile2 = os.path.join(os.path.dirname(sys.argv[0]), "tmp.log")
fileHandler2 = logging.FileHandler(logFile2, mode='w', encoding='utf-8', delay=True)
fileHandler2.formatter = logging.Formatter('%(asctime)s|%(levelname)-7.7s %(message)s', '%H:%M:%S')
fileHandler2.level = logging.DEBUG
logging.getLogger().addHandler(fileHandler2)
Logger = logging.getLogger(__name__)
# NZBGet passes following arguments to postprocess-programm as environment
# variables:
# NZBPP_DIRECTORY - path to destination dir for downloaded files;
NZBPP_DIRECTORY = os.path.normpath(os.getenv('NZBPP_DIRECTORY'))
# NZBPP_NZBNAME - user-friendly name of processed nzb-file as it is displayed
# by the program. The file path and extension are removed.
# If download was renamed, this parameter reflects the new name;
NZBPP_NZBNAME = os.getenv('NZBPP_NZBNAME')
# NZBPP_NZBFILENAME - name of processed nzb-file. It includes file extension and also
# may include full path;
NZBPP_NZBFILENAME = os.getenv('NZBPP_NZBFILENAME')
# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string);
NZBPP_CATEGORY = os.getenv('NZBPP_CATEGORY')
# NZBPP_PARSTATUS - result of par-check:
# 0 = not checked: par-check is disabled or nzb-file does
# not contain any par-files;
# 1 = checked and failed to repair;
# 2 = checked and successfully repaired;
# 3 = checked and can be repaired but repair is disabled.
NZBPP_PARSTATUS = os.getenv('NZBPP_PARSTATUS')
# NZBPP_UNPACKSTATUS - result of unpack:
# 0 = unpack is disabled or was skipped due to nzb-file
# properties or due to errors during par-check;
# 1 = unpack failed;
# 2 = unpack successful.
NZBPP_UNPACKSTATUS = os.getenv('NZBPP_UNPACKSTATUS')
NZBOP_CONFIGFILE = os.getenv('NZBOP_CONFIGFILE')
NZBOP_UNPACK = os.getenv('NZBOP_UNPACK')
NZBPR_PostProcess = os.getenv('NZBPR_PostProcess')
NZBPR_DestDir = os.getenv('NZBPR_DestDir')
NZBOP_ALLOWREPROCESS = os.getenv('NZBOP_ALLOWREPROCESS')
clientAgent = "nzbget"
try:
download_id = os.getenv('NZBPR_couchpotato')
except:
download_id = ""
# Name of script's configuration file
SCRIPT_CONFIG_FILE = "nzbget-postprocess.conf"
# Exit codes
POSTPROCESS_PARCHECK_CURRENT=91
POSTPROCESS_PARCHECK_ALL=92
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_NONE=95
# Check if the script is called from nzbget 10.0 or later
if NZBPP_DIRECTORY == "" or NZBOP_CONFIGFILE == "":
Logger.info("*** NZBGet post-processing script ***")
Logger.warning("This script is supposed to be called from nzbget (10.0 or later).")
exit(POSTPROCESS_ERROR)
if NZBOP_UNPACK == "":
Logger.error("This script requires nzbget version at least 10.0-testing-r555 or 10.0-stable.")
exit(POSTPROCESS_ERROR)
# Check if postprocessing was disabled in postprocessing parameters
# (for current nzb-file) via web-interface or via command line with
# "nzbget -E G O PostProcess=no <ID>"
if NZBPR_PostProcess == "no":
Logger.warning("Post-Process: Post-processing disabled for this nzb-file, exiting")
exit(POSTPROCESS_NONE)
Logger.info("Post-Process: Post-processing script successfully started")
#os.chdir(NZBPP_DIRECTORY)
# Determine the location of configuration file (it must be stored in
# the directory with nzbget.conf).
ConfigDir = os.path.dirname(NZBOP_CONFIGFILE)
ScriptConfigFile = os.path.join(ConfigDir, SCRIPT_CONFIG_FILE)
if not os.path.isfile(ScriptConfigFile):
Logger.error("Post-Process: Configuration file %s not found, exiting", ScriptConfigFile)
exit(POSTPROCESS_ERROR)
# Readg configuration file
config = ConfigObj(ScriptConfigFile)
Failed_Directory = config['Failed_Directory']
RenameIMG = config['RenameIMG']
JoinTS = config['JoinTS']
SickBeard = config['SickBeard']
SickBeardCategory = config['SickBeardCategory']
CouchPotato = config['CouchPotato']
CouchPotatoCategory = config['CouchPotatoCategory']
HeadPhones = config['HeadPhones']
HeadPhonesCategory = config['HeadPhonesCategory']
Mylar = config['Mylar']
MylarCategory = config['MylarCategory']
Gamez = config['Gamez']
GamezCategory = config['GamezCategory']
FileCleanUp = (config['FileCleanUp']).split(' ')
Delete_Failed = config['Delete_Failed']
Debug = config['Debug']
PostProcess = config['PostProcess']
DestDir = config['DestDir']
Email_successful = (config['Email_successful']).split(' ')
Email_failed = (config['Email_failed']).split(' ')
sendEmail = config['sendEmail']
Email_From = config['Email_From']
Email_To = config['Email_To']
Email_Server = config['Email_Server']
Tsl = config['Tsl']
Email_User = config['Email_User']
Email_Pass = config['Email_Pass']
Email_Subject = config['Email_Subject']
Email_Message = config['Email_Message']
Add_Log = config['Add_Log']
# Check nzbget.conf options
BadConfig = 0
if NZBOP_ALLOWREPROCESS == "yes":
Logger.error("Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file")
BadConfig = 1
if NZBOP_UNPACK != "yes":
Logger.error("Post-Process: Please enable option \"Unpack\" in nzbget configuration file")
BadConfig = 1
if BadConfig == 1:
Logger.error("Post-Process: Exiting due to incompatible nzbget configuration")
exit(POSTPROCESS_ERROR)
# Check par status
if NZBPP_PARSTATUS == 3:
Logger.warning("Post-Process: Par-check successful, but Par-repair disabled, exiting")
do_exit(POSTPROCESS_NONE)
if NZBPP_PARSTATUS == 1:
Logger.warning("Post-Process: Par-check failed, exiting")
do_exit(POSTPROCESS_NONE)
# Check unpack status
if NZBPP_UNPACKSTATUS == 1:
Logger.warning("Post-Process: Unpack failed, exiting")
do_exit(POSTPROCESS_NONE)
if NZBPP_UNPACKSTATUS == 0 and NZBPP_PARSTATUS != 2:
# Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check
for dirpath, dirnames, filenames in os.walk(NZBPP_DIRECTORY):
for file in filenames:
fileExtension = os.path.splitext(file)[1]
if fileExtension in ['.rar', '.7z', '.7z']:
Logger.warning("Post-Process: Archive files exist but unpack skipped, exiting")
exit(POSTPROCESS_NONE)
if fileExtension in ['.par2']:
Logger.warning("Post-Process: Unpack skipped and par-check skipped (although par2-files exist), exiting")
exit(POSTPROCESS_NONE)
if os.path.isfile(os.path.join(NZBPP_DIRECTORY, "_brokenlog.txt")):
Logger.warning("Post-Process: _brokenlog.txt exists, download is probably damaged, exiting")
exit(POSTPROCESS_NONE)
Logger.info("Post-Process: Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful")
# Check if destination directory exists (important for reprocessing of history items)
if not os.path.isdir(NZBPP_DIRECTORY):
Logger.error("Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist")
do_exit(POSTPROCESS_ERROR)
# All checks done, now processing the files
# If download contains only nzb-files move them into nzb-directory
# for further download
AllFilesCount = 0
NZBFilesCount = 0
for dirpath, dirnames, filenames in os.walk(NZBPP_DIRECTORY):
for file in filenames:
fileExtension = os.path.splitext(file)[1]
AllFilesCount = AllFilesCount + 1
if fileExtension in ['.nzb']:
NZBFilesCount = NZBFilesCount + 1
if AllFilesCount == NZBFilesCount:
Logger.info("Moving downloaded nzb-files into incoming nzb-directory for further download")
for dirpath, dirnames, filenames in os.walk(NZBPP_DIRECTORY):
for file in filenames:
filePath = os.path.join(dirpath, file)
shutil.move(filepath, os.path.join(NZBOP_NZBDIR, file))
# Clean up
Logger.info("Post-Process: Cleaning up")
#call(['chmod', '-R', 'a+w', NZBPP_DIRECTORY])
# Clean up list, space seperated array from GUI
for dirpath, dirnames, filenames in os.walk(NZBPP_DIRECTORY):
for file in filenames:
filePath = os.path.join(dirpath, file)
fileExtension = os.path.splitext(file)[1]
if fileExtension in FileCleanUp or fileExtension in ['.par']:
os.unlink(filePath)
if JoinTS == "yes":
# 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.ts
outputname = ""
for filename in iglob(os.path.join(NZBPP_DIRECTORY, '*.ts')):
file, ext = os.path.splitext(filename) # split off the .ts
file2, ext2 = os.path.splitext(file) # split off the .0001
outputname = file2 + ext
break
if outputname != "":
Logger.info("Post-Process: Joining ts-files")
destination = open('outputname', 'wb')
for filename in iglob(os.path.join(NZBPP_DIRECTORY, '*.ts')):
shutil.copyfileobj(open(filename, 'rb'), destination)
destination.close()
Logger.info("Post-Process: Deleting source ts-files")
for filename in iglob(os.path.join(NZBPP_DIRECTORY, '*.ts')):
if filename != outputname:
os.unlink(filename)
if RenameIMG == "yes":
# Rename img file to iso
# It will be renamed to .img.iso so you can see that it has been renamed
for dirpath, dirnames, filenames in os.walk(NZBPP_DIRECTORY):
for file in filenames:
filePath = os.path.join(dirpath, file)
fileExtension = os.path.splitext(file)[1]
if fileExtension in ['.img']:
Logger.info("Post-Process: Renaming img-files to iso")
newPath = os.path.join(dirpath, file + ".iso")
shutil.move(filePath, newPath)
# 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 not (NZBPR_DestDir == None or NZBPR_DestDir == ""):
Logger.info("Post-Process: moving files to %s", NZBPR_DestDir)
os.mkdir(NZBPR_DestDir)
for dirpath, dirnames, filenames in os.walk(NZBPP_DIRECTORY):
for file in filenames:
filePath = os.path.join(dirpath, file)
newPath = os.path,join(NZBPR_DestDir, file)
shutil.move(filePath, newPath)
os.chdir(NZBPR_DestDir)
shutil.rmtree(NZBPP_DIRECTORY)
NZBPP_DIRECTORY = NZBPR_DestDir
os.chdir(NZBPP_DIRECTORY)
# All OK, requesting cleaning up of download queue
do_exit(POSTPROCESS_SUCCESS)