mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 05:43:16 -07:00
Call common do_exit and nzbToMedia
same as 9.0
This commit is contained in:
parent
234df888ef
commit
8f2a43d803
1 changed files with 65 additions and 47 deletions
|
@ -1,13 +1,13 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# This file if part of nzbget
|
||||
# -*- coding: cp1252 -*-
|
||||
#
|
||||
# Example postprocessing script for NZBGet
|
||||
#
|
||||
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
|
||||
# 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 J<>rgen Seif <thor78@gmx.at>
|
||||
#
|
||||
# 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,7 +21,7 @@
|
|||
#
|
||||
# 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.
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
#
|
||||
|
||||
|
@ -85,6 +85,8 @@
|
|||
# the same nzb-files failed;
|
||||
# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string).
|
||||
|
||||
# Toggle detailed output (0/1)
|
||||
DEBUG=1
|
||||
|
||||
# Name of script's configuration file
|
||||
SCRIPT_CONFIG_FILE="postprocess.conf"
|
||||
|
@ -96,6 +98,52 @@ POSTPROCESS_SUCCESS=93
|
|||
POSTPROCESS_ERROR=94
|
||||
POSTPROCESS_NONE=95
|
||||
|
||||
# Postprocessing function for nzbToCouchPotato and nzbToSickBeard
|
||||
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
|
||||
if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then
|
||||
echo "*** NZBGet post-process script ***"
|
||||
|
@ -164,25 +212,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"
|
||||
else
|
||||
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
|
||||
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 to notify Par-check failed"
|
||||
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "1" >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
exit $POSTPROCESS_ERROR
|
||||
do_exit $POSTPROCESS_ERROR
|
||||
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"
|
||||
exit $POSTPROCESS_ERROR
|
||||
do_exit $POSTPROCESS_ERROR
|
||||
fi
|
||||
|
||||
cd "$NZBPP_DIRECTORY"
|
||||
|
@ -193,7 +230,7 @@ if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then
|
|||
if [ -f "_brokenlog.txt" ]; then
|
||||
if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then
|
||||
echo "[INFO] Post-Process: Brokenlog found, requesting par-repair"
|
||||
exit $POSTPROCESS_PARCHECK_ALL
|
||||
do_exit $POSTPROCESS_PARCHECK_ALL
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
@ -210,7 +247,7 @@ if (ls *.rar >/dev/null 2>&1); then
|
|||
$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"
|
||||
exit $POSTPROCESS_ERROR
|
||||
do_exit $POSTPROCESS_ERROR
|
||||
fi
|
||||
|
||||
# Make a temporary directory to store the unrarred files
|
||||
|
@ -236,20 +273,9 @@ if (ls *.rar >/dev/null 2>&1); then
|
|||
# for delayed par-check/-repair at least one par-file must be already downloaded
|
||||
if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then
|
||||
echo "[INFO] Post-Process: Requesting par-repair"
|
||||
exit $POSTPROCESS_PARCHECK_ALL
|
||||
# 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
|
||||
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 to notify unrar (second pass) failed"
|
||||
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "1">/dev/null 2>&1
|
||||
fi
|
||||
do_exit $POSTPROCESS_PARCHECK_ALL
|
||||
fi
|
||||
exit $POSTPROCESS_ERROR
|
||||
do_exit $POSTPROCESS_ERROR
|
||||
fi
|
||||
Unrared=1
|
||||
|
||||
|
@ -270,7 +296,7 @@ if (ls *.rar >/dev/null 2>&1); then
|
|||
|
||||
if [ "$?" -eq 3 ]; then
|
||||
echo "[INFO] Post-Process: Unrar (second pass) failed"
|
||||
exit $POSTPROCESS_ERROR
|
||||
do_exit $POSTPROCESS_ERROR
|
||||
fi
|
||||
|
||||
# Delete the Rar files
|
||||
|
@ -354,10 +380,11 @@ if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -d "$TvDownloadDir" ]; then
|
|||
cd ..
|
||||
rmdir "$NZBPP_DIRECTORY"
|
||||
NZBPP_DIRECTORY="$TvDownloadDir"
|
||||
cd "$NZBPP_DIRECTORY"
|
||||
fi
|
||||
fi
|
||||
# Test for category and ensure the passed directory exists as a directory.
|
||||
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -d "$MoviesDownloadDir' ]; then
|
||||
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -d "$MoviesDownloadDir" ]; then
|
||||
echo "[INFO] Post-Process: Moving Movies to $MoviesDownloadDir"
|
||||
cp -R "$NZBPP_DIRECTORY" "$MoviesDownloadDir" >/dev/null 2>&1
|
||||
if [ "$?" -ne 0 ]; then
|
||||
|
@ -368,6 +395,7 @@ if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -d "$MoviesDownloadDir' ]; th
|
|||
cd ..
|
||||
rmdir "$NZBPP_DIRECTORY"
|
||||
NZBPP_DIRECTORY="$MoviesDownloadDir"
|
||||
cd "$NZBPP_DIRECTORY"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -375,18 +403,6 @@ fi
|
|||
### END CUSTOMIZATIONS ###
|
||||
##########################
|
||||
|
||||
if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$NzbToSickBeard" ]; then
|
||||
# Call SickBeard's postprocessing script
|
||||
echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
|
||||
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "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
|
||||
# (for current nzb-file) via web-interface or via command line with
|
||||
# "nzbget -E G O DestDir=/new/path <ID>"
|
||||
|
@ -395,7 +411,9 @@ if [ "$NZBPR_DestDir" != "" ]; then
|
|||
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
|
||||
exit $POSTPROCESS_SUCCESS
|
||||
do_exit $POSTPROCESS_SUCCESS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue