Skip to content

Commit

Permalink
Improve error messages on unplayable videos
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Oct 19, 2024
1 parent 9562493 commit 8252a10
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 14 additions & 1 deletion playlet-web/src/lib/Api/YoutubeJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions playlet-web/src/lib/LinkDragDrop.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
videoStartAtTimestamp = timestamp;
}
videoModal.show();
} catch (error) {
alert(error);
} finally {
isLoading = false;
}
Expand Down

0 comments on commit 8252a10

Please sign in to comment.