Revert "fix: override player function to set player_id to 7795af42
(retarded fix but works better than anything else)"
This reverts commit 001e2de64c
.
This commit is contained in:
parent
06cb1e10b0
commit
482ba815ad
2 changed files with 1 additions and 122 deletions
|
@ -4,7 +4,6 @@ import { JSDOM } from "jsdom";
|
|||
import { Innertube, UniversalCache } from "youtubei.js";
|
||||
import { Store } from "@willsoto/node-konfig-core";
|
||||
import { externalTokenGeneratorFail, poTokenFail } from "metrics";
|
||||
import { player } from "../../main.ts";
|
||||
let getFetchClientLocation = "getFetchClient";
|
||||
if (Deno.env.get("GET_FETCH_CLIENT_LOCATION")) {
|
||||
if (Deno.env.has("DENO_COMPILED")) {
|
||||
|
@ -129,20 +128,6 @@ export const poTokenGenerate = async (
|
|||
|
||||
await BG.PoToken.generatePlaceholder(visitorData);
|
||||
|
||||
const test = await Innertube.create({
|
||||
po_token: poTokenResult.poToken,
|
||||
visitor_data: visitorData,
|
||||
fetch: getFetchClient(konfigStore),
|
||||
cache: innertubeClientCache,
|
||||
generate_session_locally: true,
|
||||
retrieve_player: false,
|
||||
})
|
||||
|
||||
test.session.player = player
|
||||
test.session.player.po_token = poTokenResult.poToken
|
||||
|
||||
return test
|
||||
|
||||
return (await Innertube.create({
|
||||
po_token: poTokenResult.poToken,
|
||||
visitor_data: visitorData,
|
||||
|
|
108
src/main.ts
108
src/main.ts
|
@ -1,18 +1,8 @@
|
|||
import { Hono } from "hono";
|
||||
import { routes } from "./routes/index.ts";
|
||||
import {
|
||||
Constants,
|
||||
Innertube,
|
||||
Log,
|
||||
Platform,
|
||||
Player,
|
||||
UniversalCache,
|
||||
} from "youtubei.js";
|
||||
import { Innertube, UniversalCache } from "youtubei.js";
|
||||
import { poTokenGenerate } from "./lib/jobs/potoken.ts";
|
||||
import { konfigLoader } from "./lib/helpers/konfigLoader.ts";
|
||||
import { ICache } from "https://raw.githubusercontent.com/LuanRT/YouTube.js/refs/tags/v13.0.0-deno/deno/src/types/Cache.ts";
|
||||
import { FetchFunction } from "https://raw.githubusercontent.com/LuanRT/YouTube.js/refs/tags/v13.0.0-deno/deno/src/types/PlatformShim.ts";
|
||||
import { getRandomUserAgent, PlayerError } from "youtubei.js/Utils";
|
||||
import type { HonoVariables } from "./lib/types/HonoVariables.ts";
|
||||
let getFetchClientLocation = "getFetchClient";
|
||||
if (Deno.env.get("GET_FETCH_CLIENT_LOCATION")) {
|
||||
|
@ -89,102 +79,6 @@ innertubeClient = await Innertube.create({
|
|||
cookie: innertubeClientCookies || undefined,
|
||||
});
|
||||
|
||||
const TAG = "Player";
|
||||
|
||||
export default class CustomPlayer extends Player {
|
||||
constructor(
|
||||
signature_timestamp: number,
|
||||
sig_sc?: string,
|
||||
nsig_sc?: string,
|
||||
) {
|
||||
super("7795af42", signature_timestamp, sig_sc, nsig_sc);
|
||||
}
|
||||
|
||||
static override async create(
|
||||
cache: ICache | undefined,
|
||||
fetch: FetchFunction = Platform.shim.fetch,
|
||||
po_token?: string,
|
||||
): Promise<CustomPlayer> {
|
||||
const url = new URL("/iframe_api", Constants.URLS.YT_BASE);
|
||||
const res = await fetch(url);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new PlayerError(
|
||||
`Failed to get player id: ${res.status} (${res.statusText})`,
|
||||
);
|
||||
}
|
||||
|
||||
const player_id = "7795af42";
|
||||
|
||||
Log.info(
|
||||
TAG,
|
||||
`Got player id (${player_id}). Checking for cached players..`,
|
||||
);
|
||||
|
||||
if (!player_id) {
|
||||
throw new PlayerError("Failed to get player id");
|
||||
}
|
||||
|
||||
// We have the player id, now we can check if we have a cached player.
|
||||
if (cache) {
|
||||
const cached_player = await Player.fromCache(cache, player_id);
|
||||
if (cached_player) {
|
||||
Log.info(TAG, "Found up-to-date player data in cache.");
|
||||
cached_player.po_token = po_token;
|
||||
return cached_player;
|
||||
}
|
||||
}
|
||||
|
||||
const player_url = new URL(
|
||||
`/s/player/${player_id}/player_ias.vflset/en_US/base.js`,
|
||||
Constants.URLS.YT_BASE,
|
||||
);
|
||||
|
||||
Log.info(
|
||||
TAG,
|
||||
`Could not find any cached player. Will download a new player from ${player_url}.`,
|
||||
);
|
||||
|
||||
const player_res = await fetch(player_url, {
|
||||
headers: {
|
||||
"user-agent": getRandomUserAgent("desktop"),
|
||||
},
|
||||
});
|
||||
|
||||
if (!player_res.ok) {
|
||||
throw new PlayerError(
|
||||
`Failed to get player data: ${player_res.status}`,
|
||||
);
|
||||
}
|
||||
|
||||
const player_js = await player_res.text();
|
||||
|
||||
const sig_timestamp = this.extractSigTimestamp(player_js);
|
||||
const sig_sc = this.extractSigSourceCode(player_js);
|
||||
const nsig_sc = this.extractNSigSourceCode(player_js);
|
||||
|
||||
Log.info(
|
||||
TAG,
|
||||
`Got signature timestamp (${sig_timestamp}) and algorithms needed to decipher signatures.`,
|
||||
);
|
||||
|
||||
const player = await Player.fromSource(
|
||||
player_id,
|
||||
sig_timestamp,
|
||||
cache,
|
||||
sig_sc,
|
||||
nsig_sc,
|
||||
);
|
||||
player.po_token = po_token;
|
||||
|
||||
return player as CustomPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
export const player = await CustomPlayer.create(undefined);
|
||||
|
||||
innertubeClient.session.player = player;
|
||||
|
||||
const poTokenRefreshInterval = Deno.env.get("FREQUENCY_SECONDS") ||
|
||||
konfigStore.get("jobs.youtube_session.frequency_seconds");
|
||||
console.log("[INFO] po_token refresh interval set to", poTokenRefreshInterval);
|
||||
|
|
Reference in a new issue