fix: use a regex to match year in ffmpeg date field. close #63

This commit is contained in:
Deluan
2020-02-08 23:17:12 -05:00
parent 029290f304
commit ab10719d27
2 changed files with 13 additions and 13 deletions
+6 -9
View File
@@ -201,20 +201,17 @@ var tagYearFormats = []string{
time.RFC3339,
}
var dateRegex = regexp.MustCompile(`^([12]\d\d\d)`)
func (m *Metadata) parseYear(tagName string) int {
if v, ok := m.tags[tagName]; ok {
var y time.Time
var err error
for _, fmt := range tagYearFormats {
if y, err = time.Parse(fmt, v); err == nil {
break
}
}
if err != nil {
match := dateRegex.FindStringSubmatch(v)
if len(match) == 0 {
log.Error("Error parsing year from ffmpeg date field. Please report this issue", "file", m.filePath, "date", v)
return 0
}
return y.Year()
year, _ := strconv.Atoi(match[1])
return year
}
return 0
}