id3v2: fix variable name and pre-compute genre regexp
This commit is contained in:
parent
4f91c64763
commit
3fc65dddfc
11
id3v2.go
11
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user