From 1480876144e0af4b509c1466c27858f606e81a72 Mon Sep 17 00:00:00 2001 From: Xavier Henner Date: Sun, 26 Apr 2015 17:55:59 +0200 Subject: [PATCH] can have multiple frames with the same name. append a number from the second one --- id3v2.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/id3v2.go b/id3v2.go index 32017b9..f5275d9 100644 --- a/id3v2.go +++ b/id3v2.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "os" + "strconv" "strings" ) @@ -166,6 +167,17 @@ func readID3v2Frames(r io.Reader, h *ID3v2Header) (map[string]interface{}, error if err != nil { return nil, err } + + // There can be multiple tag with the same name. Append a number to the + // name if there is more than one. + if _, ok := result[name]; ok { + orig := name + for i := 0; ok; i++ { + _, ok = result[orig+"_"+strconv.Itoa(i)] + name = orig + "_" + strconv.Itoa(i) + } + } + offset += headerSize + size // Check this stuff out... @@ -200,14 +212,14 @@ func readID3v2Frames(r io.Reader, h *ID3v2Header) (map[string]interface{}, error } result[name] = txt - case name == "APIC": + case name[0:4] == "APIC": p, err := readAPICFrame(b) if err != nil { return nil, err } result[name] = p - case name == "PIC": + case name[0:3] == "PIC": p, err := readPICFrame(b) if err != nil { return nil, err