diff --git a/src/modules/stream/shared.js b/src/modules/stream/shared.js new file mode 100644 index 00000000..2f898c52 --- /dev/null +++ b/src/modules/stream/shared.js @@ -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] } +} \ No newline at end of file diff --git a/src/modules/stream/types.js b/src/modules/stream/types.js index b5320003..c8873381 100644 --- a/src/modules/stream/types.js +++ b/src/modules/stream/types.js @@ -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`)