diff --git a/id3v1.go b/id3v1.go index e9e5d17..d333500 100644 --- a/id3v1.go +++ b/id3v1.go @@ -54,17 +54,17 @@ func ReadID3v1Tags(r io.ReadSeeker) (Metadata, error) { return nil, ErrNotID3v1 } - title, err := readStringTrimNULL(r, 30) + title, err := readString(r, 30) if err != nil { return nil, err } - artist, err := readStringTrimNULL(r, 30) + artist, err := readString(r, 30) if err != nil { return nil, err } - album, err := readStringTrimNULL(r, 30) + album, err := readString(r, 30) if err != nil { return nil, err } @@ -82,10 +82,10 @@ func ReadID3v1Tags(r io.ReadSeeker) (Metadata, error) { var comment string var track int if commentBytes[28] == 0 { - comment = strings.TrimSpace(string(commentBytes[:28])) + comment = trimString(string(commentBytes[:28])) track = int(commentBytes[29]) } else { - comment = strings.TrimSpace(string(commentBytes)) + comment = trimString(string(commentBytes)) } var genre string @@ -98,17 +98,21 @@ func ReadID3v1Tags(r io.ReadSeeker) (Metadata, error) { } m := make(map[string]interface{}) - m["title"] = strings.TrimSpace(title) - m["artist"] = strings.TrimSpace(artist) - m["album"] = strings.TrimSpace(album) - m["year"] = strings.TrimSpace(year) - m["comment"] = strings.TrimSpace(comment) + m["title"] = trimString(title) + m["artist"] = trimString(artist) + m["album"] = trimString(album) + m["year"] = trimString(year) + m["comment"] = trimString(comment) m["track"] = track m["genre"] = genre return metadataID3v1(m), nil } +func trimString(x string) string { + return strings.TrimSpace(strings.Trim(x, "\x00")) +} + // metadataID3v1 is the implementation of Metadata used for ID3v1 tags. type metadataID3v1 map[string]interface{} diff --git a/util.go b/util.go index 4278ce9..ec28ac6 100644 --- a/util.go +++ b/util.go @@ -5,7 +5,6 @@ package tag import ( - "bytes" "encoding/binary" "io" ) @@ -50,14 +49,6 @@ func readString(r io.Reader, n int) (string, error) { return string(b), nil } -func readStringTrimNULL(r io.Reader, n int) (string, error) { - b, err := readBytes(r, n) - if err != nil { - return "", err - } - return string(bytes.Trim(b, "\x00")), nil -} - func readInt(r io.Reader, n int) (int, error) { b, err := readBytes(r, n) if err != nil {