replace got with undici

might as well since it already comes with youtubei.js
This commit is contained in:
dumbmoron 2023-08-20 14:44:34 +00:00
parent 244357820d
commit 814bfa404a
3 changed files with 12 additions and 13 deletions

View file

@ -30,10 +30,10 @@
"express": "^4.18.1",
"express-rate-limit": "^6.3.0",
"ffmpeg-static": "^5.1.0",
"got": "^12.1.0",
"nanoid": "^4.0.2",
"node-cache": "^5.1.2",
"set-cookie-parser": "2.6.0",
"undici": "^5.19.1",
"url-pattern": "1.0.3",
"xml-js": "^1.6.11",
"youtubei.js": "^5.4.0"

View file

@ -1,6 +1,6 @@
import { streamAudioOnly, streamDefault, streamLiveRender, streamVideoOnly } from "./types.js";
export default function(res, streamInfo) {
export default async function(res, streamInfo) {
try {
if (streamInfo.isAudioOnly && streamInfo.type !== "bridge") {
streamAudioOnly(streamInfo, res);
@ -8,14 +8,14 @@ export default function(res, streamInfo) {
}
switch (streamInfo.type) {
case "render":
streamLiveRender(streamInfo, res);
await streamLiveRender(streamInfo, res);
break;
case "videoM3U8":
case "mute":
streamVideoOnly(streamInfo, res);
break;
default:
streamDefault(streamInfo, res);
await streamDefault(streamInfo, res);
break;
}
} catch (e) {

View file

@ -1,24 +1,22 @@
import { spawn } from "child_process";
import ffmpeg from "ffmpeg-static";
import got from "got";
import { ffmpegArgs, genericUserAgent } from "../config.js";
import { getThreads, metadataManager, msToTime } from "../sub/utils.js";
import { request } from 'undici';
function fail(res) {
if (!res.headersSent) res.sendStatus(500);
return res.destroy();
}
export function streamDefault(streamInfo, res) {
export async function streamDefault(streamInfo, res) {
try {
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1];
let regFilename = !streamInfo.mute ? streamInfo.filename : `${streamInfo.filename.split('.')[0]}_mute.${format}`;
res.setHeader('Content-disposition', `attachment; filename="${streamInfo.isAudioOnly ? `${streamInfo.filename}.${streamInfo.audioFormat}` : regFilename}"`);
const stream = got.get(streamInfo.urls, {
headers: {
"user-agent": genericUserAgent
},
isStream: true
const { body: stream } = await request(streamInfo.urls, {
headers: { 'user-agent': genericUserAgent }
});
stream.pipe(res).on('error', () => fail(res));
stream.on('error', () => fail(res));
@ -27,11 +25,12 @@ export function streamDefault(streamInfo, res) {
fail(res);
}
}
export function streamLiveRender(streamInfo, res) {
export async function streamLiveRender(streamInfo, res) {
try {
if (streamInfo.urls.length !== 2) return fail(res);
let audio = got.get(streamInfo.urls[1], { isStream: true });
let { body: audio } = await request(streamInfo.urls[1]);
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1],
args = [
'-loglevel', '-8',