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.
|
// Fired when waiting for the user to authorize the sign in attempt.
|
||||||
innertubeClient.session.on("auth-pending", (data) => {
|
innertubeClient.session.on("auth-pending", (data) => {
|
||||||
console.log(
|
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.
|
// Fired when authentication is successful.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { Innertube } from "youtubei.js";
|
import { FormatUtils, Innertube } from "youtubei.js";
|
||||||
import { HonoVariables } from "../../lib/types/HonoVariables.ts";
|
import { HonoVariables } from "../../lib/types/HonoVariables.ts";
|
||||||
import { Store } from "@willsoto/node-konfig-core";
|
import { Store } from "@willsoto/node-konfig-core";
|
||||||
import {
|
import {
|
||||||
|
@ -42,39 +42,35 @@ dashManifest.get("/:videoId", async (c) => {
|
||||||
.streaming_data.adaptive_formats
|
.streaming_data.adaptive_formats
|
||||||
.filter((i) => i.mime_type.includes("mp4"));
|
.filter((i) => i.mime_type.includes("mp4"));
|
||||||
|
|
||||||
const dashFile = await videoInfo.toDash(
|
const player_response = videoInfo.page[0];
|
||||||
// @ts-ignore URL is the same type as URLTransformer
|
// 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) => {
|
(url: URL) => {
|
||||||
const selectedItagFormat = videoInfo.streaming_data
|
let dashUrl = url;
|
||||||
?.adaptive_formats?.filter((i) => {
|
if (local) {
|
||||||
if (
|
// Can't create URL type without host part
|
||||||
i.itag == Number(url.searchParams.get("itag")) &&
|
dashUrl = (dashUrl.pathname + dashUrl.search + "&host=" +
|
||||||
i.is_drc === undefined
|
dashUrl.host) as unknown as URL;
|
||||||
) {
|
if (konfigStore.get("networking.ump") as boolean) {
|
||||||
return true;
|
dashUrl = dashUrl + "&ump=1" as unknown as URL;
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
|
return dashUrl;
|
||||||
|
} else {
|
||||||
|
return dashUrl;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
undefined,
|
||||||
|
videoInfo.cpn,
|
||||||
|
undefined,
|
||||||
|
innertubeClient.actions,
|
||||||
|
undefined,
|
||||||
|
captions,
|
||||||
|
undefined,
|
||||||
);
|
);
|
||||||
return c.text(dashFile.replaceAll("&", "&"));
|
return c.text(dashFile.replaceAll("&", "&"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,14 +53,13 @@ latestVersion.get("/", async (c) => {
|
||||||
});
|
});
|
||||||
} else if (selectedItagFormat) {
|
} else if (selectedItagFormat) {
|
||||||
const itagUrl = selectedItagFormat[0].url as string;
|
const itagUrl = selectedItagFormat[0].url as string;
|
||||||
let urlToRedirect = new URL(itagUrl);
|
const itagUrlParsed = new URL(itagUrl);
|
||||||
|
let urlToRedirect = itagUrlParsed.toString();
|
||||||
if (local) {
|
if (local) {
|
||||||
urlToRedirect = new URL(
|
urlToRedirect = itagUrlParsed.pathname + urlToRedirect.search +
|
||||||
urlToRedirect.pathname + urlToRedirect.search +
|
"&host=" + itagUrlParsed.host;
|
||||||
"&host=" + urlToRedirect.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") ||
|
"content-length": googlevideoResponse.headers.get("content-length") ||
|
||||||
"",
|
"",
|
||||||
"access-control-allow-origin": "*",
|
"access-control-allow-origin": "*",
|
||||||
"accept-ranges": googlevideoResponse.headers.get("accept-ranges") || "",
|
"accept-ranges": googlevideoResponse.headers.get("accept-ranges") || "",
|
||||||
"cache-control": googlevideoResponse.headers.get("cache-control") || "",
|
|
||||||
"content-type": googlevideoResponse.headers.get("content-type") || "",
|
"content-type": googlevideoResponse.headers.get("content-type") || "",
|
||||||
"expires": googlevideoResponse.headers.get("expires") || "",
|
"expires": googlevideoResponse.headers.get("expires") || "",
|
||||||
"last-modified": googlevideoResponse.headers.get("last-modified") || "",
|
"last-modified": googlevideoResponse.headers.get("last-modified") || "",
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Response(googlevideoResponse.body, {
|
return new Response(googlevideoResponse.body, {
|
||||||
status: rangeHeader ? 206 : googlevideoResponse.status,
|
status: googlevideoResponse.status,
|
||||||
statusText: googlevideoResponse.statusText,
|
statusText: googlevideoResponse.statusText,
|
||||||
headers: headersForResponse,
|
headers: headersForResponse,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue