fix: add support for sensitive content videos
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m19s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m19s
This commit is contained in:
parent
4a21526be1
commit
f266edfedb
3 changed files with 36 additions and 2 deletions
|
@ -3,6 +3,7 @@ import { generateRandomString } from "youtubei.js/Utils";
|
|||
import { compress, decompress } from "https://deno.land/x/brotli@0.1.7/mod.ts";
|
||||
import { Store } from "@willsoto/node-konfig-core";
|
||||
import { failedRequests, successfulRequests, retryCount } from "metrics";
|
||||
import { innertubeEmbeddedClient } from "../../main.ts";
|
||||
let youtubePlayerReqLocation = "youtubePlayerReq";
|
||||
if (Deno.env.get("YT_PLAYER_REQ_LOCATION")) {
|
||||
if (Deno.env.has("DENO_COMPILED")) {
|
||||
|
@ -65,6 +66,28 @@ export const youtubePlayerParsing = async (
|
|||
);
|
||||
}
|
||||
|
||||
if (
|
||||
youtubePlayerResponse.data.playabilityStatus.status === "UNPLAYABLE" ||
|
||||
youtubePlayerResponse.data.playabilityStatus.status === "LOGIN_REQUIRED" ||
|
||||
youtubePlayerResponse.data.playabilityStatus.status === "CONTENT_CHECK_REQUIRED" ||
|
||||
youtubePlayerResponse.data.playabilityStatus.reason === "Sign in to confirm your age"
|
||||
) {
|
||||
innertubeEmbeddedClient.session.context.client.visitorData =
|
||||
innertubeClient.session.context.client.visitorData;
|
||||
if (innertubeClient.session.po_token) {
|
||||
innertubeEmbeddedClient.session.po_token =
|
||||
innertubeClient.session.po_token;
|
||||
}
|
||||
innertubeEmbeddedClient.session.player =
|
||||
innertubeClient.session.player;
|
||||
|
||||
youtubePlayerResponse = await youtubePlayerReq(
|
||||
innertubeEmbeddedClient,
|
||||
videoId,
|
||||
konfigStore,
|
||||
);
|
||||
}
|
||||
|
||||
const videoData = youtubePlayerResponse.data;
|
||||
|
||||
const video = new YT.VideoInfo(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ApiResponse, Innertube } from "youtubei.js";
|
||||
import { ApiResponse, ClientType, Innertube } from "youtubei.js";
|
||||
import { Store } from "@willsoto/node-konfig-core";
|
||||
import NavigationEndpoint from "youtubei.js/NavigationEndpoint";
|
||||
|
||||
|
@ -15,6 +15,9 @@ export const youtubePlayerReq = async (
|
|||
if (innertubeClientOauthEnabled) {
|
||||
innertubeClientUsed = "TV";
|
||||
}
|
||||
if (innertubeClient.session.client_name == ClientType.WEB_EMBEDDED) {
|
||||
innertubeClientUsed = "WEB_EMBEDDED"
|
||||
}
|
||||
|
||||
const watch_endpoint = new NavigationEndpoint({
|
||||
watchEndpoint: { videoId: videoId },
|
||||
|
|
10
src/main.ts
10
src/main.ts
|
@ -1,6 +1,6 @@
|
|||
import { Hono } from "hono";
|
||||
import { routes } from "./routes/index.ts";
|
||||
import { Innertube, UniversalCache } from "youtubei.js";
|
||||
import { ClientType, Innertube, UniversalCache } from "youtubei.js";
|
||||
import { poTokenGenerate } from "./lib/jobs/potoken.ts";
|
||||
import { konfigLoader } from "./lib/helpers/konfigLoader.ts";
|
||||
import type { HonoVariables } from "./lib/types/HonoVariables.ts";
|
||||
|
@ -79,6 +79,14 @@ innertubeClient = await Innertube.create({
|
|||
cookie: innertubeClientCookies || undefined,
|
||||
});
|
||||
|
||||
export const innertubeEmbeddedClient = await Innertube.create({
|
||||
cache: innertubeClientCache,
|
||||
client_type: ClientType.WEB_EMBEDDED,
|
||||
retrieve_player: false,
|
||||
fetch: getFetchClient(konfigStore),
|
||||
cookie: innertubeClientCookies || undefined,
|
||||
});
|
||||
|
||||
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