add support for external token generator
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 55s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 55s
This commit is contained in:
parent
d631aada71
commit
465878355b
2 changed files with 33 additions and 7 deletions
|
@ -22,8 +22,37 @@ export const poTokenGenerate = async (
|
|||
konfigStore: Store<Record<string, unknown>>,
|
||||
innertubeClientCache: UniversalCache,
|
||||
): Promise<Innertube> => {
|
||||
const externalTokenGenerator = konfigStore.get(
|
||||
"server.external_token_generator",
|
||||
) as string;
|
||||
const requestKey = "O43z0dpjhgX20SCx4KAo";
|
||||
|
||||
if (externalTokenGenerator != "" && externalTokenGenerator != undefined) {
|
||||
console.log(
|
||||
"poTokenGenerate: using external token generator at " +
|
||||
externalTokenGenerator,
|
||||
);
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${externalTokenGenerator}/generate`,
|
||||
);
|
||||
const data = await response.json();
|
||||
return (await Innertube.create({
|
||||
po_token: data.potoken,
|
||||
visitor_data: data.visitorData,
|
||||
fetch: getFetchClient(konfigStore),
|
||||
cache: innertubeClientCache,
|
||||
generate_session_locally: true,
|
||||
}));
|
||||
} catch (e) {
|
||||
console.error(
|
||||
"poTokenGenerate: error fetch token from the external token generator: " +
|
||||
e,
|
||||
);
|
||||
console.log("poTokenGenerate: Using built-in token generator");
|
||||
}
|
||||
}
|
||||
|
||||
if (innertubeClient.session.po_token) {
|
||||
innertubeClient = await Innertube.create({ retrieve_player: false });
|
||||
}
|
||||
|
|
11
src/main.ts
11
src/main.ts
|
@ -67,17 +67,12 @@ if (!innertubeClientOauthEnabled) {
|
|||
}
|
||||
setInterval(
|
||||
async () => {
|
||||
const currentDateTime = new Date();
|
||||
console.log("regenrate token called: " + currentDateTime)
|
||||
if (innertubeClientJobPoTokenEnabled) {
|
||||
innertubeClient = await poTokenGenerate(
|
||||
innertubeClient,
|
||||
konfigStore,
|
||||
innertubeClientCache,
|
||||
);
|
||||
const currentDateTimexd = new Date();
|
||||
console.log("regenerate token finished: " + currentDateTimexd)
|
||||
console.log("po_token: " + innertubeClient.session.po_token)
|
||||
} else {
|
||||
innertubeClient = await Innertube.create({
|
||||
cache: innertubeClientCache,
|
||||
|
@ -85,7 +80,9 @@ if (!innertubeClientOauthEnabled) {
|
|||
});
|
||||
}
|
||||
},
|
||||
konfigStore.get("jobs.youtube_session.frequency_seconds") as number * 1000 || 50000);
|
||||
konfigStore.get("jobs.youtube_session.frequency_seconds") as number *
|
||||
1000 || 50000,
|
||||
);
|
||||
} else if (innertubeClientOauthEnabled) {
|
||||
// Fired when waiting for the user to authorize the sign in attempt.
|
||||
innertubeClient.session.on("auth-pending", (data) => {
|
||||
|
@ -117,11 +114,11 @@ app.use("*", async (c, next) => {
|
|||
});
|
||||
|
||||
routes(app, konfigStore);
|
||||
|
||||
const https = Deno.env.get("HTTPS");
|
||||
const port = konfigStore.get("server.port") as number;
|
||||
const host = konfigStore.get("server.host") as string;
|
||||
|
||||
|
||||
if (https == "TRUE" || https == "true") {
|
||||
const cert = Deno.readTextFileSync("/data/cert.pem");
|
||||
const key = Deno.readTextFileSync("/data/key.key");
|
||||
|
|
Loading…
Reference in a new issue