From 8252a102b59415d1f95c3490f994a5cc5656253e Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 19 Oct 2024 11:59:27 -0400 Subject: [PATCH] Improve error messages on unplayable videos --- .../Services/Innertube/InnertubeService.bs | 30 ++++++++++++++++++- playlet-web/src/lib/Api/YoutubeJs.ts | 15 +++++++++- playlet-web/src/lib/LinkDragDrop.svelte | 2 ++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs index 7853ea25..f3f7e787 100644 --- a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs +++ b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs @@ -210,9 +210,37 @@ namespace InnertubeService end if if playabilityStatus["status"] <> "OK" + errorMessage = "" + if IsString(playabilityStatus["reason"]) + errorMessage = playabilityStatus["reason"] + end if + + subreason = ObjectUtils.Dig(playabilityStatus, ["errorScreen", "playerErrorMessageRenderer", "subreason"]) + if IsAssociativeArray(subreason) + subreasonText = "" + runs = subreason["runs"] + if IsArray(runs) + for each rn in runs + text = rn["text"] + if IsString(text) + subreasonText += text + end if + end for + end if + subreason = subreasonText + end if + + if IsString(subreason) + errorMessage += `\n` + subreason + end if + + if errorMessage = "" + errorMessage = "Video not available" + end if + return { Success: false - Error: playabilityStatus["reason"] + Error: errorMessage } end if diff --git a/playlet-web/src/lib/Api/YoutubeJs.ts b/playlet-web/src/lib/Api/YoutubeJs.ts index fda48397..b8e64b38 100644 --- a/playlet-web/src/lib/Api/YoutubeJs.ts +++ b/playlet-web/src/lib/Api/YoutubeJs.ts @@ -90,7 +90,20 @@ export class YoutubeJs { console.log('[YTJS] info:', info); if (info.playability_status.status !== 'OK') { - throw new Error(`Video not available: ${info.playability_status.reason}`); + let errorMessage = ""; + if (info.playability_status.reason) { + errorMessage = info.playability_status.reason; + } + if (info.playability_status.error_screen) { + if (info.playability_status.error_screen.hasKey('subreason')) { + const subreason = info.playability_status.error_screen.subreason; + if (subreason?.text && typeof subreason.text === 'string') { + errorMessage += `\n` + subreason.text; + } + } + } + + throw new Error(errorMessage); } // Populate a video object that is similar to Invidious format. diff --git a/playlet-web/src/lib/LinkDragDrop.svelte b/playlet-web/src/lib/LinkDragDrop.svelte index 17c9ff13..1aa658e1 100644 --- a/playlet-web/src/lib/LinkDragDrop.svelte +++ b/playlet-web/src/lib/LinkDragDrop.svelte @@ -115,6 +115,8 @@ videoStartAtTimestamp = timestamp; } videoModal.show(); + } catch (error) { + alert(error); } finally { isLoading = false; }