refactor: decouple tag writers from deezer models

This commit is contained in:
Mathis Maquenne
2026-08-05 11:37:59 +02:00
parent 3c9da5f24a
commit 16c71c8688
8 changed files with 265 additions and 201 deletions
+69
View File
@@ -0,0 +1,69 @@
package tag
import (
"path"
"github.com/bogem/id3v2/v2"
"github.com/go-flac/flacvorbis/v2"
"github.com/go-flac/go-flac/v2"
)
type AlbumMetadata struct {
Artist string
Title string
Label string
OriginalReleaseDate string
ReleaseDate string
ProducerLine string
Copyright string
}
type Metadata struct {
Title string
Artists string
Composers string
Lyricists string
Genre string
BPM string
Key string
TrackNumber string
Duration string
Gain string
ISRC string
Cover []byte
Album *AlbumMetadata
}
type tagger interface {
write(m Metadata) error
}
func newTagger(filePath string) (tagger, error) {
if path.Ext(filePath) == ".mp3" {
tag, err := id3v2.Open(filePath, id3v2.Options{Parse: true})
if err != nil {
return nil, err
}
return &id3v2Tagger{tag: tag}, nil
}
file, err := flac.ParseFile(filePath)
if err != nil {
return nil, err
}
cmts, idx := extractFLACComment(file)
if cmts == nil {
cmts = flacvorbis.New()
}
return &flacTagger{file: file, cmts: cmts, index: idx, path: filePath}, nil
}
func Write(filePath string, m Metadata) error {
t, err := newTagger(filePath)
if err != nil {
return err
}
return t.write(m)
}