fix: backport fixes from a sister project
This commit is contained in:
15
ythdd_api.py
15
ythdd_api.py
@@ -4,6 +4,7 @@ from markupsafe import escape
|
||||
import requests, time, json
|
||||
import ythdd_globals
|
||||
import ythdd_api_v1, ythdd_inv_tl
|
||||
import traceback
|
||||
|
||||
def api_greeting():
|
||||
string = {'status': 200, 'msg': f"ok (ythdd {ythdd_globals.version})", 'latest_api': f"v{ythdd_globals.apiVersion}"}
|
||||
@@ -25,10 +26,15 @@ def api_global_catchall(received_request):
|
||||
#return api_greeting()
|
||||
resp = api_greeting()
|
||||
try:
|
||||
status, received, data = ythdd_api_v1.lookup(request_list)
|
||||
status, received, data = ythdd_api_v1.lookup(request_list, request)
|
||||
except Exception as e:
|
||||
ythdd_globals.apiFailedRequests += 1
|
||||
stripped_filename = __file__[max(__file__.rfind("/"), __file__.rfind("\\")) + 1:]
|
||||
print(f"\n{c.FAIL}Error! /api/{received_request} -> {stripped_filename}:L{e.__traceback__.tb_lineno} -> {type(e).__name__}{c.ENDC}:"
|
||||
+ f"{traceback.format_exc()}")
|
||||
status, received, data = 500, f"internal server error: call ended in failure: {e}", []
|
||||
if ythdd_globals.config["general"]["debug"]:
|
||||
status, received, data = 500, f"internal server error: call ended in failure: {e} ({stripped_filename}:L{e.__traceback__.tb_lineno})", []
|
||||
resp = Response(json.dumps({'status': status, 'msg': received, 'data': data}), mimetype='application/json', status=status)
|
||||
elif request_list[0] == 'invidious':
|
||||
# drop 'invidious' from the list
|
||||
@@ -43,12 +49,17 @@ def api_global_catchall(received_request):
|
||||
# if a path has been supplied try to get appropriate data
|
||||
try:
|
||||
# lookup and construct a response
|
||||
resp = ythdd_inv_tl.lookup(request_list)
|
||||
resp = ythdd_inv_tl.lookup(request_list, request)
|
||||
#print(resp) # for debugging purposes
|
||||
# unless an error occurs
|
||||
except Exception as e:
|
||||
ythdd_globals.apiFailedRequests += 1
|
||||
stripped_filename = __file__[max(__file__.rfind("/"), __file__.rfind("\\")) + 1:]
|
||||
print(f"\n{c.FAIL}Error! /api/{received_request} -> {stripped_filename}:L{e.__traceback__.tb_lineno} -> {type(e).__name__}{c.ENDC}:"
|
||||
+ f"{traceback.format_exc()}")
|
||||
status, received, data = 500, f"internal server error: invidious translation call ended in failure: {e}", []
|
||||
if ythdd_globals.config["general"]["debug"]:
|
||||
status, received, data = 500, f"internal server error: invidious translation call ended in failure: {e} ({stripped_filename}:L{e.__traceback__.tb_lineno})", []
|
||||
resp = Response(json.dumps({'status': status, 'msg': received, 'data': data}), mimetype='application/json', status=status)
|
||||
else:
|
||||
ythdd_globals.apiFailedRequests += 1
|
||||
|
||||
Reference in New Issue
Block a user