id3v2: try to parse the year when 'year' tag could be a date (#104)

Co-authored-by: David Howden <dhowden@gmail.com>
This commit is contained in:
Jorge Junior
2024-04-17 15:37:06 +10:00
committed by GitHub
co-authored by David Howden
parent dc579f508b
commit 3d75831295
3 changed files with 15 additions and 4 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: "1.20"
cache: true
- name: Build
+1 -1
View File
@@ -1,6 +1,6 @@
module github.com/dhowden/tag
go 1.18
go 1.20
require github.com/dhowden/itl v0.0.0-20170329215456-9fbe21093131
+13 -2
View File
@@ -7,6 +7,7 @@ package tag
import (
"strconv"
"strings"
"time"
)
type frameNames map[string][2]string
@@ -89,8 +90,18 @@ func (m metadataID3v2) Genre() string {
}
func (m metadataID3v2) Year() int {
year, _ := strconv.Atoi(m.getString(frames.Name("year", m.Format())))
return year
stringYear := m.getString(frames.Name("year", m.Format()))
if year, err := strconv.Atoi(stringYear); err == nil {
return year
}
date, err := time.Parse(time.DateOnly, stringYear)
if err != nil {
return 0
}
return date.Year()
}
func parseXofN(s string) (x, n int) {