Skip to content

Commit

Permalink
normalised tag names, fixed failing test for missing genre tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hope authored and Sean Hope committed Oct 31, 2021
1 parent e7d29c6 commit a0b3d24
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 9 additions & 7 deletions vorbis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,37 @@ func New() *MetaDataBlockVorbisComment {
// empty list if the tag is not present. If there
// is no tag, error would still be nil
func (c *MetaDataBlockVorbisComment) Get(key string) ([]string, error) {
if value, exists := c.Comments[key]; exists {
if value, exists := c.Comments[strings.ToUpper(key)]; exists {
return value, nil
}
return []string{}, nil
}

// Add adds a value to an existing tag, or sets the tag if not present
func (c *MetaDataBlockVorbisComment) Add(key string, val string) error {
for _, char := range key {
stdKey := strings.ToUpper(key)
for _, char := range stdKey {
if char < 0x20 || char > 0x7d || char == '=' {
return ErrorInvalidFieldName
}
}
if xval, exists := c.Comments[key]; exists {
c.Comments[key] = append(xval, val)
if xval, exists := c.Comments[stdKey]; exists {
c.Comments[stdKey] = append(xval, val)
} else {
c.Comments[key] = []string{val}
c.Comments[stdKey] = []string{val}
}
return nil
}

// Sets sets a new tag or replaces replaces the value of a existing tag
func (c *MetaDataBlockVorbisComment) Set(key string, val []string) error {
for _, char := range key {
stdKey := strings.ToUpper(key)
for _, char := range stdKey {
if char < 0x20 || char > 0x7d || char == '=' {
return ErrorInvalidFieldName
}
}
c.Comments[key] = val
c.Comments[stdKey] = val
return nil
}

Expand Down
16 changes: 16 additions & 0 deletions vorbis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ func TestVorbisFromExistingFlac(t *testing.T) {
t.Error("Unexpected artist name: ", res)
t.Fail()
}

if res, err := cmt.Get(FIELD_TITLE); err != nil {
t.Error(err)
t.Fail()
} else if len(res) != 1 || res[0] != "Bee Moved" {
t.Error("Unexpected title name: ", res)
t.Fail()
}

if res, err := cmt.Get(FIELD_GENRE); err != nil {
t.Error(err)
t.Fail()
} else if len(res) != 0 {
t.Error("Unexpected genre: ", res)
t.Fail()
}
}
check(cmt)
new, err := ParseFromMetaDataBlock(cmt.Marshal())
Expand Down

0 comments on commit a0b3d24

Please sign in to comment.