Skip to content

Commit

Permalink
make date token optional when using {x.cdt} variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoisaiah committed Oct 30, 2024
1 parent d0a3767 commit aee227f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
18 changes: 18 additions & 0 deletions replace/replace_test/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ func TestVariables(t *testing.T) {
"-f", ".*", "-r", "{x.cdt.YYYY}_{exif.make}_{exif.model}_ISO{exif.iso}_w{exif.w}_h{exif.h}_{exif.wh}_{exif.et}s_{exif.fl}mm({exif.fl35}mm)_f{x.fnum}{ext}",
},
},
{
Name: "replace with Exif DateTimeOriginal",
Changes: file.Changes{
{
BaseDir: "testdata",
Source: "pic.jpg",
},
{
BaseDir: "testdata",
Source: "image.dng",
},
},
Want: []string{
"testdata/2001-05-19T18:36:41Z.jpg",
"testdata/2005-08-03T18:59:18Z.dng",
},
Args: []string{"-f", ".*", "-r", "{x.cdt}{ext}"},
},
{
Name: "ensure slashes in ID3 variables are replaced with underscores",
Changes: file.Changes{
Expand Down
2 changes: 1 addition & 1 deletion replace/variables/variable_regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func init() {

exifVarRegex = regexp.MustCompile(
fmt.Sprintf(
"{+(?:exif|x)\\.(?:(iso|et|fl|w|h|wh|make|model|lens|fnum|fl35|lat|lon|soft)|(?:(cdt)\\.("+tokenString+")))(?:\\.%s)?}+",
"{+(?:exif|x)\\.(?:(iso|et|fl|w|h|wh|make|model|lens|fnum|fl35|lat|lon|soft)|(?:(cdt)(?:\\.("+tokenString+"))?))(?:\\.%s)?}+",
transformTokens,
),
)
Expand Down
4 changes: 4 additions & 0 deletions replace/variables/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ func getExifDate(exifData *Exif, format string) string {
return ""
}

if format == "" {
return dateTime.Format(time.RFC3339)
}

return dateTime.Format(dateTokens[format])
}

Expand Down

0 comments on commit aee227f

Please sign in to comment.