Fixed issues with webroot settings and reverse proxies.

Fixed issues with WebAPI and WebAPI builder.
This commit is contained in:
echel0n 2014-06-19 08:47:28 -07:00
parent b9c22582cf
commit 07685f4295
4 changed files with 115 additions and 112 deletions

View file

@ -275,7 +275,7 @@ def main():
if restore(restoreDir, sickbeard.PROG_DIR): if restore(restoreDir, sickbeard.PROG_DIR):
logger.log(u"Restore successful...") logger.log(u"Restore successful...")
else: else:
logger.log(u"Restore FAILED!") logger.log(u"Restore FAILED!", logger.ERROR)
# If they don't specify a config file then put it in the data dir # If they don't specify a config file then put it in the data dir
if not sickbeard.CONFIG_FILE: if not sickbeard.CONFIG_FILE:

View file

@ -98,11 +98,11 @@ class Api(webserve.MainHandler):
# if debug was set call the "_call_dispatcher" # if debug was set call the "_call_dispatcher"
if 'debug' in kwargs: if 'debug' in kwargs:
outDict = _call_dispatcher(args, kwargs) # this way we can debug the cherry.py traceback in the browser outDict = _call_dispatcher(self, args, kwargs) # this way we can debug the cherry.py traceback in the browser
del kwargs["debug"] del kwargs["debug"]
else: # if debug was not set we wrap the "call_dispatcher" in a try block to assure a json output else: # if debug was not set we wrap the "call_dispatcher" in a try block to assure a json output
try: try:
outDict = _call_dispatcher(args, kwargs) outDict = _call_dispatcher(self, args, kwargs)
except Exception, e: # real internal error oohhh nooo :( except Exception, e: # real internal error oohhh nooo :(
logger.log(u"API :: " + ex(e), logger.ERROR) logger.log(u"API :: " + ex(e), logger.ERROR)
errorData = {"error_msg": ex(e), errorData = {"error_msg": ex(e),
@ -135,23 +135,22 @@ class Api(webserve.MainHandler):
t.sortedShowList = sorted(sickbeard.showList, lambda x, y: cmp(titler(x.name), titler(y.name))) t.sortedShowList = sorted(sickbeard.showList, lambda x, y: cmp(titler(x.name), titler(y.name)))
myDB = db.DBConnection(row_type="dict")
seasonSQLResults = {} seasonSQLResults = {}
episodeSQLResults = {} episodeSQLResults = {}
for curShow in t.sortedShowList: with db.DBConnection(row_type="dict") as myDB:
seasonSQLResults[curShow.indexerid] = myDB.select( for curShow in t.sortedShowList:
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season DESC", [curShow.indexerid]) seasonSQLResults[curShow.indexerid] = myDB.select(
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season DESC", [curShow.indexerid])
for curShow in t.sortedShowList: for curShow in t.sortedShowList:
episodeSQLResults[curShow.indexerid] = myDB.select( episodeSQLResults[curShow.indexerid] = myDB.select(
"SELECT DISTINCT season,episode FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC", "SELECT DISTINCT season,episode FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC",
[curShow.indexerid]) [curShow.indexerid])
t.seasonSQLResults = seasonSQLResults t.seasonSQLResults = seasonSQLResults
t.episodeSQLResults = episodeSQLResults t.episodeSQLResults = episodeSQLResults
myDB.connection.close()
if len(sickbeard.API_KEY) == 32: if len(sickbeard.API_KEY) == 32:
t.apikey = sickbeard.API_KEY t.apikey = sickbeard.API_KEY
else: else:
@ -197,7 +196,7 @@ class Api(webserve.MainHandler):
return False, msg, args, kwargs return False, msg, args, kwargs
def call_dispatcher(args, kwargs): def call_dispatcher(handler, args, kwargs):
""" calls the appropriate CMD class """ calls the appropriate CMD class
looks for a cmd in args and kwargs looks for a cmd in args and kwargs
or calls the TVDBShorthandWrapper when the first args element is a number or calls the TVDBShorthandWrapper when the first args element is a number
@ -230,10 +229,10 @@ def call_dispatcher(args, kwargs):
if not (multiCmds and cmd in ('show.getposter', 'show.getbanner')): # skip these cmd while chaining if not (multiCmds and cmd in ('show.getposter', 'show.getbanner')): # skip these cmd while chaining
try: try:
if cmd in _functionMaper: if cmd in _functionMaper:
curOutDict = _functionMaper.get(cmd)(curArgs, curOutDict = _functionMaper.get(cmd)(handler, curArgs,
curKwargs).run() # get the cmd class, init it and run() curKwargs).run() # get the cmd class, init it and run()
elif _is_int(cmd): elif _is_int(cmd):
curOutDict = TVDBShorthandWrapper(curArgs, curKwargs, cmd).run() curOutDict = TVDBShorthandWrapper(handler, curArgs, curKwargs, cmd).run()
else: else:
curOutDict = _responds(RESULT_ERROR, "No such cmd: '" + cmd + "'") curOutDict = _responds(RESULT_ERROR, "No such cmd: '" + cmd + "'")
except ApiError, e: # Api errors that we raised, they are harmless except ApiError, e: # Api errors that we raised, they are harmless
@ -257,7 +256,7 @@ def call_dispatcher(args, kwargs):
if multiCmds: # if we had multiple cmds we have to wrap it in a response dict if multiCmds: # if we had multiple cmds we have to wrap it in a response dict
outDict = _responds(RESULT_SUCCESS, outDict) outDict = _responds(RESULT_SUCCESS, outDict)
else: # index / no cmd given else: # index / no cmd given
outDict = CMD_SickBeard(args, kwargs).run() outDict = CMD_SickBeard(handler, args, kwargs).run()
return outDict return outDict
@ -296,10 +295,10 @@ def filter_params(cmd, args, kwargs):
return curArgs, curKwargs return curArgs, curKwargs
class ApiCall(webserve.MainHandler): class ApiCall(object):
_help = {"desc": "No help message available. Please tell the devs that a help msg is missing for this cmd"} _help = {"desc": "No help message available. Please tell the devs that a help msg is missing for this cmd"}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# missing # missing
try: try:
@ -311,6 +310,9 @@ class ApiCall(webserve.MainHandler):
if 'help' in kwargs: if 'help' in kwargs:
self.run = self.return_help self.run = self.return_help
# RequestHandler
self.handler = handler
def run(self): def run(self):
# override with real output function in subclass # override with real output function in subclass
return {} return {}
@ -477,7 +479,8 @@ class ApiCall(webserve.MainHandler):
class TVDBShorthandWrapper(ApiCall): class TVDBShorthandWrapper(ApiCall):
_help = {"desc": "this is an internal function wrapper. call the help command directly for more information"} _help = {"desc": "this is an internal function wrapper. call the help command directly for more information"}
def __init__(self, args, kwargs, sid): def __init__(self, handler, args, kwargs, sid):
self.handler = handler
self.origArgs = args self.origArgs = args
self.kwargs = kwargs self.kwargs = kwargs
self.sid = sid self.sid = sid
@ -486,17 +489,17 @@ class TVDBShorthandWrapper(ApiCall):
self.e, args = self.check_params(args, kwargs, "e", None, False, "ignore", []) self.e, args = self.check_params(args, kwargs, "e", None, False, "ignore", [])
self.args = args self.args = args
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" internal function wrapper """ """ internal function wrapper """
args = (self.sid,) + self.origArgs args = (self.sid,) + self.origArgs
if self.e: if self.e:
return CMD_Episode(args, self.kwargs).run() return CMD_Episode(self.handler, args, self.kwargs).run()
elif self.s: elif self.s:
return CMD_ShowSeasons(args, self.kwargs).run() return CMD_ShowSeasons(self.handler, args, self.kwargs).run()
else: else:
return CMD_Show(args, self.kwargs).run() return CMD_Show(self.handler, args, self.kwargs).run()
################################ ################################
@ -681,11 +684,11 @@ class CMD_Help(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
self.subject, args = self.check_params(args, kwargs, "subject", "help", False, "string", _functionMaper.keys()) self.subject, args = self.check_params(args, kwargs, "subject", "help", False, "string", _functionMaper.keys())
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display help information for a given subject/command """ """ display help information for a given subject/command """
@ -705,7 +708,7 @@ class CMD_ComingEpisodes(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
self.sort, args = self.check_params(args, kwargs, "sort", "date", False, "string", ["date", "show", "network"]) self.sort, args = self.check_params(args, kwargs, "sort", "date", False, "string", ["date", "show", "network"])
@ -714,7 +717,7 @@ class CMD_ComingEpisodes(ApiCall):
self.paused, args = self.check_params(args, kwargs, "paused", sickbeard.COMING_EPS_DISPLAY_PAUSED, False, "int", self.paused, args = self.check_params(args, kwargs, "paused", sickbeard.COMING_EPS_DISPLAY_PAUSED, False, "int",
[0, 1]) [0, 1])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display the coming episodes """ """ display the coming episodes """
@ -817,7 +820,7 @@ class CMD_Episode(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
self.s, args = self.check_params(args, kwargs, "season", None, True, "int", []) self.s, args = self.check_params(args, kwargs, "season", None, True, "int", [])
@ -825,7 +828,7 @@ class CMD_Episode(ApiCall):
# optional # optional
self.fullPath, args = self.check_params(args, kwargs, "full_path", 0, False, "bool", []) self.fullPath, args = self.check_params(args, kwargs, "full_path", 0, False, "bool", [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display detailed info about an episode """ """ display detailed info about an episode """
@ -875,14 +878,14 @@ class CMD_EpisodeSearch(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
self.s, args = self.check_params(args, kwargs, "season", None, True, "int", []) self.s, args = self.check_params(args, kwargs, "season", None, True, "int", [])
self.e, args = self.check_params(args, kwargs, "episode", None, True, "int", []) self.e, args = self.check_params(args, kwargs, "episode", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" search for an episode """ """ search for an episode """
@ -924,7 +927,7 @@ class CMD_EpisodeSetStatus(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
self.s, args = self.check_params(args, kwargs, "season", None, True, "int", []) self.s, args = self.check_params(args, kwargs, "season", None, True, "int", [])
@ -934,7 +937,7 @@ class CMD_EpisodeSetStatus(ApiCall):
self.e, args = self.check_params(args, kwargs, "episode", None, False, "int", []) self.e, args = self.check_params(args, kwargs, "episode", None, False, "int", [])
self.force, args = self.check_params(args, kwargs, "force", 0, False, "bool", []) self.force, args = self.check_params(args, kwargs, "force", 0, False, "bool", [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" set status of an episode or a season (when no ep is provided) """ """ set status of an episode or a season (when no ep is provided) """
@ -1028,14 +1031,14 @@ class CMD_SubtitleSearch(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
self.s, args = self.check_params(args, kwargs, "season", None, True, "int", []) self.s, args = self.check_params(args, kwargs, "season", None, True, "int", [])
self.e, args = self.check_params(args, kwargs, "episode", None, True, "int", []) self.e, args = self.check_params(args, kwargs, "episode", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" search episode subtitles """ """ search episode subtitles """
@ -1078,12 +1081,12 @@ class CMD_Exceptions(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, False, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, False, "int", [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display scene exceptions for all or a given show """ """ display scene exceptions for all or a given show """
@ -1121,13 +1124,13 @@ class CMD_History(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
self.limit, args = self.check_params(args, kwargs, "limit", 100, False, "int", []) self.limit, args = self.check_params(args, kwargs, "limit", 100, False, "int", [])
self.type, args = self.check_params(args, kwargs, "type", None, False, "string", ["downloaded", "snatched"]) self.type, args = self.check_params(args, kwargs, "type", None, False, "string", ["downloaded", "snatched"])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display sickbeard downloaded/snatched history """ """ display sickbeard downloaded/snatched history """
@ -1179,11 +1182,11 @@ class CMD_HistoryClear(ApiCall):
_help = {"desc": "clear sickbeard's history", _help = {"desc": "clear sickbeard's history",
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" clear sickbeard's history """ """ clear sickbeard's history """
@ -1198,11 +1201,11 @@ class CMD_HistoryTrim(ApiCall):
_help = {"desc": "trim sickbeard's history by removing entries greater than 30 days old" _help = {"desc": "trim sickbeard's history by removing entries greater than 30 days old"
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" trim sickbeard's history """ """ trim sickbeard's history """
@ -1220,13 +1223,13 @@ class CMD_Logs(ApiCall):
"desc": "the minimum level classification of log entries to show, with each level inherting its above level"}} "desc": "the minimum level classification of log entries to show, with each level inherting its above level"}}
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
self.min_level, args = self.check_params(args, kwargs, "min_level", "error", False, "string", self.min_level, args = self.check_params(args, kwargs, "min_level", "error", False, "string",
["error", "warning", "info", "debug"]) ["error", "warning", "info", "debug"])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" view sickbeard's log """ """ view sickbeard's log """
@ -1278,11 +1281,11 @@ class CMD_Logs(ApiCall):
class CMD_SickBeard(ApiCall): class CMD_SickBeard(ApiCall):
_help = {"desc": "display misc sickbeard related information"} _help = {"desc": "display misc sickbeard related information"}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display misc sickbeard related information """ """ display misc sickbeard related information """
@ -1299,13 +1302,13 @@ class CMD_SickBeardAddRootDir(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.location, args = self.check_params(args, kwargs, "location", None, True, "string", []) self.location, args = self.check_params(args, kwargs, "location", None, True, "string", [])
# optional # optional
self.default, args = self.check_params(args, kwargs, "default", 0, False, "bool", []) self.default, args = self.check_params(args, kwargs, "default", 0, False, "bool", [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" add a parent directory to sickbeard's config """ """ add a parent directory to sickbeard's config """
@ -1352,11 +1355,11 @@ class CMD_SickBeardAddRootDir(ApiCall):
class CMD_SickBeardCheckScheduler(ApiCall): class CMD_SickBeardCheckScheduler(ApiCall):
_help = {"desc": "query the scheduler"} _help = {"desc": "query the scheduler"}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" query the scheduler """ """ query the scheduler """
@ -1379,12 +1382,12 @@ class CMD_SickBeardDeleteRootDir(ApiCall):
"requiredParameters": {"location": {"desc": "the full path to root (parent) directory"}} "requiredParameters": {"location": {"desc": "the full path to root (parent) directory"}}
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.location, args = self.check_params(args, kwargs, "location", None, True, "string", []) self.location, args = self.check_params(args, kwargs, "location", None, True, "string", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" delete a parent directory from sickbeard's config """ """ delete a parent directory from sickbeard's config """
@ -1423,11 +1426,11 @@ class CMD_SickBeardDeleteRootDir(ApiCall):
class CMD_SickBeardGetDefaults(ApiCall): class CMD_SickBeardGetDefaults(ApiCall):
_help = {"desc": "get sickbeard user defaults"} _help = {"desc": "get sickbeard user defaults"}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" get sickbeard user defaults """ """ get sickbeard user defaults """
@ -1443,11 +1446,11 @@ class CMD_SickBeardGetDefaults(ApiCall):
class CMD_SickBeardGetMessages(ApiCall): class CMD_SickBeardGetMessages(ApiCall):
_help = {"desc": "get all messages"} _help = {"desc": "get all messages"}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
messages = [] messages = []
@ -1461,11 +1464,11 @@ class CMD_SickBeardGetMessages(ApiCall):
class CMD_SickBeardGetRootDirs(ApiCall): class CMD_SickBeardGetRootDirs(ApiCall):
_help = {"desc": "get sickbeard user parent directories"} _help = {"desc": "get sickbeard user parent directories"}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" get the parent directories defined in sickbeard's config """ """ get the parent directories defined in sickbeard's config """
@ -1478,12 +1481,12 @@ class CMD_SickBeardPauseBacklog(ApiCall):
"optionalParameters": {"pause ": {"desc": "pause or unpause the global backlog"}} "optionalParameters": {"pause ": {"desc": "pause or unpause the global backlog"}}
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
self.pause, args = self.check_params(args, kwargs, "pause", 0, False, "bool", []) self.pause, args = self.check_params(args, kwargs, "pause", 0, False, "bool", [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" pause the backlog search """ """ pause the backlog search """
@ -1498,15 +1501,15 @@ class CMD_SickBeardPauseBacklog(ApiCall):
class CMD_SickBeardPing(ApiCall): class CMD_SickBeardPing(ApiCall):
_help = {"desc": "check to see if sickbeard is running"} _help = {"desc": "check to see if sickbeard is running"}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" check to see if sickbeard is running """ """ check to see if sickbeard is running """
self.set_header('Cache-Control', "max-age=0,no-cache,no-store") self.handler.set_header('Cache-Control', "max-age=0,no-cache,no-store")
if sickbeard.started: if sickbeard.started:
return _responds(RESULT_SUCCESS, {"pid": sickbeard.PID}, "Pong") return _responds(RESULT_SUCCESS, {"pid": sickbeard.PID}, "Pong")
else: else:
@ -1516,11 +1519,11 @@ class CMD_SickBeardPing(ApiCall):
class CMD_SickBeardRestart(ApiCall): class CMD_SickBeardRestart(ApiCall):
_help = {"desc": "restart sickbeard"} _help = {"desc": "restart sickbeard"}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" restart sickbeard """ """ restart sickbeard """
@ -1542,7 +1545,7 @@ class CMD_SickBeardSearchIndexers(ApiCall):
'de': 14, 'da': 10, 'fi': 11, 'hu': 19, 'ja': 25, 'he': 24, 'ko': 32, 'de': 14, 'da': 10, 'fi': 11, 'hu': 19, 'ja': 25, 'he': 24, 'ko': 32,
'sv': 8, 'sl': 30} 'sv': 8, 'sl': 30}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
self.name, args = self.check_params(args, kwargs, "name", None, False, "string", []) self.name, args = self.check_params(args, kwargs, "name", None, False, "string", [])
@ -1551,7 +1554,7 @@ class CMD_SickBeardSearchIndexers(ApiCall):
self.indexer, args = self.check_params(args, kwargs, "indexer", None, False, "string", []) self.indexer, args = self.check_params(args, kwargs, "indexer", None, False, "string", [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" search for show at tvdb with a given string and language """ """ search for show at tvdb with a given string and language """
@ -1624,7 +1627,7 @@ class CMD_SickBeardSetDefaults(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
self.initial, args = self.check_params(args, kwargs, "initial", None, False, "list", self.initial, args = self.check_params(args, kwargs, "initial", None, False, "list",
@ -1638,7 +1641,7 @@ class CMD_SickBeardSetDefaults(ApiCall):
self.status, args = self.check_params(args, kwargs, "status", None, False, "string", self.status, args = self.check_params(args, kwargs, "status", None, False, "string",
["wanted", "skipped", "archived", "ignored"]) ["wanted", "skipped", "archived", "ignored"])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" set sickbeard user defaults """ """ set sickbeard user defaults """
@ -1693,11 +1696,11 @@ class CMD_SickBeardSetDefaults(ApiCall):
class CMD_SickBeardShutdown(ApiCall): class CMD_SickBeardShutdown(ApiCall):
_help = {"desc": "shutdown sickbeard"} _help = {"desc": "shutdown sickbeard"}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" shutdown sickbeard """ """ shutdown sickbeard """
@ -1711,12 +1714,12 @@ class CMD_Show(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display information for a given show """ """ display information for a given show """
@ -1779,7 +1782,7 @@ class CMD_ShowAddExisting(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
if "tvdbid" in args or "tvdbid" in kwargs: if "tvdbid" in args or "tvdbid" in kwargs:
_INDEXER_INT = 1 _INDEXER_INT = 1
_INDEXER = "tvdbid" _INDEXER = "tvdbid"
@ -1788,7 +1791,7 @@ class CMD_ShowAddExisting(ApiCall):
_INDEXER = "tvrageid" _INDEXER = "tvrageid"
else: else:
_INDEXER_INT = None _INDEXER_INT = None
_INDEXER = None _INDEXER = None
# required # required
self.indexerid, args = self.check_params(args, kwargs, _INDEXER, None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, _INDEXER, None, True, "int", [])
self.indexer = _INDEXER_INT self.indexer = _INDEXER_INT
@ -1805,7 +1808,7 @@ class CMD_ShowAddExisting(ApiCall):
self.subtitles, args = self.check_params(args, kwargs, "subtitles", int(sickbeard.USE_SUBTITLES), False, "int", self.subtitles, args = self.check_params(args, kwargs, "subtitles", int(sickbeard.USE_SUBTITLES), False, "int",
[]) [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" add a show in sickbeard with an existing folder """ """ add a show in sickbeard with an existing folder """
@ -1879,7 +1882,7 @@ class CMD_ShowAddNew(ApiCall):
'de': 14, 'da': 10, 'fi': 11, 'hu': 19, 'ja': 25, 'he': 24, 'ko': 32, 'de': 14, 'da': 10, 'fi': 11, 'hu': 19, 'ja': 25, 'he': 24, 'ko': 32,
'sv': 8, 'sl': 30} 'sv': 8, 'sl': 30}
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
if "tvdbid" in args or "tvdbid" in kwargs: if "tvdbid" in args or "tvdbid" in kwargs:
_INDEXER_INT = 1 _INDEXER_INT = 1
_INDEXER = "tvdbid" _INDEXER = "tvdbid"
@ -1888,7 +1891,7 @@ class CMD_ShowAddNew(ApiCall):
_INDEXER = "tvrageid" _INDEXER = "tvrageid"
else: else:
_INDEXER_INT = None _INDEXER_INT = None
_INDEXER = None _INDEXER = None
# required # required
self.indexerid, args = self.check_params(args, kwargs, _INDEXER, None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, _INDEXER, None, True, "int", [])
self.indexer = _INDEXER_INT self.indexer = _INDEXER_INT
@ -1908,7 +1911,7 @@ class CMD_ShowAddNew(ApiCall):
self.subtitles, args = self.check_params(args, kwargs, "subtitles", int(sickbeard.USE_SUBTITLES), False, "int", self.subtitles, args = self.check_params(args, kwargs, "subtitles", int(sickbeard.USE_SUBTITLES), False, "int",
[]) [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" add a show in sickbeard with an existing folder """ """ add a show in sickbeard with an existing folder """
@ -2009,12 +2012,12 @@ class CMD_ShowCache(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" check sickbeard's cache to see if the banner or poster image for a show is valid """ """ check sickbeard's cache to see if the banner or poster image for a show is valid """
@ -2044,12 +2047,12 @@ class CMD_ShowDelete(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" delete a show in sickbeard """ """ delete a show in sickbeard """
@ -2071,12 +2074,12 @@ class CMD_ShowGetQuality(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" get quality setting for a show in sickbeard """ """ get quality setting for a show in sickbeard """
@ -2095,12 +2098,12 @@ class CMD_ShowGetPoster(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" get the poster for a show in sickbeard """ """ get the poster for a show in sickbeard """
@ -2113,12 +2116,12 @@ class CMD_ShowGetBanner(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" get the banner for a show in sickbeard """ """ get the banner for a show in sickbeard """
@ -2133,13 +2136,13 @@ class CMD_ShowPause(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
self.pause, args = self.check_params(args, kwargs, "pause", 0, False, "bool", []) self.pause, args = self.check_params(args, kwargs, "pause", 0, False, "bool", [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" set a show's paused state in sickbeard """ """ set a show's paused state in sickbeard """
@ -2163,12 +2166,12 @@ class CMD_ShowRefresh(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" refresh a show in sickbeard """ """ refresh a show in sickbeard """
@ -2192,14 +2195,14 @@ class CMD_ShowSeasonList(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
self.sort, args = self.check_params(args, kwargs, "sort", "desc", False, "string", self.sort, args = self.check_params(args, kwargs, "sort", "desc", False, "string",
["asc", "desc"]) # "asc" and "desc" default and fallback is "desc" ["asc", "desc"]) # "asc" and "desc" default and fallback is "desc"
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display the season list for a given show """ """ display the season list for a given show """
@ -2230,13 +2233,13 @@ class CMD_ShowSeasons(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
self.season, args = self.check_params(args, kwargs, "season", None, False, "int", []) self.season, args = self.check_params(args, kwargs, "season", None, False, "int", [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display a listing of episodes for all or a given show """ """ display a listing of episodes for all or a given show """
@ -2295,7 +2298,7 @@ class CMD_ShowSetQuality(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
@ -2308,7 +2311,7 @@ class CMD_ShowSetQuality(ApiCall):
["sddvd", "hdtv", "rawhdtv", "fullhdtv", "hdwebdl", "fullhdwebdl", ["sddvd", "hdtv", "rawhdtv", "fullhdtv", "hdwebdl", "fullhdwebdl",
"hdbluray", "fullhdbluray"]) "hdbluray", "fullhdbluray"])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" set the quality for a show in sickbeard by taking in a deliminated """ set the quality for a show in sickbeard by taking in a deliminated
@ -2355,12 +2358,12 @@ class CMD_ShowStats(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display episode statistics for a given show """ """ display episode statistics for a given show """
@ -2460,12 +2463,12 @@ class CMD_ShowUpdate(ApiCall):
} }
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, True, "int", [])
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" update a show in sickbeard """ """ update a show in sickbeard """
@ -2488,13 +2491,13 @@ class CMD_Shows(ApiCall):
}, },
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
self.sort, args = self.check_params(args, kwargs, "sort", "id", False, "string", ["id", "name"]) self.sort, args = self.check_params(args, kwargs, "sort", "id", False, "string", ["id", "name"])
self.paused, args = self.check_params(args, kwargs, "paused", None, False, "bool", []) self.paused, args = self.check_params(args, kwargs, "paused", None, False, "bool", [])
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display_is_int_multi( self.indexerid )shows in sickbeard """ """ display_is_int_multi( self.indexerid )shows in sickbeard """
@ -2533,11 +2536,11 @@ class CMD_ShowsStats(ApiCall):
_help = {"desc": "display the global shows and episode stats" _help = {"desc": "display the global shows and episode stats"
} }
def __init__(self, args, kwargs): def __init__(self, handler, args, kwargs):
# required # required
# optional # optional
# super, missing, help # super, missing, help
ApiCall.__init__(self, args, kwargs) ApiCall.__init__(self, handler, args, kwargs)
def run(self): def run(self):
""" display the global shows and episode stats """ """ display the global shows and episode stats """

View file

@ -169,7 +169,7 @@ class MainHandler(RequestHandler):
path = self.request.uri.replace(sickbeard.WEB_ROOT, '').split('?')[0] path = self.request.uri.replace(sickbeard.WEB_ROOT, '').split('?')[0]
method = path.strip('/').split('/')[-1] method = path.strip('/').split('/')[-1]
if path.startswith('/api'): if path.startswith('/api') and method != 'builder':
apikey = path.strip('/').split('/')[-1] apikey = path.strip('/').split('/')[-1]
method = path.strip('/').split('/')[0] method = path.strip('/').split('/')[0]
self.request.arguments.update({'apikey': [apikey]}) self.request.arguments.update({'apikey': [apikey]})

View file

@ -73,7 +73,7 @@ def initWebServer(options={}):
# Main Handler # Main Handler
app.add_handlers(".*$", [ app.add_handlers(".*$", [
(r"/", RedirectHandler, {'url': '%s/home/' % options['web_root']}), (r"%s" % options['web_root'], RedirectHandler, {'url': '%s/home/' % options['web_root']}),
(r'%s/api/(.*)(/?)' % options['web_root'], webapi.Api), (r'%s/api/(.*)(/?)' % options['web_root'], webapi.Api),
(r'%s/(.*)(/?)' % options['web_root'], webserve.MainHandler) (r'%s/(.*)(/?)' % options['web_root'], webserve.MainHandler)
]) ])