mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-01 06:44:24 +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 { addItem } from "$lib/state/queen-bee/queue";
|
||||||
import { openQueuePopover } from "$lib/state/queue-visibility";
|
import { openQueuePopover } from "$lib/state/queue-visibility";
|
||||||
|
import { ffmpegMetadataArgs } from "$lib/util";
|
||||||
|
|
||||||
import type { CobaltPipelineItem } from "$lib/types/workers";
|
import type { CobaltPipelineItem } from "$lib/types/workers";
|
||||||
import type { CobaltLocalProcessingResponse, CobaltSaveRequestBody } from "$lib/types/api";
|
import type { CobaltLocalProcessingResponse, CobaltSaveRequestBody } from "$lib/types/api";
|
||||||
@ -80,7 +81,8 @@ export const createSavePipeline = (info: CobaltLocalProcessingResponse, request:
|
|||||||
workerArgs: {
|
workerArgs: {
|
||||||
ffargs: [
|
ffargs: [
|
||||||
"-c:v", "copy",
|
"-c:v", "copy",
|
||||||
"-c:a", "copy"
|
"-c:a", "copy",
|
||||||
|
...(info.output.metadata ? ffmpegMetadataArgs(info.output.metadata) : [])
|
||||||
],
|
],
|
||||||
output: {
|
output: {
|
||||||
type: info.output.type,
|
type: info.output.type,
|
||||||
|
@ -43,6 +43,19 @@ type CobaltTunnelResponse = {
|
|||||||
status: CobaltResponseType.Tunnel,
|
status: CobaltResponseType.Tunnel,
|
||||||
} & CobaltPartialURLResponse;
|
} & CobaltPartialURLResponse;
|
||||||
|
|
||||||
|
export const CobaltFileMetadataKeys = [
|
||||||
|
'album',
|
||||||
|
'copyright',
|
||||||
|
'title',
|
||||||
|
'artist',
|
||||||
|
'track',
|
||||||
|
'date'
|
||||||
|
];
|
||||||
|
|
||||||
|
export type CobaltFileMetadata = Record<
|
||||||
|
typeof CobaltFileMetadataKeys[number], string | undefined
|
||||||
|
>;
|
||||||
|
|
||||||
export type CobaltLocalProcessingResponse = {
|
export type CobaltLocalProcessingResponse = {
|
||||||
status: CobaltResponseType.LocalProcessing,
|
status: CobaltResponseType.LocalProcessing,
|
||||||
|
|
||||||
@ -54,14 +67,7 @@ export type CobaltLocalProcessingResponse = {
|
|||||||
output: {
|
output: {
|
||||||
type: string, // mimetype
|
type: string, // mimetype
|
||||||
filename: string,
|
filename: string,
|
||||||
metadata?: {
|
metadata?: CobaltFileMetadata,
|
||||||
album?: string,
|
|
||||||
copyright?: string,
|
|
||||||
title?: string,
|
|
||||||
artist?: string,
|
|
||||||
track?: string,
|
|
||||||
date?: string
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
audio?: {
|
audio?: {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { CobaltFileMetadataKeys, type CobaltFileMetadata } from "$lib/types/api";
|
||||||
|
|
||||||
export const formatFileSize = (size: number | undefined) => {
|
export const formatFileSize = (size: number | undefined) => {
|
||||||
size ||= 0;
|
size ||= 0;
|
||||||
|
|
||||||
@ -12,3 +14,15 @@ export const formatFileSize = (size: number | undefined) => {
|
|||||||
const unit = units[units.length - 1] + "B";
|
const unit = units[units.length - 1] + "B";
|
||||||
return `${roundedSize} ${unit}`;
|
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