fix: resolve bugs found in pre-release review
This commit is contained in:
+30
-16
@@ -3,6 +3,7 @@ package tag
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/bogem/id3v2/v2"
|
||||
)
|
||||
@@ -14,20 +15,19 @@ type id3v2Tagger struct {
|
||||
func (t *id3v2Tagger) write(m Metadata) error {
|
||||
defer t.tag.Close()
|
||||
|
||||
duration, err := strconv.Atoi(m.Duration)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
length := fmt.Sprintf("%d", duration*1000)
|
||||
|
||||
if m.Album != nil {
|
||||
year := m.Album.ReleaseDate
|
||||
if parts := strings.Split(year, "-"); len(parts) == 3 {
|
||||
year = parts[0]
|
||||
}
|
||||
|
||||
t.addTag("TRCK", m.TrackNumber)
|
||||
t.addTag("TPE2", m.Album.Artist)
|
||||
t.addTag("TALB", m.Album.Title)
|
||||
t.addTag("TPUB", m.Album.Label)
|
||||
t.addTag("TDOR", m.Album.OriginalReleaseDate)
|
||||
t.addTag("TYER", m.Album.ReleaseDate)
|
||||
t.addTag("COMM", m.Album.ProducerLine)
|
||||
t.addTag("TYER", year)
|
||||
t.addComment(m.Album.ProducerLine)
|
||||
t.addTag("TCOP", m.Album.Copyright)
|
||||
}
|
||||
|
||||
@@ -36,19 +36,23 @@ func (t *id3v2Tagger) write(m Metadata) error {
|
||||
t.addTag("TCOM", m.Composers)
|
||||
t.addTag("TEXT", m.Lyricists)
|
||||
t.addTag("TCON", m.Genre)
|
||||
t.addTag("TLEN", length)
|
||||
if duration, err := strconv.Atoi(m.Duration); err == nil {
|
||||
t.addTag("TLEN", fmt.Sprintf("%d", duration*1000))
|
||||
}
|
||||
t.addTag("TBPM", m.BPM)
|
||||
t.addTag("TKEY", m.Key)
|
||||
t.addTXXX("GAIN", m.Gain)
|
||||
t.addTXXX("ISRC", m.ISRC)
|
||||
|
||||
t.tag.AddAttachedPicture(id3v2.PictureFrame{
|
||||
Encoding: t.tag.DefaultEncoding(),
|
||||
MimeType: "image/jpeg",
|
||||
PictureType: id3v2.PTFrontCover,
|
||||
Description: "Cover",
|
||||
Picture: m.Cover,
|
||||
})
|
||||
if len(m.Cover) > 0 {
|
||||
t.tag.AddAttachedPicture(id3v2.PictureFrame{
|
||||
Encoding: t.tag.DefaultEncoding(),
|
||||
MimeType: "image/jpeg",
|
||||
PictureType: id3v2.PTFrontCover,
|
||||
Description: "Cover",
|
||||
Picture: m.Cover,
|
||||
})
|
||||
}
|
||||
|
||||
return t.tag.Save()
|
||||
}
|
||||
@@ -59,6 +63,16 @@ func (t *id3v2Tagger) addTag(name, value string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *id3v2Tagger) addComment(value string) {
|
||||
if value != "" {
|
||||
t.tag.AddCommentFrame(id3v2.CommentFrame{
|
||||
Encoding: t.tag.DefaultEncoding(),
|
||||
Language: "eng",
|
||||
Text: value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (t *id3v2Tagger) addTXXX(description, value string) {
|
||||
if value != "" {
|
||||
t.tag.AddUserDefinedTextFrame(id3v2.UserDefinedTextFrame{
|
||||
|
||||
Reference in New Issue
Block a user