improve dash manifest
This commit is contained in:
parent
4182701c03
commit
5ac9e62f41
4 changed files with 34 additions and 40 deletions
|
@ -76,7 +76,7 @@ if (!innertubeClientOauthEnabled) {
|
|||
// Fired when waiting for the user to authorize the sign in attempt.
|
||||
innertubeClient.session.on("auth-pending", (data) => {
|
||||
console.log(
|
||||
`Go to ${data.verification_url} in your browser and enter code ${data.user_code} to authenticate.`,
|
||||
`[INFO] [OAUTH] Go to ${data.verification_url} in your browser and enter code ${data.user_code} to authenticate.`,
|
||||
);
|
||||
});
|
||||
// Fired when authentication is successful.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Hono } from "hono";
|
||||
import { Innertube } from "youtubei.js";
|
||||
import { FormatUtils, Innertube } from "youtubei.js";
|
||||
import { HonoVariables } from "../../lib/types/HonoVariables.ts";
|
||||
import { Store } from "@willsoto/node-konfig-core";
|
||||
import {
|
||||
|
@ -42,39 +42,35 @@ dashManifest.get("/:videoId", async (c) => {
|
|||
.streaming_data.adaptive_formats
|
||||
.filter((i) => i.mime_type.includes("mp4"));
|
||||
|
||||
const dashFile = await videoInfo.toDash(
|
||||
// @ts-ignore URL is the same type as URLTransformer
|
||||
const player_response = videoInfo.page[0];
|
||||
// TODO: fix include storyboards in DASH manifest file
|
||||
//const storyboards = player_response.storyboards;
|
||||
const captions = player_response.captions?.caption_tracks;
|
||||
|
||||
const dashFile = await FormatUtils.toDash(
|
||||
videoInfo.streaming_data,
|
||||
videoInfo.page[0].video_details?.is_post_live_dvr,
|
||||
(url: URL) => {
|
||||
const selectedItagFormat = videoInfo.streaming_data
|
||||
?.adaptive_formats?.filter((i) => {
|
||||
if (
|
||||
i.itag == Number(url.searchParams.get("itag")) &&
|
||||
i.is_drc === undefined
|
||||
) {
|
||||
return true;
|
||||
} else if (
|
||||
i.itag == Number(url.searchParams.get("itag")) &&
|
||||
i.is_drc === url.search.includes("drc")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (selectedItagFormat) {
|
||||
let dashUrl = new URL(selectedItagFormat[0].url as string);
|
||||
if (local) {
|
||||
// Can't create URL type without host part
|
||||
dashUrl =
|
||||
(dashUrl.pathname + dashUrl.search + "&host=" +
|
||||
dashUrl.host) as unknown as URL;
|
||||
if (konfigStore.get("networking.ump") as boolean) {
|
||||
dashUrl = dashUrl + "&ump=1" as unknown as URL;
|
||||
}
|
||||
return dashUrl;
|
||||
} else {
|
||||
return dashUrl;
|
||||
let dashUrl = url;
|
||||
if (local) {
|
||||
// Can't create URL type without host part
|
||||
dashUrl = (dashUrl.pathname + dashUrl.search + "&host=" +
|
||||
dashUrl.host) as unknown as URL;
|
||||
if (konfigStore.get("networking.ump") as boolean) {
|
||||
dashUrl = dashUrl + "&ump=1" as unknown as URL;
|
||||
}
|
||||
return dashUrl;
|
||||
} else {
|
||||
return dashUrl;
|
||||
}
|
||||
},
|
||||
undefined,
|
||||
videoInfo.cpn,
|
||||
undefined,
|
||||
innertubeClient.actions,
|
||||
undefined,
|
||||
captions,
|
||||
undefined,
|
||||
);
|
||||
return c.text(dashFile.replaceAll("&", "&"));
|
||||
}
|
||||
|
|
|
@ -53,14 +53,13 @@ latestVersion.get("/", async (c) => {
|
|||
});
|
||||
} else if (selectedItagFormat) {
|
||||
const itagUrl = selectedItagFormat[0].url as string;
|
||||
let urlToRedirect = new URL(itagUrl);
|
||||
const itagUrlParsed = new URL(itagUrl);
|
||||
let urlToRedirect = itagUrlParsed.toString();
|
||||
if (local) {
|
||||
urlToRedirect = new URL(
|
||||
urlToRedirect.pathname + urlToRedirect.search +
|
||||
"&host=" + urlToRedirect.host
|
||||
);
|
||||
urlToRedirect = itagUrlParsed.pathname + urlToRedirect.search +
|
||||
"&host=" + itagUrlParsed.host;
|
||||
}
|
||||
return c.redirect(urlToRedirect.toString());
|
||||
return c.redirect(urlToRedirect);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -78,19 +78,18 @@ videoPlaybackProxy.get("/", async (c) => {
|
|||
);
|
||||
}
|
||||
|
||||
let headersForResponse = {
|
||||
const headersForResponse = {
|
||||
"content-length": googlevideoResponse.headers.get("content-length") ||
|
||||
"",
|
||||
"access-control-allow-origin": "*",
|
||||
"accept-ranges": googlevideoResponse.headers.get("accept-ranges") || "",
|
||||
"cache-control": googlevideoResponse.headers.get("cache-control") || "",
|
||||
"content-type": googlevideoResponse.headers.get("content-type") || "",
|
||||
"expires": googlevideoResponse.headers.get("expires") || "",
|
||||
"last-modified": googlevideoResponse.headers.get("last-modified") || "",
|
||||
};
|
||||
|
||||
return new Response(googlevideoResponse.body, {
|
||||
status: rangeHeader ? 206 : googlevideoResponse.status,
|
||||
status: googlevideoResponse.status,
|
||||
statusText: googlevideoResponse.statusText,
|
||||
headers: headersForResponse,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue