Unbewohnte
3 years ago
7 changed files with 132 additions and 21 deletions
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
package v2 |
||||
|
||||
import "testing" |
||||
|
||||
func Test_GetFIdentifierDescription(t *testing.T) { |
||||
description := GetFIdentifierDescription("TIT2") |
||||
|
||||
if description != "Title/songname/content description" { |
||||
t.Errorf("GetFIdentifierDescription failed: expected description for TIT2 to be %s, got %s", |
||||
"Title/songname/content description", description) |
||||
} |
||||
|
||||
description = GetFIdentifierDescription("TBP") |
||||
if description != "BPM (Beats Per Minute)" { |
||||
t.Errorf("GetFIdentifierDescription failed: expected description for TBP to be %s, got %s", |
||||
"BPM (Beats Per Minute)", description) |
||||
} |
||||
|
||||
description = GetFIdentifierDescription("SomeInvalidFrameIDName") |
||||
if description != "" { |
||||
t.Errorf("GetFIdentifierDescription failed: expected description for SomeInvalidFrameIDName to be \"\", got %s", |
||||
description) |
||||
} |
||||
} |
@ -1,6 +1,69 @@
|
||||
package v2 |
||||
|
||||
import "github.com/Unbewohnte/id3ed/util" |
||||
|
||||
type ID3v2Tag struct { |
||||
Header Header |
||||
Frames map[string]Frame |
||||
Frames []Frame |
||||
} |
||||
|
||||
// Searches for frame with the same identifier as id in tag,
|
||||
// returns &it if found
|
||||
func (tag *ID3v2Tag) GetFrame(id string) *Frame { |
||||
for _, frame := range tag.Frames { |
||||
if frame.Header.ID == id { |
||||
return &frame |
||||
} |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// Returns the contents for the title frame
|
||||
func (tag *ID3v2Tag) Title() string { |
||||
switch tag.Header.Version { |
||||
case V2_2: |
||||
return util.ToStringLossy(tag.GetFrame("TT2").Contents) |
||||
default: |
||||
return util.ToStringLossy(tag.GetFrame("TIT2").Contents) |
||||
} |
||||
} |
||||
|
||||
// Returns the contents for the album frame
|
||||
func (tag *ID3v2Tag) Album() string { |
||||
switch tag.Header.Version { |
||||
case V2_2: |
||||
return util.ToStringLossy(tag.GetFrame("TAL").Contents) |
||||
default: |
||||
return util.ToStringLossy(tag.GetFrame("TALB").Contents) |
||||
} |
||||
} |
||||
|
||||
// Returns the contents for the artist frame
|
||||
func (tag *ID3v2Tag) Artist() string { |
||||
switch tag.Header.Version { |
||||
case V2_2: |
||||
return util.ToStringLossy(tag.GetFrame("TP1").Contents) |
||||
default: |
||||
return util.ToStringLossy(tag.GetFrame("TPE1").Contents) |
||||
} |
||||
} |
||||
|
||||
// Returns the contents for the year frame
|
||||
func (tag *ID3v2Tag) Year() string { |
||||
switch tag.Header.Version { |
||||
case V2_2: |
||||
return util.ToStringLossy(tag.GetFrame("TYE").Contents) |
||||
default: |
||||
return util.ToStringLossy(tag.GetFrame("TYER").Contents) |
||||
} |
||||
} |
||||
|
||||
// Returns the contents for the comment frame
|
||||
func (tag *ID3v2Tag) Comment() string { |
||||
switch tag.Header.Version { |
||||
case V2_2: |
||||
return util.ToStringLossy(tag.GetFrame("COM").Contents) |
||||
default: |
||||
return util.ToStringLossy(tag.GetFrame("COMM").Contents) |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue