Added manual run for SickBeard.

Fixed some conditional checks.
This commit is contained in:
echel0n 2014-04-02 01:36:59 -07:00
commit 5f476ebc1a
4 changed files with 56 additions and 43 deletions

1
.gitignore vendored
View file

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

View file

@ -37,24 +37,20 @@ def delete(dirName):
Logger.exception("Unable to delete folder %s", dirName)
def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputCategory=None):
def processEpisode(dirName, nzbName=None, failed=False, clientAgent = "manual", inputCategory=None):
status = int(failed)
Logger.info("Loading config from %s", CONFIG_FILE)
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
section = "SickBeard"
if inputCategory != None and config().has_section(inputCategory):
section = inputCategory
watch_dir = ""
host = config().get(section, "host")
port = config().get(section, "port")
username = config().get(section, "username")
@ -100,7 +96,22 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
process_method = config().get(section, "process_method")
except config.NoOptionError:
process_method = None
# configure dirName for manual run
try:
if dirName == 'Manual Run':
delay = 0
if watch_dir != "" and (not host in ['localhost', '127.0.0.1']):
dirName = watch_dir
else:
dirName = config().get("Torrent", "outputDirectory")
# check if path is valid
if not os.path.exists(dirName):
return 1 # failure
except config.NoOptionError:
return 1 # failure
mediaContainer = (config().get("Extensions", "mediaExtensions")).split(',')
minSampleSize = int(config().get("Extensions", "minSampleSize"))
@ -117,11 +128,11 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
# auto-detect fork type
fork, params = autoFork()
if nzbName != "Manual Run" and (not fork in SICKBEARD_TORRENT or (clientAgent in ['nzbget','sabnzbd'] and not nzbExtractionBy == "Destination")):
if fork not in SICKBEARD_TORRENT or (clientAgent in ['nzbget','sabnzbd'] and nzbExtractionBy != "Destination"):
process_all_exceptions(nzbName.lower(), dirName)
nzbName, dirName = convert_to_ascii(nzbName, dirName)
# Now check if movie files exist in destination. Eventually extraction may be done here if nzbExtractionBy == TorrentToMedia
# Now check if tv files exist in destination. Eventually extraction may be done here if nzbExtractionBy == TorrentToMedia
video = int(0)
for dirpath, dirnames, filenames in os.walk(dirName):
for file in filenames:
@ -140,9 +151,6 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
status = int(1)
failed = True
if watch_dir != "" and (not host in ['localhost', '127.0.0.1'] or nzbName == "Manual Run"):
dirName = watch_dir
dirSize = getDirectorySize(dirName) # get total directory size to calculate needed processing time.
TimeOut = int(TimePerGiB) * dirSize # SickBeard needs to complete all moving and renaming before returning the log sequence via url.
TimeOut += 60 # Add an extra minute for over-head/processing/metadata.
@ -154,13 +162,13 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
params['nzbName'] = nzbName
for param in copy.copy(params):
if param is "failed":
if param == "failed":
params[param] = failed
if param is "dirName" or param is "dir":
if param in ["dirName", "dir"]:
params[param] = dirName
if param is "process_method":
if param == "process_method":
if process_method:
params[param] = process_method
else:

View file

@ -7,21 +7,21 @@ def migrate():
section = "CouchPotato"
for option, value in configold.items(section) or config(MOVIE_CONFIG_FILE).items(section):
if option is "category": # change this old format
if option == "category": # change this old format
option = "cpsCategory"
if option is "outputDirectory": # move this to new location format
if option == "outputDirectory": # move this to new location format
value = os.path.split(os.path.normpath(value))[0]
confignew.set("Torrent", option, value)
continue
if option in ["username", "password" ]: # these are no-longer needed.
continue
if option is "cpsCategory":
if option == "cpsCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
section = "SickBeard"
for option, value in configold.items(section) or config(TV_CONFIG_FILE).items(section):
if option is "category": # change this old format
if option == "category": # change this old format
option = "sbCategory"
if option == "wait_for": # remove old format
continue
@ -29,81 +29,81 @@ def migrate():
option = "fork"
if value not in ["default", "failed", "failed-torrent", "auto"]:
value = "auto"
if option is "fork" and value not in ["default", "failed", "failed-torrent", "auto"]:
if option == "fork" and value not in ["default", "failed", "failed-torrent", "auto"]:
value = "auto"
if option is "outputDirectory": # move this to new location format
if option == "outputDirectory": # move this to new location format
value = os.path.split(os.path.normpath(value))[0]
confignew.set("Torrent", option, value)
continue
if option is "sbCategory":
if option == "sbCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
for section in configold.sections():
if section is "HeadPhones":
if section == "HeadPhones":
if option in ["username", "password" ]:
continue
if option is "hpCategory":
if option == "hpCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
if section is "Mylar":
if section == "Mylar":
if option in "mlCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
if section is "Gamez":
if section == "Gamez":
if option in ["username", "password" ]: # these are no-longer needed.
continue
if option == "gzCategory":
categories.extend(value.split(','))
confignew.set(section, option, value)
if section is "Torrent":
if section == "Torrent":
if option in ["compressedExtensions", "mediaExtensions", "metaExtensions", "minSampleSize"]:
section = "Extensions" # these were moved
if option is "useLink": # Sym links supported now as well.
if option == "useLink": # Sym links supported now as well.
num_value = int(value or 0)
if num_value is 1:
if num_value == 1:
value = "hard"
else:
value = "no"
confignew.set(section, option, value)
if section is "Extensions":
if section == "Extensions":
confignew.set(section, option, value)
if section is "Transcoder":
if section == "Transcoder":
confignew.set(section, option, value)
if section is "WakeOnLan":
if section == "WakeOnLan":
confignew.set(section, option, value)
if section is "UserScript":
if section == "UserScript":
confignew.set(section, option, value)
if section is "ASCII":
if section == "ASCII":
confignew.set(section, option, value)
if section is "passwords":
if section == "passwords":
confignew.set(section, option, value)
if section is "loggers":
if section == "loggers":
confignew.set(section, option, value)
if section is "handlers":
if section == "handlers":
confignew.set(section, option, value)
if section is "formatters":
if section == "formatters":
confignew.set(section, option, value)
if section is "logger_root":
if section == "logger_root":
confignew.set(section, option, value)
if section is "handler_console":
if section == "handler_console":
confignew.set(section, option, value)
if section is "formatter_generic":
if section == "formatter_generic":
confignew.set(section, option, value)
for section in categories:

View file

@ -399,12 +399,16 @@ elif len(sys.argv) >= SABNZB_0717_NO_OF_ARGUMENTS:
Logger.info("MAIN: Script triggered from SABnzbd 0.7.17+")
clientAgent = "sabnzbd"
nzbDir, inputName, status, inputCategory, download_id = (sys.argv[1], sys.argv[2], sys.argv[7], sys.argv[5], '')
else: # only CPS supports this manual run for now.
Logger.warn("MAIN: Invalid number of arguments received from client.")
Logger.info("MAIN: Running autoProcessMovie as a manual run...")
else: # only CPS and SB supports this manual run for now.
clientAgent = "manual"
Logger.warn("MAIN: Invalid number of arguments received from client.")
Logger.info("MAIN: Running autoProcessMovie as a manual run...")
nzbDir, inputName, status, inputCategory, download_id = ('Manual Run', 'Manual Run', 0, cpsCategory[0], '')
Logger.info("MAIN: Running autoProcessTV as a manual run...")
nzbDir, status, inputCategory = ('Manual Run', 0, sbCategory[0])
if inputCategory in cpsCategory:
Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName)
result = autoProcessMovie.process(nzbDir, inputName, status, clientAgent, download_id, inputCategory)