Merge string trimming for id3v1 into single method
This commit is contained in:
parent
bcc288a50a
commit
222f0b2988
24
id3v1.go
24
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{}
|
||||
|
||||
|
9
util.go
9
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user