From eef1ffcbbd25dcc902890022a504933164293074 Mon Sep 17 00:00:00 2001 From: Xavier Henner Date: Fri, 22 May 2015 01:20:55 +0200 Subject: [PATCH] Support for the UFID tag --- id3v2.go | 7 +++++++ id3v2frames.go | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/id3v2.go b/id3v2.go index 37ed734..894623d 100644 --- a/id3v2.go +++ b/id3v2.go @@ -225,6 +225,13 @@ func readID3v2Frames(r io.Reader, h *ID3v2Header) (map[string]interface{}, error } result[rawName] = txt + case name == "UFID" || name == "UFI": + t, err := readUfid(b) + if err != nil { + return nil, err + } + result[rawName] = t + case name == "WXXX" || name == "WXX": t, err := readTextWithDescrFrame(b, false, false) // no lang, no enc if err != nil { diff --git a/id3v2frames.go b/id3v2frames.go index 979bb29..b1b7967 100644 --- a/id3v2frames.go +++ b/id3v2frames.go @@ -195,6 +195,26 @@ func readTextWithDescrFrame(b []byte, hasLang bool, encoded bool) (*Comm, error) }, nil } +// UFID is composed of a provider (frequently an URL and a binary identifier) +// The identifier can be a text (Musicbrainz use texts, but not necessary) +type Ufid struct { + Provider string + Identifier []byte +} + +func (u Ufid) String() string { + return fmt.Sprintf("%v (%v)", u.Provider, string(u.Identifier)) +} + +func readUfid(b []byte) (*Ufid, error) { + result := bytes.SplitN(b, []byte{0}, 2) + + return &Ufid{ + Provider: string(result[0]), + Identifier: result[1], + }, nil +} + var pictureTypes = map[byte]string{ 0x00: "Other", 0x01: "32x32 pixels 'file icon' (PNG only)",