id3v2: fix variable name and pre-compute genre regexp

This commit is contained in:
David Howden 2018-04-02 08:17:10 +10:00
parent 4f91c64763
commit 3fc65dddfc

View File

@ -409,16 +409,17 @@ func ReadID3v2Tags(r io.ReadSeeker) (Metadata, error) {
return metadataID3v2{header: h, frames: f}, nil
}
var id3v2genreRe = regexp.MustCompile(`(.*[^(]|.* |^)\(([0-9]+)\) *(.*)$`)
// id3v2genre parse a id3v2 genre tag and expand the numeric genres
func id3v2genre(genre string) string {
c := true
for c {
orig := genre
re := regexp.MustCompile("(.*[^(]|.* |^)\\(([0-9]+)\\) *(.*)$")
if match := re.FindStringSubmatch(genre); len(match) > 0 {
if genreId, err := strconv.Atoi(match[2]); err == nil {
if genreId < len(id3v2Genres) {
genre = id3v2Genres[genreId]
if match := id3v2genreRe.FindStringSubmatch(genre); len(match) > 0 {
if genreID, err := strconv.Atoi(match[2]); err == nil {
if genreID < len(id3v2Genres) {
genre = id3v2Genres[genreID]
if match[1] != "" {
genre = strings.TrimSpace(match[1]) + " " + genre
}