|
|
@ -2,6 +2,7 @@ package ffmpeg
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"mime"
|
|
|
|
"mime"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
@ -11,7 +12,7 @@ import (
|
|
|
|
"golang.org/x/exp/slices"
|
|
|
|
"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)
|
|
|
|
f, err := flac.ParseFile(m.Audio)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -62,27 +63,30 @@ func updateMetaFlac(_ context.Context, outPath string, m *UpdateMetadataParams)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if m.AlbumArt != nil {
|
|
|
|
if m.AlbumArt != nil {
|
|
|
|
|
|
|
|
coverMime := mime.TypeByExtension(m.AlbumArtExt)
|
|
|
|
|
|
|
|
logger.Debug("cover image mime detect", zap.String("mime", coverMime))
|
|
|
|
cover, err := flacpicture.NewFromImageData(
|
|
|
|
cover, err := flacpicture.NewFromImageData(
|
|
|
|
flacpicture.PictureTypeFrontCover,
|
|
|
|
flacpicture.PictureTypeFrontCover,
|
|
|
|
"Front cover",
|
|
|
|
"Front cover",
|
|
|
|
m.AlbumArt,
|
|
|
|
m.AlbumArt,
|
|
|
|
mime.TypeByExtension(m.AlbumArtExt),
|
|
|
|
coverMime,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
coverBlock := cover.Marshal()
|
|
|
|
|
|
|
|
f.Meta = append(f.Meta, &coverBlock)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add / replace flac cover
|
|
|
|
if err != nil {
|
|
|
|
coverIdx := slices.IndexFunc(f.Meta, func(b *flac.MetaDataBlock) bool {
|
|
|
|
logger.Warn("failed to create flac cover", zap.Error(err))
|
|
|
|
return b.Type == flac.Picture
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if coverIdx < 0 {
|
|
|
|
|
|
|
|
f.Meta = append(f.Meta, &coverBlock)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
f.Meta[coverIdx] = &coverBlock
|
|
|
|
coverBlock := cover.Marshal()
|
|
|
|
|
|
|
|
f.Meta = append(f.Meta, &coverBlock)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add / replace flac cover
|
|
|
|
|
|
|
|
coverIdx := slices.IndexFunc(f.Meta, func(b *flac.MetaDataBlock) bool {
|
|
|
|
|
|
|
|
return b.Type == flac.Picture
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if coverIdx < 0 {
|
|
|
|
|
|
|
|
f.Meta = append(f.Meta, &coverBlock)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
f.Meta[coverIdx] = &coverBlock
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|