stream: fix bilibili downloads

fixes #302
This commit is contained in:
dumbmoron 2024-02-15 01:27:19 +00:00
parent d80d37e936
commit d70754238e
No known key found for this signature in database
GPG key ID: C59997C76C6A8E5F

View file

@ -80,17 +80,33 @@ export async function streamLiveRender(streamInfo, res) {
if (streamInfo.urls.length !== 2) return shutdown(); if (streamInfo.urls.length !== 2) return shutdown();
const { body: audio } = await request(streamInfo.urls[1], { const { body: audio } = await request(streamInfo.urls[1], {
maxRedirections: 16, signal: abortController.signal maxRedirections: 16, signal: abortController.signal,
headers: {
'user-agent': genericUserAgent,
referer: streamInfo.service === 'bilibili'
? 'https://www.bilibili.com/'
: undefined,
}
}); });
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], const format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1];
args = [ let args = [
'-loglevel', '-8', '-loglevel', '-8',
'-user_agent', genericUserAgent
];
if (streamInfo.service === 'bilibili') {
args.push(
'-headers', 'Referer: https://www.bilibili.com/\r\n',
)
}
args.push(
'-i', streamInfo.urls[0], '-i', streamInfo.urls[0],
'-i', 'pipe:3', '-i', 'pipe:3',
'-map', '0:v', '-map', '0:v',
'-map', '1:a', '-map', '1:a',
]; );
args = args.concat(ffmpegArgs[format]); args = args.concat(ffmpegArgs[format]);
if (streamInfo.metadata) { if (streamInfo.metadata) {
@ -129,11 +145,16 @@ export function streamAudioOnly(streamInfo, res) {
try { try {
let args = [ let args = [
'-loglevel', '-8' '-loglevel', '-8',
] '-user_agent', genericUserAgent
];
if (streamInfo.service === "twitter") { if (streamInfo.service === "twitter") {
args.push('-seekable', '0') args.push('-seekable', '0');
} else if (streamInfo.service === 'bilibili') {
args.push('-headers', 'Referer: https://www.bilibili.com/\r\n');
} }
args.push( args.push(
'-i', streamInfo.urls, '-i', streamInfo.urls,
'-vn' '-vn'
@ -178,17 +199,23 @@ export function streamVideoOnly(streamInfo, res) {
let args = [ let args = [
'-loglevel', '-8' '-loglevel', '-8'
] ]
if (streamInfo.service === "twitter") { if (streamInfo.service === "twitter") {
args.push('-seekable', '0') args.push('-seekable', '0')
} else if (streamInfo.service === 'bilibili') {
args.push('-headers', 'Referer: https://www.bilibili.com/\r\n')
} }
args.push( args.push(
'-i', streamInfo.urls, '-i', streamInfo.urls,
'-c', 'copy' '-c', 'copy'
) )
if (streamInfo.mute) { if (streamInfo.mute) {
args.push('-an') args.push('-an')
} }
if (streamInfo.service === "vimeo" || streamInfo.service === "rutube") {
if (['vimeo', 'rutube'].includes(streamInfo.service)) {
args.push('-bsf:a', 'aac_adtstoasc') args.push('-bsf:a', 'aac_adtstoasc')
} }