mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2026-05-04 16:41:37 +00:00
Captions: Error checking
This commit is contained in:
parent
8e69928756
commit
c837828a22
2 changed files with 22 additions and 8 deletions
24
index.py
24
index.py
|
|
@ -92,17 +92,25 @@ class Second(object):
|
|||
@cherrypy.tools.json_out()
|
||||
def suggestions(self, *, q, **kwargs):
|
||||
return extract_search_suggestions(q)
|
||||
|
||||
|
||||
@cherrypy.expose
|
||||
def captions(self, id, **kwargs):
|
||||
result = extract_captions(id, **kwargs)
|
||||
if type(result) is dict:
|
||||
cherrypy.response.headers["content-type"] = "application/json"
|
||||
return bytes(json.dumps(result), "utf8")
|
||||
else:
|
||||
cherrypy.response.headers["content-type"] = "text/vtt; charset=UTF-8"
|
||||
return result
|
||||
try:
|
||||
result = extract_captions(id, **kwargs)
|
||||
if type(result) is dict:
|
||||
cherrypy.response.headers["content-type"] = "application/json"
|
||||
return bytes(json.dumps(result), "utf8")
|
||||
else:
|
||||
cherrypy.response.headers["content-type"] = "text/vtt; charset=UTF-8"
|
||||
return result
|
||||
|
||||
except StopIteration:
|
||||
cherrypy.response.status = "400"
|
||||
cherrypy.response.headers["content-type"] = "application/json"
|
||||
return bytes(json.dumps({
|
||||
"error": "No captions matching that language or label",
|
||||
"identifier": "NO_MATCHING_CAPTIONS"
|
||||
}), "utf8")
|
||||
|
||||
@cherrypy.expose
|
||||
def vi(self, id, file):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue