From c20d4c34aa6ea557c5e2e21804ca26023e4cfb99 Mon Sep 17 00:00:00 2001 From: sherl Date: Mon, 22 Sep 2025 10:50:33 +0200 Subject: [PATCH] feat: check for playback errors and return them in invidious api fashion --- ythdd_inv_tl.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ythdd_inv_tl.py b/ythdd_inv_tl.py index 0dce6d1..f420c5f 100644 --- a/ythdd_inv_tl.py +++ b/ythdd_inv_tl.py @@ -93,19 +93,21 @@ def trending(): def popular(): return send(200, [{}]) -def getError(idata: dict): +def getError(wdata: dict): unknown_error = {"status": "Unknown error", "reason": "This is a generic ythdd error."} error = "" try: - playabilityStatus = safeTraverse(idata, ['stage1', 'playabilityStatus'], default=unknown_error) - print(playabilityStatus) + playabilityStatus = safeTraverse(wdata, ['ec1', 'playabilityStatus'], default=unknown_error) + # check for error + if safeTraverse(playabilityStatus, ["status"], default="error") == "OK": + return None # no error? return None error += f"({playabilityStatus['status']}) {playabilityStatus['reason']}" except: error += f"Generic error" try: - errorScreen = safeTraverse(idata, ['stage1', 'playabilityStatus', 'errorScreen', 'playerErrorMessageRenderer', 'subreason', 'runs'], default=[]) + errorScreen = safeTraverse(wdata, ['ec1', 'playabilityStatus', 'errorScreen', 'playerErrorMessageRenderer', 'subreason', 'runs'], default=[]) error += " - " for x in errorScreen: error += f"{x['text']} " @@ -349,9 +351,14 @@ def videos(data): else: del ythdd_globals.video_cache[data[3]] - ydata = ythdd_extractor.extract(data[3], manifest_fix=True) wdata = ythdd_extractor.WEBextractSinglePage(data[3]) + error = getError(wdata) + if error is not None: + return send(500, {"status": "error", "error": error}) + + ydata = ythdd_extractor.extract(data[3], manifest_fix=True) + #return send(200, {'ydata': ydata, 'wdata': wdata}) #return send(200, {'idata': idata, 'wdata': wdata})