This commit is contained in:
schumi2004 2012-12-08 14:07:05 -08:00
commit 31c7e781cf
5 changed files with 174 additions and 176 deletions

View file

@ -1,109 +1,105 @@
# Author: Nic Wolfe <nic@wolfeden.ca> # Author: Nic Wolfe <nic@wolfeden.ca>
# URL: http://code.google.com/p/sickbeard/ # URL: http://code.google.com/p/sickbeard/
# #
# This file is part of Sick Beard. # This file is part of Sick Beard.
# #
# Sick Beard is free software: you can redistribute it and/or modify # Sick Beard is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# Sick Beard is distributed in the hope that it will be useful, # Sick Beard is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>. # along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
import sys import sys
import urllib import urllib
import os.path import os.path
import ConfigParser import ConfigParser
class AuthURLOpener(urllib.FancyURLopener): class AuthURLOpener(urllib.FancyURLopener):
def __init__(self, user, pw): def __init__(self, user, pw):
self.username = user self.username = user
self.password = pw self.password = pw
self.numTries = 0 self.numTries = 0
urllib.FancyURLopener.__init__(self) urllib.FancyURLopener.__init__(self)
def prompt_user_passwd(self, host, realm): def prompt_user_passwd(self, host, realm):
if self.numTries == 0: if self.numTries == 0:
self.numTries = 1 self.numTries = 1
return (self.username, self.password) return (self.username, self.password)
else: else:
return ('', '') return ('', '')
def openit(self, url): def openit(self, url):
self.numTries = 0 self.numTries = 0
return urllib.FancyURLopener.open(self, url) return urllib.FancyURLopener.open(self, url)
def processEpisode(dirName, nzbName=None, status=0): def processEpisode(dirName, nzbName=None, failed=False):
config = ConfigParser.ConfigParser()
status = int(status) configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")
if status > 0: print "Loading config from", configFilename
print "the download failed. nothing to process"
sys.exit() if not os.path.isfile(configFilename):
print "ERROR: You need an autoProcessTV.cfg file - did you rename and edit the .sample?"
config = ConfigParser.ConfigParser() sys.exit(-1)
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")
print "Loading config from", configFilename try:
fp = open(configFilename, "r")
if not os.path.isfile(configFilename): config.readfp(fp)
print "ERROR: You need an autoProcessTV.cfg file - did you rename and edit the .sample?" fp.close()
sys.exit(-1) except IOError, e:
print "Could not read configuration file: ", str(e)
try: sys.exit(1)
fp = open(configFilename, "r")
config.readfp(fp) host = config.get("SickBeard", "host")
fp.close() port = config.get("SickBeard", "port")
except IOError, e: username = config.get("SickBeard", "username")
print "Could not read configuration file: ", str(e) password = config.get("SickBeard", "password")
sys.exit(1) try:
ssl = int(config.get("SickBeard", "ssl"))
host = config.get("SickBeard", "host") except (ConfigParser.NoOptionError, ValueError):
port = config.get("SickBeard", "port") ssl = 0
username = config.get("SickBeard", "username")
password = config.get("SickBeard", "password") try:
try: web_root = config.get("SickBeard", "web_root")
ssl = int(config.get("SickBeard", "ssl")) except ConfigParser.NoOptionError:
except (ConfigParser.NoOptionError, ValueError): web_root = ""
ssl = 0
params = {}
try:
web_root = config.get("SickBeard", "web_root") params['quiet'] = 1
except ConfigParser.NoOptionError:
web_root = "" params['dirName'] = dirName
if nzbName != None:
params = {} params['nzbName'] = nzbName
params['quiet'] = 1 params['failed'] = failed
params['dir'] = dirName myOpener = AuthURLOpener(username, password)
if nzbName != None:
params['nzbName'] = nzbName if ssl:
protocol = "https://"
myOpener = AuthURLOpener(username, password) else:
protocol = "http://"
if ssl:
protocol = "https://" url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(params)
else:
protocol = "http://" print "Opening URL:", url
url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(params) try:
urlObj = myOpener.openit(url)
print "Opening URL:", url except IOError, e:
print "Unable to open URL: ", str(e)
try: sys.exit(1)
urlObj = myOpener.openit(url)
except IOError, e: result = urlObj.readlines()
print "Unable to open URL: ", str(e) for line in result:
sys.exit(1) print line
result = urlObj.readlines()
for line in result:
print line

View file

@ -3,30 +3,18 @@
import sys import sys
import autoProcessMovie import autoProcessMovie
# SABnzbd if len(sys.argv) < 8:
if len(sys.argv) == 8: print "Invalid number of arguments received from client. Please update it."
# SABnzbd argv: sys.exit()
# 1 The final directory of the job (full path) else:
# 2 The original name of the NZB file print "Script triggered from client, starting autoProcessMovie..."
# 3 Clean version of the job name (no path info and ".nzb" removed)
# 4 Indexer's report number (if supported)
# 5 User-defined category
# 6 Group that the NZB was posted in e.g. alt.binaries.x
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
print "Script triggered from SABnzbd, starting autoProcessMovie..."
autoProcessMovie.process(sys.argv[1], sys.argv[2], sys.argv[7]) autoProcessMovie.process(sys.argv[1], sys.argv[2], sys.argv[7])
# NZBGet # sys.argv:
elif len(sys.argv) == 3: # 1 The final directory of the job (full path)
# NZBGet argv: # 2 The original name of the NZB file
# 1 The final directory of the job (full path) # 3 Clean version of the job name (no path info and ".nzb" removed)
# 2 The original name of the NZB file # 4 Indexer's report number (if supported)
# From NZBGet only successful downloads are triggered so status is set to "0" # 5 User-defined category
print "Script triggered from NZBGet, starting autoProcessMovie..." # 6 Group that the NZB was posted in e.g. alt.binaries.x
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
autoProcessMovie.process(sys.argv[1], sys.argv[2], 0)
else:
print "Invalid number of arguments received from client."
print "Running autoProcessMovie as a manual run..."
autoProcessMovie.process('Manual Run', 'Manual Run', 0)

View file

@ -21,33 +21,21 @@
# Edited by Clinton Hall to prevent processing of failed downloads. # Edited by Clinton Hall to prevent processing of failed downloads.
# Also added suppot for NZBGet. With help from thorli # Also added suppot for NZBGet. With help from thorli
import sys import sys
import autoProcessTV import autoProcessTV
# SABnzbd if len(sys.argv) < 8:
if len(sys.argv) == 8: print "Invalid number of arguments received from client. Please update it."
# SABnzbd argv: sys.exit()
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file
# 3 Clean version of the job name (no path info and ".nzb" removed)
# 4 Indexer's report number (if supported)
# 5 User-defined category
# 6 Group that the NZB was posted in e.g. alt.binaries.x
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
print "Script triggered from SABnzbd, starting autoProcessTV..."
autoProcessTV.processEpisode(sys.argv[1], sys.argv[2], sys.argv[7])
# NZBGet
elif len(sys.argv) == 3:
# NZBGet argv:
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file
# From NZBGet only successful downloads are triggered so status is set to "0"
print "Script triggered from NZBGet, starting autoProcessTV..."
autoProcessTV.processEpisode(sys.argv[1], sys.argv[2], 0)
else: else:
print "Invalid number of arguments received from client." print "Script triggered from client, starting autoProcessTV..."
sys.exit() autoProcessTV.processEpisode(sys.argv[1], sys.argv[2], sys.argv[7])
# sys.argv:
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file
# 3 Clean version of the job name (no path info and ".nzb" removed)
# 4 Indexer's report number (if supported)
# 5 User-defined category
# 6 Group that the NZB was posted in e.g. alt.binaries.x
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2

View file

@ -164,6 +164,18 @@ 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
# Uncomment if SickBeard Branch is fixed
#if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$SabToSickBeard" ]; then
# # Call SickBeard's postprocessing script
# echo "[INFO] Post-Process: Running SickBeard's postprocessing script to notify Par-check failed"
#$PythonCmd $SabToSickBeard "$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 fi
exit $POSTPROCESS_ERROR exit $POSTPROCESS_ERROR
fi fi
@ -226,6 +238,18 @@ if (ls *.rar >/dev/null 2>&1); 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: Requesting par-repair" echo "[INFO] Post-Process: Requesting par-repair"
exit $POSTPROCESS_PARCHECK_ALL exit $POSTPROCESS_PARCHECK_ALL
# Send notifications to SickBeard or CouchPotato that unrar (second pass) failed
# Uncomment if SickBeard Branch is fixed
#if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$SabToSickBeard" ]; then
# # Call SickBeard's postprocessing script
# echo "[INFO] Post-Process: Running SickBeard's postprocessing script to notify unrar (second pass) failed"
# $PythonCmd $SabToSickBeard "$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
fi fi
exit $POSTPROCESS_ERROR exit $POSTPROCESS_ERROR
fi fi
@ -282,9 +306,9 @@ fi
# Clean up # Clean up
echo "[INFO] Post-Process: Cleaning up" echo "[INFO] Post-Process: Cleaning up"
chmod -R a+rw . chmod -R a+rw .
rm *.nzb >/dev/null 2>&1 # Clean up list, space seperated from GUI
rm *.sfv >/dev/null 2>&1 rm $FileCleanUp >/dev/null 2>&1
rm *.1 >/dev/null 2>&1 # Removed by default
rm _brokenlog.txt >/dev/null 2>&1 rm _brokenlog.txt >/dev/null 2>&1
if [ "$Unrared" -eq 1 ]; then if [ "$Unrared" -eq 1 ]; then
# Delete par2-file only if there were files for unpacking. # Delete par2-file only if there were files for unpacking.
@ -321,30 +345,30 @@ fi
# Move categories to /share/yourdirectory and remove download destination directory # Move categories to /share/yourdirectory and remove download destination directory
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then
echo "[INFO] Post-Process: Moving TV shows to $TV_DL_DIR" echo "[INFO] Post-Process: Moving TV shows to $TvDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$TV_DL_DIR" >/dev/null 2>&1 cp -R "$NZBPP_DIRECTORY" "$TvDownloadDir" >/dev/null 2>&1
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $TV_DL_DIR" echo "[ERROR] Post-Process: Moving to $TvDownloadDir"
exit $POSTPROCESS_ERROR exit $POSTPROCESS_ERROR
else else
rm -fr * rm -fr *
cd .. cd ..
rmdir "$NZBPP_DIRECTORY" rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$TV_DL_DIR" NZBPP_DIRECTORY="$TvDownloadDir"
fi fi
fi fi
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
echo "[INFO] Post-Process: Moving Movies to $MOVIES_DL_DIR" echo "[INFO] Post-Process: Moving Movies to $MoviesDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$MOVIES_DL_DIR" >/dev/null 2>&1 cp -R "$NZBPP_DIRECTORY" "$MoviesDownloadDir" >/dev/null 2>&1
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $MOVIES_DL_DIR" echo "[ERROR] Post-Process: Moving to $MoviesDownloadDir"
exit $POSTPROCESS_ERROR exit $POSTPROCESS_ERROR
else else
rm -fr * rm -fr *
cd .. cd ..
rmdir "$NZBPP_DIRECTORY" rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$MOVIES_DL_DIR" NZBPP_DIRECTORY="$MoviesDownloadDir"
fi fi
fi fi
@ -355,13 +379,13 @@ fi
if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$NzbToSickBeard" ]; then if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$NzbToSickBeard" ]; then
# Call SickBeard's postprocessing script # Call SickBeard's postprocessing script
echo "[INFO] Post-Process: Running SickBeard's postprocessing script" echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 $PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "" "" "" "" "0" >/dev/null 2>&1
fi fi
if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then
# Call CouchPotato's postprocessing script # Call CouchPotato's postprocessing script
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" echo "[INFO] Post-Process: Running CouchPotato's postprocessing script"
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 $PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "" "" "" "" "0" >/dev/null 2>&1
fi fi
# Check if destination directory was set in postprocessing parameters # Check if destination directory was set in postprocessing parameters

View file

@ -36,15 +36,15 @@ PythonCmd=/usr/local/python/bin/python
NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py
# Set the full path where completed movies should be placed # Set the full path where completed movies should be placed
# before CouchPotato's Renamer is called # before SickBeard's Renamer is called
TV_DL_DIR=/usr/local/nzbget/complete/tv TvDownloadDir=/usr/local/nzbget/complete/tv
# Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing # Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing
NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py
# Set the full path where completed movies should be placed # Set the full path where completed movies should be placed
# before CouchPotato's Renamer is called # before CouchPotato's Renamer is called
MOVIES_DL_DIR=/usr/local/nzbget/complete/movies MoviesDownloadDir=/usr/local/nzbget/complete/movies
############################################################################## ##############################################################################
### OPTIONS ### ### OPTIONS ###
@ -70,6 +70,8 @@ CouchPotato=yes
# Category for Couchpotato's postprocessing. # Category for Couchpotato's postprocessing.
CouchPotatoCategory=movies CouchPotatoCategory=movies
# Clean up list. (space seperated, default *.nzb *.sfv *.1)
FileCleanUp=*.nzb *.sfv *.1
############################################################################## ##############################################################################
### POSTPROCESSING-PARAMETERS ### ### POSTPROCESSING-PARAMETERS ###