fix: temporary player_id override until an official fix cames out
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m4s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m4s
This commit is contained in:
parent
117d934ca9
commit
b766210c00
7 changed files with 169 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
|||
From e78a26c4f36bac6cb20d9c45568116c72c745d24 Mon Sep 17 00:00:00 2001
|
||||
From 93d8817ad62d43f1077bc199589bb0a2a023f255 Mon Sep 17 00:00:00 2001
|
||||
From: Fijxu <fijxu@nadeko.net>
|
||||
Date: Mon, 24 Mar 2025 18:44:10 -0300
|
||||
Subject: [PATCH 1/6] feat: add support for an external videoplayback proxy
|
||||
Subject: [PATCH 1/7] feat: add support for an external videoplayback proxy
|
||||
|
||||
---
|
||||
config/config.example.toml | 1 +
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
From 004c812e80ad15f2a6699aaa69c8c4a2112b6830 Mon Sep 17 00:00:00 2001
|
||||
From 9316c695cb8dfa7bbeff988dbf75d3645d7fe766 Mon Sep 17 00:00:00 2001
|
||||
From: Fijxu <fijxu@nadeko.net>
|
||||
Date: Mon, 24 Mar 2025 18:52:53 -0300
|
||||
Subject: [PATCH 2/6] feat: report the external videoplayback proxy via /info
|
||||
Subject: [PATCH 2/7] feat: report the external videoplayback proxy via /info
|
||||
endpoint
|
||||
|
||||
---
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
From 58287cea5d7224147187376b74e2287e9e369ccb Mon Sep 17 00:00:00 2001
|
||||
From bcc993ffefc44e1d3b2678cb2ffe8bbd4f1eee62 Mon Sep 17 00:00:00 2001
|
||||
From: Fijxu <fijxu@nadeko.net>
|
||||
Date: Mon, 24 Mar 2025 19:02:01 -0300
|
||||
Subject: [PATCH 3/6] feat: add resolution limit on DASH streams to save
|
||||
Subject: [PATCH 3/7] feat: add resolution limit on DASH streams to save
|
||||
bandwidth
|
||||
|
||||
---
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
From 4c9f43edffabeb8367fb74ef3017bec9a39227c6 Mon Sep 17 00:00:00 2001
|
||||
From b0c833a79cf2060ce994fdcd5945800accc0af9c Mon Sep 17 00:00:00 2001
|
||||
From: Fijxu <fijxu@nadeko.net>
|
||||
Date: Mon, 24 Mar 2025 19:06:04 -0300
|
||||
Subject: [PATCH 4/6] feat: add env variable to set verify_requests
|
||||
Subject: [PATCH 4/7] feat: add env variable to set verify_requests
|
||||
|
||||
---
|
||||
src/lib/helpers/config.ts | 4 +++-
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
From 41f9a63113fc05a9f332a49dc85d14920066be0f Mon Sep 17 00:00:00 2001
|
||||
From 4854d4765775914294f9663f0ce7c498ce2bbc2c Mon Sep 17 00:00:00 2001
|
||||
From: Fijxu <fijxu@nadeko.net>
|
||||
Date: Mon, 24 Mar 2025 19:20:52 -0300
|
||||
Subject: [PATCH 5/6] feat: add support for multiple proxies
|
||||
Subject: [PATCH 5/7] feat: add support for multiple proxies
|
||||
|
||||
---
|
||||
src/lib/helpers/getFetchClient.ts | 17 ++++++++++++++++-
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
From 9205a5b19f7f5e351bf00a30bbc7717bac321524 Mon Sep 17 00:00:00 2001
|
||||
From 44bc921cc4600607b41f3b919b3751ac85c43e8b Mon Sep 17 00:00:00 2001
|
||||
From: Fijxu <fijxu@nadeko.net>
|
||||
Date: Mon, 24 Mar 2025 19:37:34 -0300
|
||||
Subject: [PATCH 6/6] ci: update deno to 2.2.4
|
||||
Subject: [PATCH 6/7] ci: update deno to 2.2.4
|
||||
|
||||
---
|
||||
Dockerfile | 2 +-
|
||||
|
|
|
@ -0,0 +1,157 @@
|
|||
From 8fc7011f718f8227371758a7b5f848f7d049627d Mon Sep 17 00:00:00 2001
|
||||
From: Fijxu <fijxu@nadeko.net>
|
||||
Date: Mon, 24 Mar 2025 20:06:47 -0300
|
||||
Subject: [PATCH 7/7] 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
|
||||
|
Loading…
Add table
Reference in a new issue