From 3d75831295e8a3dfbf59ed763169b22da6451186 Mon Sep 17 00:00:00 2001 From: Jorge Junior Date: Wed, 17 Apr 2024 02:37:06 -0300 Subject: [PATCH] id3v2: try to parse the year when 'year' tag could be a date (#104) Co-authored-by: David Howden --- .github/workflows/go.yml | 2 +- go.mod | 2 +- id3v2metadata.go | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f89f878..3788420 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 diff --git a/go.mod b/go.mod index d57cf38..e1aa28a 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/id3v2metadata.go b/id3v2metadata.go index 6185963..4279f64 100644 --- a/id3v2metadata.go +++ b/id3v2metadata.go @@ -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) {