From 09c94a2c943d74f5f6f9875d5f33276f9ac87a67 Mon Sep 17 00:00:00 2001 From: Alex McLain Date: Sun, 10 May 2020 20:40:01 -0700 Subject: [PATCH 1/2] Add templatable 'year_captured' property. --- README.md | 10 +++++++++- lib/halation/engine.rb | 11 ++++++++++- spec/config_spec.rb | 2 +- spec/engine_spec.rb | 17 +++++++++++++---- spec/roll_spec.rb | 6 +++--- spec/samples/set_1/config.yml | 2 +- spec/samples/set_1/roll.yml | 6 +++--- 7 files changed, 40 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 2774326..75d1c95 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ and information about your cameras. # Example config.yml --- artist: "Example User" -copyright: "2016 Example User" +copyright: "{{ year_captured }} Example User" cameras: - tag: "rz67" make: "Mamiya" @@ -63,6 +63,14 @@ cameras: focal_length: 250 ``` +### Templating + +Templated values are supported within the YAML files using the moustache +`{{` `}}` syntax. + +- `year_captured` - Available within the `copyright` field to substitute the year +the image was captured. + ## Tags Tags are user-defined values that serve as a quick and simple way to reference diff --git a/lib/halation/engine.rb b/lib/halation/engine.rb index 2892ed0..9a21ef1 100644 --- a/lib/halation/engine.rb +++ b/lib/halation/engine.rb @@ -66,7 +66,7 @@ def run ExifToolImage.new(_image_files[i]).tap do |exif| exif["Artist"] = @roll.artist || @config.artist - exif["Copyright"] = @roll.copyright || @config.copyright + exif["Copyright"] = template_copyright(@config, @roll, frame) exif["DateTimeOriginal"] = frame.date_captured || @roll.date_captured exif["CreateDate"] = frame.date_scanned || @roll.date_scanned exif["Make"] = camera.make @@ -84,5 +84,14 @@ def run end end + private + + def template_copyright(config, roll, frame) + date_captured = frame.date_captured || roll.date_captured + year_captured = date_captured.strftime("%Y") + + copyright = (roll.copyright || config.copyright).clone + copyright.gsub!(Regexp.new("{{\s*year_captured\s*}}"), year_captured) + end end end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 767f713..b33702a 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -25,7 +25,7 @@ } let(:artist) { "Test Artist" } - let(:copyright) { "2016 Test Artist" } + let(:copyright) { "{{ year_captured }} Test Artist" } let(:cameras) {[ { diff --git a/spec/engine_spec.rb b/spec/engine_spec.rb index e06aea6..7ebe400 100644 --- a/spec/engine_spec.rb +++ b/spec/engine_spec.rb @@ -34,7 +34,6 @@ let(:working_dir) { "spec/samples/under_test" } let(:artist) { "Me" } - let(:copyright) { "2016 Me" } let(:make) { "Mamiya" } let(:model) { "Mamiya RZ67 Pro II" } let(:iso) { 100 } @@ -42,8 +41,9 @@ let(:exif_results) {[ { # Frame 1 - "DateTimeOriginal" => Time.parse("2016-02-03 01:02:03"), - "CreateDate" => Time.parse("2016-02-15 08:09:10"), + "Copyright" => "2017 Me", + "DateTimeOriginal" => Time.parse("2017-02-03 01:02:03"), + "CreateDate" => Time.parse("2017-02-15 08:09:10"), "LensModel" => "Z180mm f/4.5W-N", "ExposureTime" => 1.0/250, "FNumber" => 8, @@ -53,6 +53,7 @@ }, { # Frame 2 + "Copyright" => "2016 Me", "DateTimeOriginal" => Time.parse("2016-01-02"), "CreateDate" => Time.parse("2016-01-05"), "LensModel" => "Z100-200mm f/5.2W", @@ -64,6 +65,7 @@ }, { # Frame 3 + "Copyright" => "2016 Me", "DateTimeOriginal" => Time.parse("2016-01-02"), "CreateDate" => Time.parse("2016-01-05"), "LensModel" => "Z110mm f/2.8W", @@ -75,6 +77,7 @@ }, { # Frame 4 + "Copyright" => "2016 Me", "DateTimeOriginal" => Time.parse("2016-01-02"), "CreateDate" => Time.parse("2016-01-05"), "LensModel" => "Z110mm f/2.8W", @@ -86,6 +89,7 @@ }, { # Frame 5 + "Copyright" => "2016 Me", "DateTimeOriginal" => Time.parse("2016-01-02"), "CreateDate" => Time.parse("2016-01-05"), "LensModel" => "Z110mm f/2.8W", @@ -97,6 +101,7 @@ }, { # Frame 6 + "Copyright" => "2016 Me", "DateTimeOriginal" => Time.parse("2016-01-02"), "CreateDate" => Time.parse("2016-01-05"), "LensModel" => "Z110mm f/2.8W", @@ -108,6 +113,7 @@ }, { # Frame 7 + "Copyright" => "2016 Me", "DateTimeOriginal" => Time.parse("2016-01-02"), "CreateDate" => Time.parse("2016-01-05"), "LensModel" => "Z110mm f/2.8W", @@ -119,6 +125,7 @@ }, { # Frame 8 + "Copyright" => "2016 Me", "DateTimeOriginal" => Time.parse("2016-01-02"), "CreateDate" => Time.parse("2016-01-05"), "LensModel" => "Z110mm f/2.8W", @@ -130,6 +137,7 @@ }, { # Frame 9 + "Copyright" => "2016 Me", "DateTimeOriginal" => Time.parse("2016-01-02"), "CreateDate" => Time.parse("2016-01-05"), "LensModel" => "Z110mm f/2.8W", @@ -141,6 +149,7 @@ }, { # Frame 10 + "Copyright" => "2016 Me", "DateTimeOriginal" => Time.parse("2016-01-02"), "CreateDate" => Time.parse("2016-01-05"), "LensModel" => "Z110mm f/2.8W", @@ -172,7 +181,7 @@ MiniExiftool.new(image_file, numerical: true).tap do |exif| exif["Artist"].should eq artist - exif["Copyright"].should eq copyright + exif["Copyright"].should eq exif_results[i]["Copyright"] exif["DateTimeOriginal"].should eq exif_results[i]["DateTimeOriginal"] exif["CreateDate"].should eq exif_results[i]["CreateDate"] exif["Make"].should eq make diff --git a/spec/roll_spec.rb b/spec/roll_spec.rb index 49bebbe..ee49eb0 100644 --- a/spec/roll_spec.rb +++ b/spec/roll_spec.rb @@ -27,7 +27,7 @@ it "has values" do subject.artist.should eq "Me" - subject.copyright.should eq "2016 Me" + subject.copyright.should eq "{{ year_captured }} Me" subject.date_captured.should eq Time.parse("2016-01-02") subject.date_scanned.should eq Time.parse("2016-01-05") subject.camera.should eq "rz67" @@ -41,8 +41,8 @@ case i when 0 frame.number.should eq 1 - frame.date_captured.should eq Time.parse("2016-02-03 01:02:03") - frame.date_scanned.should eq Time.parse("2016-02-15 08:09:10") + frame.date_captured.should eq Time.parse("2017-02-03 01:02:03") + frame.date_scanned.should eq Time.parse("2017-02-15 08:09:10") frame.lens.should eq "180" frame.focal_length.should be nil frame.shutter.should eq "1/250" diff --git a/spec/samples/set_1/config.yml b/spec/samples/set_1/config.yml index 39907c0..d722bb3 100644 --- a/spec/samples/set_1/config.yml +++ b/spec/samples/set_1/config.yml @@ -1,6 +1,6 @@ --- artist: "Test Artist" -copyright: "2016 Test Artist" +copyright: "{{ year_captured }} Test Artist" cameras: - tag: "rz67" make: "Mamiya" diff --git a/spec/samples/set_1/roll.yml b/spec/samples/set_1/roll.yml index dd4320a..0f2a6e5 100644 --- a/spec/samples/set_1/roll.yml +++ b/spec/samples/set_1/roll.yml @@ -1,6 +1,6 @@ --- artist: "Me" -copyright: "2016 Me" +copyright: "{{ year_captured }} Me" date_captured: "2016-01-02" # default date_scanned: "2016-01-05" # default camera: "rz67" @@ -8,8 +8,8 @@ lens: 110 # default iso: 100 frames: - number: 1 - date_captured: "2016-02-03 01:02:03" # overridden - date_scanned: "2016-02-15 08:09:10" # overridden + date_captured: "2017-02-03 01:02:03" # overridden + date_scanned: "2017-02-15 08:09:10" # overridden lens: 180 # overridden shutter: "1/250" aperture: 8 From 8824ea6c987be79e46bec832b13a307b5b905792 Mon Sep 17 00:00:00 2001 From: Alex McLain Date: Sun, 10 May 2020 20:56:47 -0700 Subject: [PATCH 2/2] Add templatable 'artist' property. --- README.md | 3 ++- lib/halation/engine.rb | 2 ++ spec/config_spec.rb | 2 +- spec/roll_spec.rb | 2 +- spec/samples/set_1/config.yml | 2 +- spec/samples/set_1/roll.yml | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 75d1c95..245144c 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ and information about your cameras. # Example config.yml --- artist: "Example User" -copyright: "{{ year_captured }} Example User" +copyright: "{{ year_captured }} {{ artist }}" cameras: - tag: "rz67" make: "Mamiya" @@ -68,6 +68,7 @@ cameras: Templated values are supported within the YAML files using the moustache `{{` `}}` syntax. +- `artist` - Available within the `copyright` field to substitute the artist name. - `year_captured` - Available within the `copyright` field to substitute the year the image was captured. diff --git a/lib/halation/engine.rb b/lib/halation/engine.rb index 9a21ef1..453524d 100644 --- a/lib/halation/engine.rb +++ b/lib/halation/engine.rb @@ -87,10 +87,12 @@ def run private def template_copyright(config, roll, frame) + artist = roll.artist || config.artist date_captured = frame.date_captured || roll.date_captured year_captured = date_captured.strftime("%Y") copyright = (roll.copyright || config.copyright).clone + copyright.gsub!(Regexp.new("{{\s*artist\s*}}"), artist) copyright.gsub!(Regexp.new("{{\s*year_captured\s*}}"), year_captured) end end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index b33702a..40cfc0f 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -25,7 +25,7 @@ } let(:artist) { "Test Artist" } - let(:copyright) { "{{ year_captured }} Test Artist" } + let(:copyright) { "{{ year_captured }} {{ artist }}" } let(:cameras) {[ { diff --git a/spec/roll_spec.rb b/spec/roll_spec.rb index ee49eb0..9b42f5f 100644 --- a/spec/roll_spec.rb +++ b/spec/roll_spec.rb @@ -27,7 +27,7 @@ it "has values" do subject.artist.should eq "Me" - subject.copyright.should eq "{{ year_captured }} Me" + subject.copyright.should eq "{{ year_captured }} {{ artist }}" subject.date_captured.should eq Time.parse("2016-01-02") subject.date_scanned.should eq Time.parse("2016-01-05") subject.camera.should eq "rz67" diff --git a/spec/samples/set_1/config.yml b/spec/samples/set_1/config.yml index d722bb3..f507a14 100644 --- a/spec/samples/set_1/config.yml +++ b/spec/samples/set_1/config.yml @@ -1,6 +1,6 @@ --- artist: "Test Artist" -copyright: "{{ year_captured }} Test Artist" +copyright: "{{ year_captured }} {{ artist }}" cameras: - tag: "rz67" make: "Mamiya" diff --git a/spec/samples/set_1/roll.yml b/spec/samples/set_1/roll.yml index 0f2a6e5..5225cab 100644 --- a/spec/samples/set_1/roll.yml +++ b/spec/samples/set_1/roll.yml @@ -1,6 +1,6 @@ --- artist: "Me" -copyright: "{{ year_captured }} Me" +copyright: "{{ year_captured }} {{ artist }}" date_captured: "2016-01-02" # default date_scanned: "2016-01-05" # default camera: "rz67"