diff --git a/id3v2.go b/id3v2.go index a9d8b0a..c3af801 100644 --- a/id3v2.go +++ b/id3v2.go @@ -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 }