All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m5s
157 lines
5.9 KiB
Diff
157 lines
5.9 KiB
Diff
From 1809787ec91c57bb273a26f42f56bb9c8450789e Mon Sep 17 00:00:00 2001
|
|
From: Fijxu <fijxu@nadeko.net>
|
|
Date: Mon, 24 Mar 2025 20:06:47 -0300
|
|
Subject: [PATCH 7/9] fix: temporary player_id override until an official fix
|
|
cames out
|
|
|
|
---
|
|
deno.lock | 2 +
|
|
src/lib/jobs/potoken.ts | 5 +++
|
|
src/main.ts | 90 ++++++++++++++++++++++++++++++++++++++++-
|
|
3 files changed, 96 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/deno.lock b/deno.lock
|
|
index 338ad71..27d8ae6 100644
|
|
--- a/deno.lock
|
|
+++ b/deno.lock
|
|
@@ -451,6 +451,8 @@
|
|
"https://esm.sh/@bufbuild/protobuf@2.0.0/wire": "eb1be07dad5823fc419cc9e6f62077a70962ce42facb1a5240b7d5c3674e852f",
|
|
"https://esm.sh/bgutils-js@3.2.0": "9691c575e7f81d8c2652260f59356b5de97a242fc8b464dbba880a543f6ce075",
|
|
"https://esm.sh/bgutils-js@3.2.0/denonext/bgutils-js.mjs": "9acd0267c5bf7273ba122a295f97795cb81d0f6d001db708c92548ac82977f93",
|
|
+ "https://raw.githubusercontent.com/LuanRT/YouTube.js/refs/tags/v13.0.0-deno/deno/src/types/Cache.ts": "06cd238bce7c9657055151587e36ee445e8236d54d27272124ced10ea7be0da4",
|
|
+ "https://raw.githubusercontent.com/LuanRT/YouTube.js/refs/tags/v13.0.0-deno/deno/src/types/PlatformShim.ts": "06f656f0d2bc20980ef77148455b662af10fe4b0e48d41566bf28e471eea4be1",
|
|
"https://raw.githubusercontent.com/LuanRT/YouTube.js/refs/tags/v13.1.0-deno/deno.ts": "f913bfdb3c66b2330fa8b531bd1e291437b836c9fbf002b9ae044bf14e1f397c",
|
|
"https://raw.githubusercontent.com/LuanRT/YouTube.js/refs/tags/v13.1.0-deno/deno/package.json": "4e1d16c0f95a2b58dc6dba7e0fe969b800794a6040ae02116e14eae2444e4429",
|
|
"https://raw.githubusercontent.com/LuanRT/YouTube.js/refs/tags/v13.1.0-deno/deno/protos/generated/misc/common.ts": "7d6ca8d7cd7eafe1f8d5ddc11c440566c418aeaf2d8a03a72eced7466a691039",
|
|
diff --git a/src/lib/jobs/potoken.ts b/src/lib/jobs/potoken.ts
|
|
index 6867082..233ac32 100644
|
|
--- a/src/lib/jobs/potoken.ts
|
|
+++ b/src/lib/jobs/potoken.ts
|
|
@@ -1,3 +1,4 @@
|
|
+import { player } from "../../main.ts";
|
|
import { BG, buildURL, GOOG_API_KEY, USER_AGENT } from "bgutils";
|
|
import type { WebPoSignalOutput } from "bgutils";
|
|
import { JSDOM } from "jsdom";
|
|
@@ -133,8 +134,12 @@ export const poTokenGenerate = async (
|
|
fetch: getFetchClient(config),
|
|
cache: innertubeClientCache,
|
|
generate_session_locally: true,
|
|
+ retrieve_player: false,
|
|
});
|
|
|
|
+ instantiatedInnertubeClient.session.player = player;
|
|
+ instantiatedInnertubeClient.session.player.po_token = sessionPoToken;
|
|
+
|
|
try {
|
|
const feed = await instantiatedInnertubeClient.getTrending();
|
|
// get all videos and shuffle them randomly to avoid using the same trending video over and over
|
|
diff --git a/src/main.ts b/src/main.ts
|
|
index a792fee..b57cdc5 100644
|
|
--- a/src/main.ts
|
|
+++ b/src/main.ts
|
|
@@ -1,6 +1,17 @@
|
|
import { Hono } from "hono";
|
|
import { routes } from "./routes/index.ts";
|
|
-import { Innertube, UniversalCache } from "youtubei.js";
|
|
+import {
|
|
+ Constants,
|
|
+ Innertube,
|
|
+ Log,
|
|
+ Platform,
|
|
+ Player,
|
|
+ UniversalCache,
|
|
+} from "youtubei.js";
|
|
+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 { poTokenGenerate } from "./lib/jobs/potoken.ts";
|
|
import { USER_AGENT } from "bgutils";
|
|
import { retry } from "@std/async";
|
|
@@ -64,6 +75,83 @@ innertubeClient = await Innertube.create({
|
|
user_agent: USER_AGENT,
|
|
});
|
|
|
|
+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 player_id = "7795af42";
|
|
+
|
|
+ Log.info(
|
|
+ `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) {
|
|
+ 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,
|
|
+ );
|
|
+
|
|
+ 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(
|
|
+ `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;
|
|
+
|
|
if (!innertubeClientOauthEnabled) {
|
|
if (innertubeClientJobPoTokenEnabled) {
|
|
({ innertubeClient, tokenMinter } = await retry(
|
|
--
|
|
2.49.0
|
|
|