stream: extract headers to shared file

This commit is contained in:
dumbmoron 2024-04-27 10:59:27 +00:00
parent ec746f57a7
commit 49eaa7d4ed
No known key found for this signature in database
2 changed files with 23 additions and 19 deletions

View file

@ -0,0 +1,21 @@
import { genericUserAgent } from "../config.js";
const defaultHeaders = {
'user-agent': genericUserAgent
}
const serviceHeaders = {
bilibili: {
referer: 'https://www.bilibili.com/'
},
youtube: {
accept: '*/*',
origin: 'https://www.youtube.com',
referer: 'https://www.youtube.com',
DNT: '?1'
}
}
export function getHeaders(service) {
return { ...defaultHeaders, ...serviceHeaders[service] }
}

View file

@ -5,26 +5,9 @@ import { create as contentDisposition } from "content-disposition-header";
import { metadataManager } from "../sub/utils.js";
import { destroyInternalStream } from "./manage.js";
import { ffmpegArgs, genericUserAgent } from "../config.js";
import { ffmpegArgs } from "../config.js";
import { getHeaders } from "./shared.js";
const defaultHeaders = {
'user-agent': genericUserAgent
}
const serviceHeaders = {
bilibili: {
referer: 'https://www.bilibili.com/'
},
youtube: {
accept: '*/*',
origin: 'https://www.youtube.com',
referer: 'https://www.youtube.com',
DNT: '?1'
}
}
function getHeaders(service) {
return { ...defaultHeaders, ...serviceHeaders[service] }
}
function toRawHeaders(headers) {
return Object.entries(headers)
.map(([key, value]) => `${key}: ${value}\r\n`)