mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 05:43:16 -07:00
Call common do_exit and nzbToMedia
Template supplied by thorli
This commit is contained in:
parent
7ab69f7789
commit
60e5c3eaba
1 changed files with 69 additions and 49 deletions
|
@ -1,13 +1,13 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
# -*- coding: cp1252 -*-
|
||||||
# This file if part of nzbget
|
|
||||||
#
|
#
|
||||||
# Example postprocessing script for NZBGet
|
# Example postprocessing script for NZBGet
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
|
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
|
||||||
# Copyright (C) 2008 Otmar Werner
|
# Copyright (C) 2008 Otmar Werner
|
||||||
# Copyright (C) 2008-2012 Andrey Prygunkov <hugbug@users.sourceforge.net>
|
# Copyright (C) 2008-2012 Andrei Prygunkov <hugbug@users.sourceforge.net>
|
||||||
# Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
|
# Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
|
||||||
|
# Copyright (C) 2012 J<>rgen Seif <thor78@gmx.at>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
#
|
#
|
||||||
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -85,6 +85,8 @@
|
||||||
# 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).
|
||||||
|
|
||||||
|
# Toggle detailed output (0/1)
|
||||||
|
DEBUG=1
|
||||||
|
|
||||||
# Name of script's configuration file
|
# Name of script's configuration file
|
||||||
SCRIPT_CONFIG_FILE="nzbget-postprocess.conf"
|
SCRIPT_CONFIG_FILE="nzbget-postprocess.conf"
|
||||||
|
@ -96,6 +98,54 @@ POSTPROCESS_SUCCESS=93
|
||||||
POSTPROCESS_ERROR=94
|
POSTPROCESS_ERROR=94
|
||||||
POSTPROCESS_NONE=95
|
POSTPROCESS_NONE=95
|
||||||
|
|
||||||
|
# Postprocessing function for nzbToCouchPotato for handling failed downloads
|
||||||
|
nzbToMedia() {
|
||||||
|
if [ "$DEBUG" ]; then echo "[DETAIL] Post-Process: Executing external postprocessing with argument $1" ; fi
|
||||||
|
PostProcessStatus=0
|
||||||
|
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
|
||||||
|
if ["$NZBPP_CATEGORY" = "$CouchPotatoCategory"]; then
|
||||||
|
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
|
||||||
|
# Call Couchpotato's postprocessing script
|
||||||
|
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script"
|
||||||
|
if [ "$DEBUG" ]; then
|
||||||
|
echo "[DETAIL] Post-Process: CouchPotato-Script-Path=$NzbToCouchPotato"
|
||||||
|
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV1=$NZBPP_DIRECTORY"
|
||||||
|
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV2=$NZBPP_NZBFILENAME"
|
||||||
|
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV3=$PostProcessStatus"
|
||||||
|
fi
|
||||||
|
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus"
|
||||||
|
else
|
||||||
|
if [ "$CouchPotato" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as it is disabled by user ('$CouchPotato')"; fi
|
||||||
|
if [ -e "$NzbToCouchPotato" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as the specified script ('$NzbToCouchPotato') does not exist"; fi
|
||||||
|
fi
|
||||||
|
if ["$NZBPP_CATEGORY" = "$SickBeardCategory"]; then
|
||||||
|
if [ "$SickBeard" = "yes" -a -e "$NzbToSickBeard" ]; then
|
||||||
|
# Call SickBeard's postprocessing script
|
||||||
|
echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
|
||||||
|
if [ "$DEBUG" ]; then
|
||||||
|
echo "[DETAIL] Post-Process: SickBeard-Script-Path=$NzbToSickBeard"
|
||||||
|
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV1=$NZBPP_DIRECTORY"
|
||||||
|
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV2=$NZBPP_NZBFILENAME"
|
||||||
|
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV3=$PostProcessStatus"
|
||||||
|
fi
|
||||||
|
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus"
|
||||||
|
else
|
||||||
|
if [ "$SickBeard" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as it is disabled by user ('$SickBeard')"; fi
|
||||||
|
if [ -e "$NzbToSickBeard" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as the specified script ('$NzbToSickBeard') does not exist"; fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pass on postprocess exit codes to external scripts for handling failed downloads
|
||||||
|
do_exit() {
|
||||||
|
if [ "$DEBUG" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" ; fi
|
||||||
|
nzbStatus=0
|
||||||
|
if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then nzbStatus=1 ; fi
|
||||||
|
nzbToMedia $nzbStatus
|
||||||
|
exit $1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 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 ***"
|
||||||
|
@ -123,7 +173,7 @@ if [ ! -f "$ScriptConfigFile" ]; then
|
||||||
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
|
do_exit $POSTPROCESS_ERROR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Readg configuration file
|
# Readg configuration file
|
||||||
|
@ -149,13 +199,13 @@ fi
|
||||||
|
|
||||||
if [ "$BadConfig" -eq 1 ]; then
|
if [ "$BadConfig" -eq 1 ]; then
|
||||||
echo "[ERROR] Post-Process: Exiting because of not compatible nzbget configuration"
|
echo "[ERROR] Post-Process: Exiting because of not compatible nzbget configuration"
|
||||||
exit $POSTPROCESS_ERROR
|
do_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
|
do_exit $POSTPROCESS_SUCCESS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check par status
|
# Check par status
|
||||||
|
@ -164,25 +214,14 @@ if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED"
|
||||||
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"
|
||||||
# Send notifications to SickBeard or CouchPotato that Par-check failed
|
|
||||||
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 to notify Par-check failed"
|
|
||||||
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "1" >/dev/null 2>&1
|
|
||||||
fi
|
fi
|
||||||
if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then
|
do_exit $POSTPROCESS_ERROR
|
||||||
# Call CouchPotato's postprocessing script
|
|
||||||
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script to notify Par-check failed"
|
|
||||||
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "1" >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
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
|
do_exit $POSTPROCESS_ERROR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$NZBPP_DIRECTORY"
|
cd "$NZBPP_DIRECTORY"
|
||||||
|
@ -193,7 +232,7 @@ 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
|
do_exit $POSTPROCESS_PARCHECK_ALL
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -210,7 +249,7 @@ if (ls *.rar >/dev/null 2>&1); then
|
||||||
$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
|
do_exit $POSTPROCESS_ERROR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make a temporary directory to store the unrarred files
|
# Make a temporary directory to store the unrarred files
|
||||||
|
@ -236,20 +275,9 @@ if (ls *.rar >/dev/null 2>&1); then
|
||||||
# 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
|
do_exit $POSTPROCESS_PARCHECK_ALL
|
||||||
# Send notifications to SickBeard or CouchPotato that unrar (second pass) failed
|
|
||||||
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 to notify unrar (second pass) failed"
|
|
||||||
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "1">/dev/null 2>&1
|
|
||||||
fi
|
fi
|
||||||
if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then
|
do_exit $POSTPROCESS_ERROR
|
||||||
# Call CouchPotato's postprocessing script
|
|
||||||
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script to notify unrar (second pass) failed"
|
|
||||||
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "1">/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
exit $POSTPROCESS_ERROR
|
|
||||||
fi
|
fi
|
||||||
Unrared=1
|
Unrared=1
|
||||||
|
|
||||||
|
@ -270,7 +298,7 @@ if (ls *.rar >/dev/null 2>&1); then
|
||||||
|
|
||||||
if [ "$?" -ne 0 ]; then
|
if [ "$?" -ne 0 ]; then
|
||||||
echo "[INFO] Post-Process: Unrar (second pass) failed"
|
echo "[INFO] Post-Process: Unrar (second pass) failed"
|
||||||
exit $POSTPROCESS_ERROR
|
do_exit $POSTPROCESS_ERROR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Delete the Rar files
|
# Delete the Rar files
|
||||||
|
@ -354,6 +382,7 @@ if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -d "$TvDownloadDir" ]; then
|
||||||
cd ..
|
cd ..
|
||||||
rmdir "$NZBPP_DIRECTORY"
|
rmdir "$NZBPP_DIRECTORY"
|
||||||
NZBPP_DIRECTORY="$TvDownloadDir"
|
NZBPP_DIRECTORY="$TvDownloadDir"
|
||||||
|
cd "$NZBPP_DIRECTORY"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# Test for category and ensure the passed directory exists as a directory.
|
# Test for category and ensure the passed directory exists as a directory.
|
||||||
|
@ -368,6 +397,7 @@ if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -d "$MoviesDownloadDir" ]; th
|
||||||
cd ..
|
cd ..
|
||||||
rmdir "$NZBPP_DIRECTORY"
|
rmdir "$NZBPP_DIRECTORY"
|
||||||
NZBPP_DIRECTORY="$MoviesDownloadDir"
|
NZBPP_DIRECTORY="$MoviesDownloadDir"
|
||||||
|
cd "$NZBPP_DIRECTORY"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -375,18 +405,6 @@ fi
|
||||||
### END CUSTOMIZATIONS ###
|
### 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" "0" >/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" "0" >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if destination directory was set in postprocessing parameters
|
# Check if destination directory was set in postprocessing parameters
|
||||||
# (for current nzb-file) via web-interface or via command line with
|
# (for current nzb-file) via web-interface or via command line with
|
||||||
# "nzbget -E G O DestDir=/new/path <ID>"
|
# "nzbget -E G O DestDir=/new/path <ID>"
|
||||||
|
@ -395,7 +413,9 @@ if [ "$NZBPR_DestDir" != "" ]; then
|
||||||
mv * $NZBPR_DestDir >/dev/null 2>&1
|
mv * $NZBPR_DestDir >/dev/null 2>&1
|
||||||
cd ..
|
cd ..
|
||||||
rmdir $NZBPP_DIRECTORY
|
rmdir $NZBPP_DIRECTORY
|
||||||
|
NZBPP_DIRECTORY=$NZBPR_DestDir
|
||||||
|
cd "$NZBPP_DIRECTORY"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# All OK, requesting cleaning up of download queue
|
# All OK, requesting cleaning up of download queue
|
||||||
exit $POSTPROCESS_SUCCESS
|
do_exit $POSTPROCESS_SUCCESS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue