|
|
|
@ -2,6 +2,7 @@ package ffmpeg
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
"mime"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
@ -11,7 +12,7 @@ import (
|
|
|
|
|
"golang.org/x/exp/slices"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams) error {
|
|
|
|
|
func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams, logger *zap.Logger) error {
|
|
|
|
|
f, err := flac.ParseFile(m.Audio)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -62,16 +63,18 @@ func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.AlbumArt != nil {
|
|
|
|
|
|
|
|
|
|
coverMime := mime.TypeByExtension(m.AlbumArtExt)
|
|
|
|
|
logger.Debug("cover image mime detect", zap.String("mime", coverMime))
|
|
|
|
|
cover, err := flacpicture.NewFromImageData(
|
|
|
|
|
flacpicture.PictureTypeFrontCover,
|
|
|
|
|
"Front cover",
|
|
|
|
|
m.AlbumArt,
|
|
|
|
|
mime.TypeByExtension(m.AlbumArtExt),
|
|
|
|
|
coverMime,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
logger.Warn("failed to create flac cover", zap.Error(err))
|
|
|
|
|
} else {
|
|
|
|
|
coverBlock := cover.Marshal()
|
|
|
|
|
f.Meta = append(f.Meta, &coverBlock)
|
|
|
|
|
|
|
|
|
@ -85,6 +88,7 @@ func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams)
|
|
|
|
|
f.Meta[coverIdx] = &coverBlock
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return f.Save(outPath)
|
|
|
|
|
}
|
|
|
|
|