Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to parse the year when 'year' tag could be a date #104

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading