Skip to content

Commit

Permalink
Merge pull request #878 from Hellowlol/process_api
Browse files Browse the repository at this point in the history
Add postprocess to api
  • Loading branch information
midgetspy committed Apr 30, 2015
2 parents b04faa6 + 693e5c5 commit 7cfff7f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions data/interfaces/default/apiBuilder.tmpl
Expand Up @@ -53,6 +53,7 @@ addList("Command", "History", "?cmd=history", "history");
addOption("Command", "History.Clear", "?cmd=history.clear", "", "", "action");
addOption("Command", "History.Trim", "?cmd=history.trim", "", "", "action");
addList("Command", "Logs", "?cmd=logs", "logs");
addList("Command", "PostProcess", "?cmd=postprocess", "postprocess", "", "","action");
addList("Command", "Show", "?cmd=show", "tvdbid");
addList("Command", "Show.AddExisting", "?cmd=show.addexisting", "show.addexisting", "", "", "action");
addList("Command", "Show.AddNew", "?cmd=show.addnew", "show.addnew", "", "", "action");
Expand Down Expand Up @@ -82,6 +83,11 @@ addOption("logs", "Info", "&min_level=info");
addOption("logs", "Warning", "&min_level=warning");
addOption("logs", "Error", "&min_level=error");

addOption("postprocess", "Optional Param", "", 1);
addOption("postprocess", "C:\\PATH\\TO\\DIR", "&path=C:\\Temp");
addOption("postprocess", "return_data", "&return_data=1");
addOption("postprocess", "force_replace", "&force_replace=1");

addOption("sb.setdefaults", "Optional Param", "", 1);
addList("sb.setdefaults", "Exclude Paused Shows on ComingEps", "&future_show_paused=0", "sb.setdefaults-status");
addList("sb.setdefaults", "Include Paused Shows on ComingEps", "&future_show_paused=1", "sb.setdefaults-status");
Expand Down
40 changes: 39 additions & 1 deletion sickbeard/webapi.py
Expand Up @@ -33,7 +33,7 @@
from sickbeard import db, logger, exceptions, history, ui, helpers
from sickbeard.exceptions import ex
from sickbeard import encodingKludge as ek
from sickbeard import search_queue
from sickbeard import search_queue, processTV
from sickbeard.common import SNATCHED, SNATCHED_PROPER, DOWNLOADED, SKIPPED, UNAIRED, IGNORED, ARCHIVED, WANTED, UNKNOWN
from common import Quality, qualityPresetStrings, statusStrings
from sickbeard import image_cache
Expand Down Expand Up @@ -1197,6 +1197,43 @@ def run(self):

return _responds(RESULT_SUCCESS, finalData)

class CMD_PostProcess(ApiCall):
_help = {"desc": "Manual postprocess TV Download Dir",
"optionalParameters": {"path": {"desc": "Post process this folder"},
"force_replace": {"desc": "Overwrite files"},
"return_data": {"desc": "Returns result for the process"}
}
}

def __init__(self, args, kwargs):
# required
# optional
self.path, args = self.check_params(args, kwargs, "path", None, False, "string", [])
self.force_replace, args = self.check_params(args, kwargs, "force_replace", 0, False, "bool", [])
self.return_data, args = self.check_params(args, kwargs, "return_data", 0, False, "bool", [])
# super, missing, help
ApiCall.__init__(self, args, kwargs)

def run(self):
""" Starts the postprocess """
pp_options = {}

if not self.path and not sickbeard.TV_DOWNLOAD_DIR:
return _responds(RESULT_FAILURE, msg="You need to provide a path or set TV Download Dir")

if not self.path:
self.path = sickbeard.TV_DOWNLOAD_DIR

if bool(self.force_replace):
pp_options["force_replace"] = True

data = processTV.processDir(self.path, method="Manual", pp_options=pp_options)

if not self.return_data:
data = ""

return _responds(RESULT_SUCCESS, data=data, msg="Started postprocess for %s" % self.path)


class CMD_SickBeard(ApiCall):
_help = {"desc": "display misc sickbeard related information"}
Expand Down Expand Up @@ -2467,6 +2504,7 @@ def run(self):
"history.clear": CMD_HistoryClear,
"history.trim": CMD_HistoryTrim,
"logs": CMD_Logs,
"postprocess": CMD_PostProcess,
"sb": CMD_SickBeard,
"sb.addrootdir": CMD_SickBeardAddRootDir,
"sb.checkscheduler": CMD_SickBeardCheckScheduler,
Expand Down

0 comments on commit 7cfff7f

Please sign in to comment.