mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-02 00:16:31 +01:00
api/stream/types: convert metadata in one place
also sanitize values & throw an error if tag isn't supported
This commit is contained in:
parent
6770738116
commit
1cbffc2d75
2 changed files with 23 additions and 20 deletions
|
@ -1,22 +1,3 @@
|
|||
export function convertMetadataToFFmpeg(obj) {
|
||||
const keys = Object.keys(obj);
|
||||
const tags = [
|
||||
"album",
|
||||
"copyright",
|
||||
"title",
|
||||
"artist",
|
||||
"track",
|
||||
"date"
|
||||
]
|
||||
let commands = []
|
||||
|
||||
for (const i in keys) {
|
||||
if (tags.includes(keys[i]))
|
||||
commands.push('-metadata', `${keys[i]}=${obj[keys[i]]}`)
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
export function getRedirectingURL(url) {
|
||||
return fetch(url, { redirect: 'manual' }).then((r) => {
|
||||
if ([301, 302, 303].includes(r.status) && r.headers.has('location'))
|
||||
|
|
|
@ -5,7 +5,6 @@ import { create as contentDisposition } from "content-disposition-header";
|
|||
|
||||
import { env } from "../config.js";
|
||||
import { destroyInternalStream } from "./manage.js";
|
||||
import { convertMetadataToFFmpeg } from "../misc/utils.js";
|
||||
import { hlsExceptions } from "../processing/service-config.js";
|
||||
import { getHeaders, closeRequest, closeResponse, pipe } from "./shared.js";
|
||||
|
||||
|
@ -16,6 +15,29 @@ const ffmpegArgs = {
|
|||
gif: ["-vf", "scale=-1:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse", "-loop", "0"]
|
||||
}
|
||||
|
||||
const metadataTags = [
|
||||
"album",
|
||||
"copyright",
|
||||
"title",
|
||||
"artist",
|
||||
"track",
|
||||
"date",
|
||||
];
|
||||
|
||||
const convertMetadataToFFmpeg = (metadata) => {
|
||||
let args = [];
|
||||
|
||||
for (const [ name, value ] of Object.entries(metadata)) {
|
||||
if (metadataTags.includes(name)) {
|
||||
args.push('-metadata', `${name}=${value.replace(/[\u0000-\u0009]/g, "")}`);
|
||||
} else {
|
||||
throw `${name} metadata tag is not supported.`;
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
const toRawHeaders = (headers) => {
|
||||
return Object.entries(headers)
|
||||
.map(([key, value]) => `${key}: ${value}\r\n`)
|
||||
|
|
Loading…
Reference in a new issue