mirror of
https://git.unlock-music.dev/um/cli.git
synced 2025-07-07 06:52:10 +08:00
feat(meta): separate flac meta process
This commit is contained in:
@ -39,11 +39,18 @@ type UpdateMetadataParams struct {
|
||||
|
||||
Meta common.AudioMeta // required
|
||||
|
||||
AlbumArt io.Reader // optional
|
||||
AlbumArtExt string // required if AlbumArt is not nil
|
||||
AlbumArt []byte // optional
|
||||
AlbumArtExt string // required if AlbumArt is not nil
|
||||
}
|
||||
|
||||
func UpdateAudioMetadata(ctx context.Context, outPath string, params *UpdateMetadataParams) error {
|
||||
func UpdateMeta(ctx context.Context, outPath string, params *UpdateMetadataParams) error {
|
||||
if params.AudioExt == ".flac" {
|
||||
return updateMetaFlac(ctx, outPath, params)
|
||||
} else {
|
||||
return updateMetaFFmpeg(ctx, outPath, params)
|
||||
}
|
||||
}
|
||||
func updateMetaFFmpeg(ctx context.Context, outPath string, params *UpdateMetadataParams) error {
|
||||
builder := newFFmpegBuilder()
|
||||
|
||||
out := newOutputBuilder(outPath) // output to file
|
||||
@ -60,7 +67,7 @@ func UpdateAudioMetadata(ctx context.Context, outPath string, params *UpdateMeta
|
||||
params.AudioExt != ".wav" /* wav doesn't support attached image */ {
|
||||
|
||||
// write cover to temp file
|
||||
artPath, err := utils.WriteTempFile(params.AlbumArt, params.AlbumArtExt)
|
||||
artPath, err := utils.WriteTempFile(bytes.NewReader(params.AlbumArt), params.AlbumArtExt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("updateAudioMeta write temp file: %w", err)
|
||||
}
|
||||
@ -77,6 +84,10 @@ func UpdateAudioMetadata(ctx context.Context, outPath string, params *UpdateMeta
|
||||
out.AddOption("disposition:v", "attached_pic")
|
||||
out.AddMetadata("s:v", "title", "Album cover")
|
||||
out.AddMetadata("s:v", "comment", "Cover (front)")
|
||||
case ".mp3":
|
||||
out.AddOption("codec:v", "mjpeg")
|
||||
out.AddMetadata("s:v", "title", "Album cover")
|
||||
out.AddMetadata("s:v", "comment", "Cover (front)")
|
||||
default: // other formats use default behavior
|
||||
}
|
||||
}
|
||||
@ -98,6 +109,11 @@ func UpdateAudioMetadata(ctx context.Context, outPath string, params *UpdateMeta
|
||||
out.AddMetadata("", "artist", strings.Join(artists, " / "))
|
||||
}
|
||||
|
||||
if params.AudioExt == ".mp3" {
|
||||
out.AddOption("write_id3v1", "true")
|
||||
out.AddOption("id3v2_version", "3")
|
||||
}
|
||||
|
||||
// execute ffmpeg
|
||||
cmd := builder.Command(ctx)
|
||||
|
||||
|
Reference in New Issue
Block a user