add support for external token generator
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 47s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 47s
This commit is contained in:
parent
d631aada71
commit
21451a59c7
1 changed files with 58 additions and 20 deletions
78
src/main.ts
78
src/main.ts
|
@ -50,6 +50,10 @@ if (!innertubeClientOauthEnabled) {
|
||||||
innertubeClientCache = new UniversalCache(false);
|
innertubeClientCache = new UniversalCache(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const externalTokenGenerator = konfigStore.get(
|
||||||
|
"server.external_token_generator",
|
||||||
|
) as string;
|
||||||
|
|
||||||
innertubeClient = await Innertube.create({
|
innertubeClient = await Innertube.create({
|
||||||
cache: innertubeClientCache,
|
cache: innertubeClientCache,
|
||||||
retrieve_player: innertubeClientFetchPlayer,
|
retrieve_player: innertubeClientFetchPlayer,
|
||||||
|
@ -65,27 +69,62 @@ if (!innertubeClientOauthEnabled) {
|
||||||
innertubeClientCache as UniversalCache,
|
innertubeClientCache as UniversalCache,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
setInterval(
|
if (externalTokenGenerator != "" && externalTokenGenerator != undefined) {
|
||||||
async () => {
|
console.log(
|
||||||
const currentDateTime = new Date();
|
"using external token generator at " + externalTokenGenerator,
|
||||||
console.log("regenrate token called: " + currentDateTime)
|
);
|
||||||
if (innertubeClientJobPoTokenEnabled) {
|
setInterval(async () => {
|
||||||
innertubeClient = await poTokenGenerate(
|
try {
|
||||||
innertubeClient,
|
const response = await fetch(
|
||||||
konfigStore,
|
`${externalTokenGenerator}/generate`,
|
||||||
innertubeClientCache,
|
|
||||||
);
|
);
|
||||||
const currentDateTimexd = new Date();
|
const data = await response.json();
|
||||||
console.log("regenerate token finished: " + currentDateTimexd)
|
innertubeClient.session.po_token = data.potoken;
|
||||||
console.log("po_token: " + innertubeClient.session.po_token)
|
innertubeClient.session.context.client.visitorData =
|
||||||
} else {
|
data.visitorData;
|
||||||
innertubeClient = await Innertube.create({
|
console.log(data.potoken);
|
||||||
cache: innertubeClientCache,
|
console.log(data.visitorData);
|
||||||
retrieve_player: innertubeClientFetchPlayer,
|
} catch (e) {
|
||||||
});
|
console.log("error fetch token: " + e);
|
||||||
}
|
}
|
||||||
},
|
}, 5000);
|
||||||
konfigStore.get("jobs.youtube_session.frequency_seconds") as number * 1000 || 50000);
|
} else {
|
||||||
|
console.log(
|
||||||
|
"using internal token generator",
|
||||||
|
);
|
||||||
|
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,
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"visitor_data: " +
|
||||||
|
innertubeClient.session.context.client.visitorData,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
innertubeClient = await Innertube.create({
|
||||||
|
cache: innertubeClientCache,
|
||||||
|
retrieve_player: innertubeClientFetchPlayer,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
konfigStore.get(
|
||||||
|
"jobs.youtube_session.frequency_seconds",
|
||||||
|
) as number * 1000 || 50000,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else if (innertubeClientOauthEnabled) {
|
} else if (innertubeClientOauthEnabled) {
|
||||||
// Fired when waiting for the user to authorize the sign in attempt.
|
// Fired when waiting for the user to authorize the sign in attempt.
|
||||||
innertubeClient.session.on("auth-pending", (data) => {
|
innertubeClient.session.on("auth-pending", (data) => {
|
||||||
|
@ -121,7 +160,6 @@ const https = Deno.env.get("HTTPS");
|
||||||
const port = konfigStore.get("server.port") as number;
|
const port = konfigStore.get("server.port") as number;
|
||||||
const host = konfigStore.get("server.host") as string;
|
const host = konfigStore.get("server.host") as string;
|
||||||
|
|
||||||
|
|
||||||
if (https == "TRUE" || https == "true") {
|
if (https == "TRUE" || https == "true") {
|
||||||
const cert = Deno.readTextFileSync("/data/cert.pem");
|
const cert = Deno.readTextFileSync("/data/cert.pem");
|
||||||
const key = Deno.readTextFileSync("/data/key.key");
|
const key = Deno.readTextFileSync("/data/key.key");
|
||||||
|
|
Loading…
Reference in a new issue