From 3fc65dddfc67142ae529efd1343c0108be6f9573 Mon Sep 17 00:00:00 2001 From: David Howden Date: Mon, 2 Apr 2018 08:17:10 +1000 Subject: [PATCH] id3v2: fix variable name and pre-compute genre regexp --- id3v2.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 }