mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-05 07:49:58 +00:00
commit
68b9a5321d
3 changed files with 16 additions and 13 deletions
|
@ -30,10 +30,10 @@
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"express-rate-limit": "^6.3.0",
|
"express-rate-limit": "^6.3.0",
|
||||||
"ffmpeg-static": "^5.1.0",
|
"ffmpeg-static": "^5.1.0",
|
||||||
"got": "^12.1.0",
|
|
||||||
"nanoid": "^4.0.2",
|
"nanoid": "^4.0.2",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
"set-cookie-parser": "2.6.0",
|
"set-cookie-parser": "2.6.0",
|
||||||
|
"undici": "^5.19.1",
|
||||||
"url-pattern": "1.0.3",
|
"url-pattern": "1.0.3",
|
||||||
"xml-js": "^1.6.11",
|
"xml-js": "^1.6.11",
|
||||||
"youtubei.js": "^5.4.0"
|
"youtubei.js": "^5.4.0"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { streamAudioOnly, streamDefault, streamLiveRender, streamVideoOnly } from "./types.js";
|
import { streamAudioOnly, streamDefault, streamLiveRender, streamVideoOnly } from "./types.js";
|
||||||
|
|
||||||
export default function(res, streamInfo) {
|
export default async function(res, streamInfo) {
|
||||||
try {
|
try {
|
||||||
if (streamInfo.isAudioOnly && streamInfo.type !== "bridge") {
|
if (streamInfo.isAudioOnly && streamInfo.type !== "bridge") {
|
||||||
streamAudioOnly(streamInfo, res);
|
streamAudioOnly(streamInfo, res);
|
||||||
|
@ -8,14 +8,14 @@ export default function(res, streamInfo) {
|
||||||
}
|
}
|
||||||
switch (streamInfo.type) {
|
switch (streamInfo.type) {
|
||||||
case "render":
|
case "render":
|
||||||
streamLiveRender(streamInfo, res);
|
await streamLiveRender(streamInfo, res);
|
||||||
break;
|
break;
|
||||||
case "videoM3U8":
|
case "videoM3U8":
|
||||||
case "mute":
|
case "mute":
|
||||||
streamVideoOnly(streamInfo, res);
|
streamVideoOnly(streamInfo, res);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
streamDefault(streamInfo, res);
|
await streamDefault(streamInfo, res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
import { spawn } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import ffmpeg from "ffmpeg-static";
|
import ffmpeg from "ffmpeg-static";
|
||||||
import got from "got";
|
|
||||||
import { ffmpegArgs, genericUserAgent } from "../config.js";
|
import { ffmpegArgs, genericUserAgent } from "../config.js";
|
||||||
import { getThreads, metadataManager } from "../sub/utils.js";
|
import { getThreads, metadataManager } from "../sub/utils.js";
|
||||||
|
import { request } from 'undici';
|
||||||
|
|
||||||
function fail(res) {
|
function fail(res) {
|
||||||
if (!res.headersSent) res.sendStatus(500);
|
if (!res.headersSent) res.sendStatus(500);
|
||||||
return res.destroy();
|
return res.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function streamDefault(streamInfo, res) {
|
export async function streamDefault(streamInfo, res) {
|
||||||
try {
|
try {
|
||||||
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1];
|
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1];
|
||||||
let regFilename = !streamInfo.mute ? streamInfo.filename : `${streamInfo.filename.split('.')[0]}_mute.${format}`;
|
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}"`);
|
res.setHeader('Content-disposition', `attachment; filename="${streamInfo.isAudioOnly ? `${streamInfo.filename}.${streamInfo.audioFormat}` : regFilename}"`);
|
||||||
const stream = got.get(streamInfo.urls, {
|
|
||||||
headers: {
|
const { body: stream, headers } = await request(streamInfo.urls, {
|
||||||
"user-agent": genericUserAgent
|
headers: { 'user-agent': genericUserAgent }
|
||||||
},
|
|
||||||
isStream: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
res.setHeader('content-type', headers['content-type']);
|
||||||
|
res.setHeader('content-length', headers['content-length']);
|
||||||
|
|
||||||
stream.pipe(res).on('error', () => fail(res));
|
stream.pipe(res).on('error', () => fail(res));
|
||||||
stream.on('error', () => fail(res));
|
stream.on('error', () => fail(res));
|
||||||
stream.on('aborted', () => fail(res));
|
stream.on('aborted', () => fail(res));
|
||||||
|
@ -27,11 +29,12 @@ export function streamDefault(streamInfo, res) {
|
||||||
fail(res);
|
fail(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export function streamLiveRender(streamInfo, res) {
|
export async function streamLiveRender(streamInfo, res) {
|
||||||
try {
|
try {
|
||||||
if (streamInfo.urls.length !== 2) return fail(res);
|
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],
|
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1],
|
||||||
args = [
|
args = [
|
||||||
'-loglevel', '-8',
|
'-loglevel', '-8',
|
||||||
|
|
Loading…
Reference in a new issue