api/youtube: catch even more innertube errors

This commit is contained in:
wukko 2024-11-23 15:37:42 +06:00
parent f1f9955159
commit 5b445d5c7e
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -143,13 +143,22 @@ export default async function(o) {
try {
info = await yt.getBasicInfo(o.id, useHLS ? 'IOS' : 'ANDROID');
} catch (e) {
if (e?.info?.reason === "This video is private") {
return { error: "content.video.private" };
} else if (e?.message === "This video is unavailable") {
return { error: "content.video.unavailable" };
} else {
return { error: "fetch.fail" };
if (e?.info) {
const errorInfo = JSON.parse(e?.info);
if (errorInfo?.reason === "This video is private") {
return { error: "content.video.private" };
}
if (["INVALID_ARGUMENT", "UNAUTHENTICATED"].includes(errorInfo?.error?.status)) {
return { error: "youtube.api_error" };
}
}
if (e?.message === "This video is unavailable") {
return { error: "content.video.unavailable" };
}
return { error: "fetch.fail" };
}
if (!info) return { error: "fetch.fail" };