Skip to content

Commit

Permalink
id3v2: try to parse the year when 'year' tag could be a date (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: David Howden <dhowden@gmail.com>
  • Loading branch information
JorgeLNJunior and dhowden authored Apr 17, 2024
1 parent dc579f5 commit 3d75831
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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

Expand Down
15 changes: 13 additions & 2 deletions id3v2metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package tag
import (
"strconv"
"strings"
"time"
)

type frameNames map[string][2]string
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3d75831

Please sign in to comment.