fixing type errors
This commit is contained in:
parent
7ed48ad2af
commit
f36079d56c
1 changed files with 31 additions and 15 deletions
|
@ -1,7 +1,9 @@
|
||||||
import { Innertube, YT, ApiResponse } from "youtubei.js";
|
import { ApiResponse, Innertube, YT } from "youtubei.js";
|
||||||
import { generateRandomString } from "youtubei.js/Utils";
|
import { generateRandomString } from "youtubei.js/Utils";
|
||||||
import { compress, decompress } from "https://deno.land/x/brotli@0.1.7/mod.ts";
|
import { compress, decompress } from "https://deno.land/x/brotli@0.1.7/mod.ts";
|
||||||
const { youtubePlayerReq } = await import(Deno.env.get("YT_PLAYER_REQ_LOCATION") || "./youtubePlayerReq.ts");
|
const { youtubePlayerReq } = await import(
|
||||||
|
Deno.env.get("YT_PLAYER_REQ_LOCATION") || "./youtubePlayerReq.ts"
|
||||||
|
);
|
||||||
import { Store } from "@willsoto/node-konfig-core";
|
import { Store } from "@willsoto/node-konfig-core";
|
||||||
|
|
||||||
const kv = await Deno.openKv();
|
const kv = await Deno.openKv();
|
||||||
|
@ -22,7 +24,7 @@ export const youtubePlayerParsing = async (
|
||||||
const youtubePlayerResponse = await youtubePlayerReq(
|
const youtubePlayerResponse = await youtubePlayerReq(
|
||||||
innertubeClient,
|
innertubeClient,
|
||||||
videoId,
|
videoId,
|
||||||
konfigStore
|
konfigStore,
|
||||||
);
|
);
|
||||||
const videoData = youtubePlayerResponse.data;
|
const videoData = youtubePlayerResponse.data;
|
||||||
|
|
||||||
|
@ -36,16 +38,26 @@ export const youtubePlayerParsing = async (
|
||||||
|
|
||||||
// Modify the original YouTube response to include deciphered URLs
|
// Modify the original YouTube response to include deciphered URLs
|
||||||
if (streamingData && videoData && videoData.streamingData) {
|
if (streamingData && videoData && videoData.streamingData) {
|
||||||
const ecatcherServiceTracking = videoData.responseContext?.serviceTrackingParams.find(o => o.service === 'ECATCHER');
|
const ecatcherServiceTracking = videoData.responseContext
|
||||||
const clientNameUsed = ecatcherServiceTracking?.params?.find(o => o.key === 'client.name');
|
?.serviceTrackingParams.find((o: { service: string }) =>
|
||||||
|
o.service === "ECATCHER"
|
||||||
|
);
|
||||||
|
const clientNameUsed = ecatcherServiceTracking?.params?.find((
|
||||||
|
o: { key: string },
|
||||||
|
) => o.key === "client.name");
|
||||||
// no need to decipher on IOS nor ANDROID
|
// no need to decipher on IOS nor ANDROID
|
||||||
if (!clientNameUsed?.value.includes("IOS") && !clientNameUsed?.value.includes("ANDROID")) {
|
if (
|
||||||
|
!clientNameUsed?.value.includes("IOS") &&
|
||||||
|
!clientNameUsed?.value.includes("ANDROID")
|
||||||
|
) {
|
||||||
for (const [index, format] of streamingData.formats.entries()) {
|
for (const [index, format] of streamingData.formats.entries()) {
|
||||||
videoData.streamingData.formats[index].url = format.decipher(
|
videoData.streamingData.formats[index].url = format
|
||||||
innertubeClient.session.player,
|
.decipher(
|
||||||
);
|
innertubeClient.session.player,
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
videoData.streamingData.formats[index].signatureCipher !==
|
videoData.streamingData.formats[index]
|
||||||
|
.signatureCipher !==
|
||||||
undefined
|
undefined
|
||||||
) {
|
) {
|
||||||
delete videoData.streamingData.formats[index]
|
delete videoData.streamingData.formats[index]
|
||||||
|
@ -53,7 +65,8 @@ export const youtubePlayerParsing = async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (
|
for (
|
||||||
const [index, adaptive_format] of streamingData.adaptive_formats
|
const [index, adaptive_format] of streamingData
|
||||||
|
.adaptive_formats
|
||||||
.entries()
|
.entries()
|
||||||
) {
|
) {
|
||||||
videoData.streamingData.adaptiveFormats[index].url =
|
videoData.streamingData.adaptiveFormats[index].url =
|
||||||
|
@ -90,11 +103,14 @@ export const youtubePlayerParsing = async (
|
||||||
videoDetails,
|
videoDetails,
|
||||||
microformat,
|
microformat,
|
||||||
invidiousCompanion: {
|
invidiousCompanion: {
|
||||||
"baseUrl": Deno.env.get("SERVER_BASE_URL") || konfigStore.get("server.base_url") as string,
|
"baseUrl": Deno.env.get("SERVER_BASE_URL") ||
|
||||||
|
konfigStore.get("server.base_url") as string,
|
||||||
},
|
},
|
||||||
}))(videoData);
|
}))(videoData);
|
||||||
|
|
||||||
if (cacheEnabled == true && videoData.playabilityStatus?.status == "OK") {
|
if (
|
||||||
|
cacheEnabled == true && videoData.playabilityStatus?.status == "OK"
|
||||||
|
) {
|
||||||
(async () => {
|
(async () => {
|
||||||
await kv.set(
|
await kv.set(
|
||||||
["video_cache", videoId],
|
["video_cache", videoId],
|
||||||
|
@ -116,7 +132,7 @@ export const youtubePlayerParsing = async (
|
||||||
|
|
||||||
export const youtubeVideoInfo = (
|
export const youtubeVideoInfo = (
|
||||||
innertubeClient: Innertube,
|
innertubeClient: Innertube,
|
||||||
youtubePlayerResponseJson: object
|
youtubePlayerResponseJson: object,
|
||||||
): YT.VideoInfo => {
|
): YT.VideoInfo => {
|
||||||
const playerResponse = {
|
const playerResponse = {
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -128,4 +144,4 @@ export const youtubeVideoInfo = (
|
||||||
innertubeClient.actions,
|
innertubeClient.actions,
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue