Merge pull request #299 from echel0n/dev

Bugfixes for auto fork feature
This commit is contained in:
Clinton Hall 2014-03-31 20:40:22 +10:30
commit 4e4bc03234
4 changed files with 35 additions and 53 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ autoProcessMedia.cfg
*.pyo *.pyo
postprocess.log postprocess.log
/.idea/

View file

@ -1,18 +1,13 @@
import sys
import urllib import urllib
import os
import ConfigParser
import logging import logging
import shutil
import time
import socket
import copy import copy
import Transcoder import Transcoder
from nzbToMediaEnv import * from nzbToMediaEnv import *
from nzbToMediaUtil import * from nzbToMediaUtil import *
from nzbToMediaSceneExceptions import process_all_exceptions from nzbToMediaSceneExceptions import process_all_exceptions
from autoSickBeardFork import autoFork from autoProcess.autoSickBeardFork import autoFork
Logger = logging.getLogger() Logger = logging.getLogger()
@ -69,22 +64,18 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
ssl = int(config.get(section, "ssl")) ssl = int(config.get(section, "ssl"))
except (ConfigParser.NoOptionError, ValueError): except (ConfigParser.NoOptionError, ValueError):
ssl = 0 ssl = 0
try: try:
web_root = config.get(section, "web_root") web_root = config.get(section, "web_root")
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
web_root = "" web_root = ""
try: try:
watch_dir = config.get(section, "watch_dir") watch_dir = config.get(section, "watch_dir")
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
watch_dir = "" watch_dir = ""
try: try:
transcode = int(config.get("Transcoder", "transcode")) transcode = int(config.get("Transcoder", "transcode"))
except (ConfigParser.NoOptionError, ValueError): except (ConfigParser.NoOptionError, ValueError):
transcode = 0 transcode = 0
try: try:
delete_failed = int(config.get(section, "delete_failed")) delete_failed = int(config.get(section, "delete_failed"))
except (ConfigParser.NoOptionError, ValueError): except (ConfigParser.NoOptionError, ValueError):
@ -155,30 +146,26 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
if watch_dir != "" and (not host in ['localhost', '127.0.0.1'] or nzbName == "Manual Run"): if watch_dir != "" and (not host in ['localhost', '127.0.0.1'] or nzbName == "Manual Run"):
dirName = watch_dir dirName = watch_dir
# don't have sickbeard display any output # configure SB params to pass
params['quiet'] = 1 params['quiet'] = 1
if nzbName is not None:
params['nzbName'] = nzbName
for param in copy.copy(params): for param in copy.copy(params):
if param is "failed": if param is "failed":
params[param] = failed params[param] = failed
if param is "dirName": if param is "dirName" or param is "dir":
params[param] = dirName params[param] = dirName
if param is "dir":
params[param] = dirName
if param is "process":
params["process"] = None
if param is "process_method": if param is "process_method":
if process_method: if process_method:
params[param] = process_method params[param] = process_method
else: else:
del params[param] del params[param]
if nzbName != None: # delete any unused params so we don't pass them to SB by mistake
params['nzbName'] = nzbName [params.pop(k) for k,v in params.iteritems() if v is None]
if status == 0: if status == 0:
Logger.info("The download succeeded. Sending process request to SickBeard's %s branch", fork) Logger.info("The download succeeded. Sending process request to SickBeard's %s branch", fork)

View file

@ -49,38 +49,35 @@ def autoFork(fork=None):
web_root = "" web_root = ""
try: try:
fork = config.get(section, "fork") fork = forks.items()[forks.keys().index(config.get(section, "fork"))]
except ConfigParser.NoOptionError: except:
fork = "auto" fork = "auto"
if fork in "auto": myOpener = AuthURLOpener(username, password)
myOpener = AuthURLOpener(username, password)
if ssl: if ssl:
protocol = "https://" protocol = "https://"
else: else:
protocol = "http://" protocol = "http://"
detected = False
if fork is "auto":
Logger.info("Attempting to auto-detect SickBeard fork") Logger.info("Attempting to auto-detect SickBeard fork")
for f in forks.iteritems(): for fork in sorted(forks.iteritems()):
url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(f[1]['params']) url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(fork[1])
# attempting to auto-detect fork # attempting to auto-detect fork
urlObj = myOpener.openit(url) urlObj = myOpener.openit(url)
if urlObj.getcode() == 200: if urlObj.getcode() == 200:
Logger.info("SickBeard fork auto-detection successful. Fork set to %s", f[1]['name']) detected = True
return f[1]['name'], f[1]['params'] break
# failed to auto-detect fork if detected:
Logger.info("SickBeard fork auto-detection failed") Logger.info("SickBeard fork auto-detection successful ...")
else:
Logger.info("SickBeard fork auto-detection failed")
fork = forks.items()[forks.keys().index(fork_default)]
else: #if not fork in "auto" Logger.info("SickBeard fork set to %s", fork[0])
try: return fork[0], fork[1]
fork = fork if fork in SICKBEARD_FAILED or fork in SICKBEARD_TORRENT else fork_default
fork = [f for f in forks.iteritems() if f[1]['name'] == fork][0]
except:
fork = [f for f in forks.iteritems() if f[1]['name'] == fork_default][0]
Logger.info("SickBeard fork set to %s", fork[1]['name'])
return fork[1]['name'], fork[1]['params']

View file

@ -10,18 +10,15 @@ SABNZB_0717_NO_OF_ARGUMENTS = 9
# Constants pertaining to SickBeard Branches: # Constants pertaining to SickBeard Branches:
fork_default = "default" fork_default = "default"
fork_default_new = "default-new"
fork_failed = "failed" fork_failed = "failed"
fork_failed_new = "failed-new"
fork_failed_torrent = "failed-torrent" fork_failed_torrent = "failed-torrent"
forks = {} # these need to be in order of most unique params first. forks = {}
forks[1] = {'name': fork_failed_torrent, 'params': {"dir": None, "failed": None, "process_method": None}}
forks[2] = {'name': fork_failed, 'params': {"dirName": None, "failed": None}}
forks[3] = {'name': fork_failed_new, 'params': {"dir": None, "failed": None}}
forks[4] = {'name': fork_default_new, 'params': {"dir": None, "process": None}}
forks[5] = {'name': fork_default, 'params': {"dir": None}}
SICKBEARD_FAILED = [fork_failed, fork_failed_torrent, fork_failed_new] forks[fork_default] = {"dir": None, "method": None}
forks[fork_failed] = {"dirName": None, "failed": None}
forks[fork_failed_torrent] = {"dir": None, "failed": None, "process_method": None}
SICKBEARD_FAILED = [fork_failed, fork_failed_torrent]
SICKBEARD_TORRENT = [fork_failed_torrent] SICKBEARD_TORRENT = [fork_failed_torrent]