mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-13 03:39:59 +00:00
stream: extract headers to shared file
This commit is contained in:
parent
ec746f57a7
commit
49eaa7d4ed
2 changed files with 23 additions and 19 deletions
21
src/modules/stream/shared.js
Normal file
21
src/modules/stream/shared.js
Normal 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] }
|
||||
}
|
|
@ -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`)
|
||||
|
|
Loading…
Reference in a new issue