best way to save what you love
Svelte collaborationdownloaderinstagramjavascriptmusicredditsocial-mediasoundcloudsveltetiktoktwittertypescriptvideovimeovkwebappyoutubeyoutube-downloader
replace got with undici
dumbmoron814bfa404a24
diff --git a/package.json b/package.jsonindex 45ccbf51..0ed6132f 100644--- a/package.json+++ b/package.json@@ -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"diff --git a/src/modules/stream/stream.js b/src/modules/stream/stream.jsindex 0cc6ea86..4b03196b 100644--- a/src/modules/stream/stream.js+++ b/src/modules/stream/stream.js@@ -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) {diff --git a/src/modules/stream/types.js b/src/modules/stream/types.jsindex b5271095..a0dc68fb 100644--- a/src/modules/stream/types.js+++ b/src/modules/stream/types.js@@ -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',