mogultv/fetch_youtube-71c76849.js

62 lines
2.1 KiB
JavaScript

async function e(e) {
const t = await async function(e, t) {
const o = t.cookies.SAPISID || t.cookies["__Secure-3PAPISID"];
if (!o) return {
success: !1,
code: 400,
message: "Missing cookie"
};
const n = new URL(t.href).origin,
c = Math.floor(Date.now() / 1e3),
a = await async function(e) {
const t = await crypto.subtle.digest("SHA-1", (new TextEncoder).encode(e));
return Array.from(new Uint8Array(t)).map((e => e.toString(16).padStart(2, "0"))).join("")
}(`${c} ${o} ${n}`), s = {
"x-origin": n,
authorization: `SAPISIDHASH ${c}_${a}`,
"x-goog-authuser": t.authUser,
cookie: Object.entries(t.cookies).map((([e, t]) => `${e}=${t}`)).join(";")
};
t.pageId && (s["x-goog-pageid"] = t.pageId);
const i = await fetch(`https://www.youtube.com${e}?key=${t.key}`, {
method: "POST",
headers: s,
body: JSON.stringify({
context: t.context
})
});
return {
success: !0,
data: await i.json()
}
}("/youtubei/v1/account/account_menu", e);
if (!t.success) return t;
const o = t.data;
try {
const e = o.actions[0].openPopupAction.popup.multiPageMenuRenderer,
t = e.header.activeAccountHeaderRenderer,
n = e.sections[0].multiPageMenuSectionRenderer.items[0].compactLinkRenderer.navigationEndpoint.browseEndpoint.browseId.trim().replace(/\n/g, "");
return /^UC.{22}$/.test(n) ? {
success: !0,
data: {
id: n,
profile: t.accountPhoto.thumbnails[0].url,
username: t.accountName.simpleText
}
} : {
success: !1,
code: 400,
message: "Failed to authenticate"
}
} catch (e) {
return {
success: !1,
code: 400,
message: "Failed to authenticate"
}
}
}
export {
e
};