diff --git a/id3v2.go b/id3v2.go index d5b3b26..dda6135 100644 --- a/id3v2.go +++ b/id3v2.go @@ -219,7 +219,7 @@ func readID3v2Frames(r io.Reader, h *ID3v2Header) (map[string]interface{}, error result[rawName] = t case name[0] == 'T': - txt, err := readTFrame(b, true) // text is encoded + txt, err := readTFrame(b) if err != nil { return nil, err } @@ -240,7 +240,7 @@ func readID3v2Frames(r io.Reader, h *ID3v2Header) (map[string]interface{}, error result[rawName] = t case name[0] == 'W': - txt, err := readTFrame(b, false) // url are not encoded + txt, err := readWFrame(b) if err != nil { return nil, err } diff --git a/id3v2frames.go b/id3v2frames.go index ccf346e..28462a8 100644 --- a/id3v2frames.go +++ b/id3v2frames.go @@ -13,25 +13,24 @@ import ( "unicode/utf16" ) -// when the frame is not encoded, add a 0 at the start -func readTFrame(b []byte, encoded bool) (string, error) { - if !encoded { - b = append([]byte{0}, b[0:]...) +func readWFrame(b []byte) (string, error) { + // Frame text is always encoded in ISO-8859-1 + b = append([]byte{0}, b...) + return readTFrame(b) +} + +func readTFrame(b []byte) (string, error) { + if len(b) == 0 { + return "", nil } - txt, err := parseText(b) + + txt, err := decodeText(b[0], b[1:]) if err != nil { return "", err } return strings.Join(strings.Split(txt, string([]byte{0})), ""), nil } -func parseText(b []byte) (string, error) { - if len(b) == 0 { - return "", nil - } - return decodeText(b[0], b[1:]) -} - func decodeText(enc byte, b []byte) (string, error) { if len(b) == 0 { return "", nil