mirror of
https://github.com/wukko/cobalt.git
synced 2025-04-29 22:14:26 +02:00
web: use metadata when processing media locally
This commit is contained in:
parent
3acfe7462a
commit
1ad7c778e5
@ -1,5 +1,6 @@
|
||||
import { addItem } from "$lib/state/queen-bee/queue";
|
||||
import { openQueuePopover } from "$lib/state/queue-visibility";
|
||||
import { ffmpegMetadataArgs } from "$lib/util";
|
||||
|
||||
import type { CobaltPipelineItem } from "$lib/types/workers";
|
||||
import type { CobaltLocalProcessingResponse, CobaltSaveRequestBody } from "$lib/types/api";
|
||||
@ -80,7 +81,8 @@ export const createSavePipeline = (info: CobaltLocalProcessingResponse, request:
|
||||
workerArgs: {
|
||||
ffargs: [
|
||||
"-c:v", "copy",
|
||||
"-c:a", "copy"
|
||||
"-c:a", "copy",
|
||||
...(info.output.metadata ? ffmpegMetadataArgs(info.output.metadata) : [])
|
||||
],
|
||||
output: {
|
||||
type: info.output.type,
|
||||
|
@ -43,6 +43,19 @@ type CobaltTunnelResponse = {
|
||||
status: CobaltResponseType.Tunnel,
|
||||
} & CobaltPartialURLResponse;
|
||||
|
||||
export const CobaltFileMetadataKeys = [
|
||||
'album',
|
||||
'copyright',
|
||||
'title',
|
||||
'artist',
|
||||
'track',
|
||||
'date'
|
||||
];
|
||||
|
||||
export type CobaltFileMetadata = Record<
|
||||
typeof CobaltFileMetadataKeys[number], string | undefined
|
||||
>;
|
||||
|
||||
export type CobaltLocalProcessingResponse = {
|
||||
status: CobaltResponseType.LocalProcessing,
|
||||
|
||||
@ -54,14 +67,7 @@ export type CobaltLocalProcessingResponse = {
|
||||
output: {
|
||||
type: string, // mimetype
|
||||
filename: string,
|
||||
metadata?: {
|
||||
album?: string,
|
||||
copyright?: string,
|
||||
title?: string,
|
||||
artist?: string,
|
||||
track?: string,
|
||||
date?: string
|
||||
},
|
||||
metadata?: CobaltFileMetadata,
|
||||
},
|
||||
|
||||
audio?: {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { CobaltFileMetadataKeys, type CobaltFileMetadata } from "$lib/types/api";
|
||||
|
||||
export const formatFileSize = (size: number | undefined) => {
|
||||
size ||= 0;
|
||||
|
||||
@ -12,3 +14,15 @@ export const formatFileSize = (size: number | undefined) => {
|
||||
const unit = units[units.length - 1] + "B";
|
||||
return `${roundedSize} ${unit}`;
|
||||
}
|
||||
|
||||
export const ffmpegMetadataArgs = (metadata: CobaltFileMetadata) =>
|
||||
Object.entries(metadata).flatMap(([name, value]) => {
|
||||
if (CobaltFileMetadataKeys.includes(name) && typeof value === "string") {
|
||||
return [
|
||||
'-metadata',
|
||||
// eslint-disable-next-line no-control-regex
|
||||
`${name}=${value.replace(/[\u0000-\u0009]/g, "")}`
|
||||
]
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user