multi_exiftool 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 317f91ac28f2791341c7c6354e996545c80f08fb7100607460295ae55c38d463
4
- data.tar.gz: d98f7b7a4a0cca8e0ce2e18f1b718ef7227412a31ff5e9b8f3d4685077d97221
3
+ metadata.gz: ae8854c3ecd3b7d994ee26ac7ec90fdac4611143fd50fba1d96d1557a4e4ff2c
4
+ data.tar.gz: 66714930cb460368f930dbc655c4dfbd502d0e45b371f21786fe3d4c6c124e0c
5
5
  SHA512:
6
- metadata.gz: 292b732d0940abb55c9dccebadfb8976767891ad33fb865e982689fd0b4a617590b95b195d1144831d073374357f68823dd51a4875962ef0374b0803753adf46
7
- data.tar.gz: b1d1c48bfdf082f7f79ebf5f5b2feefd0e661fcfb2aebc23b73cfec25606e195b2c989c5e36b05e57257e56ddbb0b0b5fef452ed3a07cb7479508062bc302fbe
6
+ metadata.gz: a0783ca4711efe4a88dd30a23a10ab357d250ada9d8fae6474cbe5356d6fc59e88743868449495bb36efaf8f65d4db1eaff889b07903fdb4fc5f64d3b2813866
7
+ data.tar.gz: 9c91eb43576561b7dc712f3d0b05bda741fd2c4fb6f3542d7a56204cec09d2543e4d301060b66f3deb5a1b07c49537f32dcb4d0c5b869ec91b695b1409c035db
data/Changelog CHANGED
@@ -1,3 +1,8 @@
1
+ 0.13.0
2
+ Implement batch processing to allow to write different values to multiple file
3
+ with only one call of the ExifTool command-line application.
4
+ Update documentation.
5
+
1
6
  0.12.0
2
7
  Implement Values#respond_to_missing?.
3
8
  Improve documentation and fix example code.
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ## Description
4
4
 
5
5
  This library is a wrapper for the ExifTool command-line application
6
- (http://www.sno.phy.queensu.ca/~phil/exiftool) written by Phil Harvey.
6
+ (https://exiftool.org) written by Phil Harvey.
7
7
  It is designed for dealing with multiple files at once by creating
8
8
  commands to call exiftool with various arguments, call it and parsing
9
9
  the results.
@@ -60,6 +60,39 @@ else
60
60
  end
61
61
  ```
62
62
 
63
+ If it is necessary to write different values to multiple files there is batch processing
64
+
65
+ ```ruby
66
+ require 'multi_exiftool'
67
+
68
+ # Object oriented approach
69
+ batch = Batch.new do
70
+ Dir['*.jpg'].each_with_index do |filename, i|
71
+ values = {creator: 'Jan Friedrich', copyright: 'Public Domain', comment: "This is file number #{i+1}."}
72
+ write filename, values
73
+ end
74
+ end
75
+ if batch.execute
76
+ puts 'ok'
77
+ else
78
+ puts batch.errors
79
+ end
80
+
81
+ # Functional approach
82
+ errors = MultiExiftool.batch do
83
+ Dir['*.jpg'].each_with_index do |filename, i|
84
+ values = {creator: 'Jan Friedrich', copyright: 'Public Domain', comment: "This is file number #{i+1}."}
85
+ write filename, values
86
+ end
87
+ end
88
+ if errors.empty?
89
+ puts 'ok'
90
+ else
91
+ puts batch.errors
92
+ end
93
+ ```
94
+
95
+
63
96
  ### Deleting
64
97
 
65
98
  ```ruby
@@ -153,7 +186,7 @@ The method Values#convert is called each time a value is fetched.
153
186
  - Ruby 1.9.1 or higher
154
187
  - An installation of the ExifTool command-line application (version 7.65 or
155
188
  higher). Instructions for installation you can find under
156
- http://www.sno.phy.queensu.ca/~phil/exiftool/install.html .
189
+ https://exiftool.org/install.html .
157
190
  - If you have problems with special characters (like German umlauts) in
158
191
  filenames on windows system it is recommended to use exiftool version 9.79
159
192
  or higher.
data/Rakefile CHANGED
@@ -11,8 +11,8 @@ Rim.setup do |p|
11
11
  p.version = MultiExiftool::VERSION
12
12
  p.authors = 'Jan Friedrich'
13
13
  p.email = 'janfri26@gmail.com'
14
- p.summary = 'This library is a wrapper for the ExifTool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool).'
15
- p.description = 'This library a is wrapper for the ExifTool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool) written by Phil Harvey. It is designed for dealing with multiple files at once by creating commands to call exiftool with various arguments, call it and parsing the results.'
14
+ p.summary = 'This library is a wrapper for the ExifTool command-line application (https://exiftool.org).'
15
+ p.description = 'This library a is wrapper for the ExifTool command-line application (https://exiftool.org) written by Phil Harvey. It is designed for dealing with multiple files at once by creating commands to call exiftool with various arguments, call it and parsing the results.'
16
16
  p.ruby_version = '>=1.9.1'
17
17
  p.license = 'MIT'
18
18
  p.homepage = 'https://github.com/janfri/multi_exiftool'
@@ -21,7 +21,7 @@ Rim.setup do |p|
21
21
  | Please ensure you have installed exiftool version 7.65 or higher and |
22
22
  | it's found in your PATH (Try "exiftool -ver" on your commandline). |
23
23
  | For more details see |
24
- | http://www.sno.phy.queensu.ca/~phil/exiftool/install.html |
24
+ | https://exiftool.org/install.html |
25
25
  +-----------------------------------------------------------------------+
26
26
  }
27
27
  p.development_dependencies << %w(contest ~>0.1)
@@ -4,10 +4,11 @@
4
4
  require_relative 'multi_exiftool/values'
5
5
  require_relative 'multi_exiftool/reader'
6
6
  require_relative 'multi_exiftool/writer'
7
+ require_relative 'multi_exiftool/batch'
7
8
 
8
9
  module MultiExiftool
9
10
 
10
- VERSION = '0.12.0'
11
+ VERSION = '0.13.0'
11
12
 
12
13
  @exiftool_command = 'exiftool'
13
14
 
@@ -25,15 +26,7 @@ module MultiExiftool
25
26
  # # error handling
26
27
  # end
27
28
  def read filenames, opts={}
28
- reader = Reader.new
29
- reader.filenames = filenames
30
- if val = opts.delete(:tags)
31
- reader.tags = val
32
- end
33
- if val = opts.delete(:group)
34
- reader.group = val
35
- end
36
- reader.options = opts unless opts.empty?
29
+ reader = Reader.new(filenames, opts)
37
30
  values = reader.read
38
31
  [values, reader.errors]
39
32
  end
@@ -47,10 +40,7 @@ module MultiExiftool
47
40
  # # do error handling
48
41
  # end
49
42
  def write filenames, values, opts={}
50
- writer = Writer.new
51
- writer.filenames = filenames
52
- writer.values = values
53
- writer.options = opts unless opts.empty?
43
+ writer = Writer.new(filenames, values, opts)
54
44
  writer.write
55
45
  writer.errors
56
46
  end
@@ -75,6 +65,24 @@ module MultiExiftool
75
65
  write(filenames, values)
76
66
  end
77
67
 
68
+
69
+ # Execute a batch of write commands
70
+ # Returns an array of the error messages
71
+ #
72
+ # Example:
73
+ # errors = MultiExiftool.batch do
74
+ # Dir['*.jpg'].each_with_index do |filename, i|
75
+ # write filename, {author: 'Jan Friedrich', comment: "This is file number #{i+1}."}
76
+ # end
77
+ # unless errors.empty?
78
+ # # do error handling
79
+ # end
80
+ def batch &block
81
+ batch = Batch.new &block
82
+ batch.execute
83
+ batch.errors
84
+ end
85
+
78
86
  attr_accessor :exiftool_command
79
87
  attr_reader :exiftool_version
80
88
 
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'executable'
5
+
6
+ module MultiExiftool
7
+
8
+ # Allow to define a batch for different writing operations as one call of the
9
+ # ExifTool command-line application
10
+ class Batch
11
+
12
+ include Executable
13
+
14
+ # Define batch operation inside a block
15
+ def initialize &blk
16
+ @writers = []
17
+ instance_exec &blk
18
+ end
19
+
20
+ # Define a write operation for the batch.
21
+ def write filenames, values, options={}
22
+ w = MultiExiftool::Writer.new(filenames, values, options)
23
+ @writers << w
24
+ end
25
+
26
+ # Getting the command-line arguments which would be executed
27
+ # when calling #write. It could be useful for logging, debugging or
28
+ # whatever.
29
+ def exiftool_args
30
+ @writers.map {|w| w.exiftool_args + ['-execute']}.flatten
31
+ end
32
+
33
+ private
34
+
35
+ def parse_results
36
+ @errors = @stderr.read.split(/\n/)
37
+ @errors.empty?
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -11,9 +11,9 @@ module MultiExiftool
11
11
  attr_reader :errors
12
12
  attr_accessor :filenames, :numerical, :options
13
13
 
14
- def initialize
15
- @options = {}
16
- @filenames = []
14
+ def initialize filenames=[], options={}
15
+ @options = options
16
+ @filenames = filenames
17
17
  @option_mapping = {numerical: :n}
18
18
  end
19
19
 
@@ -15,9 +15,17 @@ module MultiExiftool
15
15
 
16
16
  include Executable
17
17
 
18
- def initialize
19
- super
20
- @tags = []
18
+ def initialize filenames=[], opts={}
19
+ super(filenames, opts)
20
+ if val = opts.delete(:tags)
21
+ @tags = val
22
+ else
23
+ @tags = []
24
+ end
25
+ if val = opts.delete(:group)
26
+ @group = val
27
+ end
28
+ @options = opts unless opts.empty?
21
29
  end
22
30
 
23
31
  def self.mandatory_args
@@ -14,9 +14,9 @@ module MultiExiftool
14
14
 
15
15
  include Executable
16
16
 
17
- def initialize
18
- super
19
- @values = {}
17
+ def initialize filenames=[], values={}, opts={}
18
+ super(filenames, opts)
19
+ @values = values
20
20
  end
21
21
 
22
22
  def self.mandatory_args
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: multi_exiftool 0.12.0 ruby lib
2
+ # stub: multi_exiftool 0.13.0 ruby lib
3
3
  #
4
4
  # This file is automatically generated by rim.
5
5
  # PLEASE DO NOT EDIT IT DIRECTLY!
@@ -7,22 +7,22 @@
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "multi_exiftool"
10
- s.version = "0.12.0"
10
+ s.version = "0.13.0"
11
11
 
12
12
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
13
  s.require_paths = ["lib"]
14
14
  s.authors = ["Jan Friedrich"]
15
- s.date = "2020-01-02"
16
- s.description = "This library a is wrapper for the ExifTool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool) written by Phil Harvey. It is designed for dealing with multiple files at once by creating commands to call exiftool with various arguments, call it and parsing the results."
15
+ s.date = "2020-02-03"
16
+ s.description = "This library a is wrapper for the ExifTool command-line application (https://exiftool.org) written by Phil Harvey. It is designed for dealing with multiple files at once by creating commands to call exiftool with various arguments, call it and parsing the results."
17
17
  s.email = "janfri26@gmail.com"
18
- s.files = ["./.aspell.pws", "Changelog", "Gemfile", "LICENSE", "README.md", "Rakefile", "lib/multi_exiftool", "lib/multi_exiftool.rb", "lib/multi_exiftool/executable.rb", "lib/multi_exiftool/reader.rb", "lib/multi_exiftool/values.rb", "lib/multi_exiftool/writer.rb", "multi_exiftool.gemspec", "regtest/read_all_tags.rb", "regtest/read_all_tags.yml", "regtest/test.jpg", "test/data", "test/data/a.jpg", "test/data/b.jpg", "test/data/c.jpg", "test/helper.rb", "test/test_executable.rb", "test/test_exiftool_stuff.rb", "test/test_functional_api.rb", "test/test_reader.rb", "test/test_values.rb", "test/test_values_using_groups.rb", "test/test_writer.rb", "test/test_writer_groups.rb"]
18
+ s.files = ["./.aspell.pws", "Changelog", "Gemfile", "LICENSE", "README.md", "Rakefile", "lib/multi_exiftool", "lib/multi_exiftool.rb", "lib/multi_exiftool/batch.rb", "lib/multi_exiftool/executable.rb", "lib/multi_exiftool/reader.rb", "lib/multi_exiftool/values.rb", "lib/multi_exiftool/writer.rb", "multi_exiftool.gemspec", "regtest/read_all_tags.rb", "regtest/read_all_tags.yml", "regtest/test.jpg", "test/data", "test/data/a.jpg", "test/data/b.jpg", "test/data/c.jpg", "test/helper.rb", "test/test_batch.rb", "test/test_executable.rb", "test/test_exiftool_stuff.rb", "test/test_functional_api.rb", "test/test_reader.rb", "test/test_values.rb", "test/test_values_using_groups.rb", "test/test_writer.rb", "test/test_writer_groups.rb"]
19
19
  s.homepage = "https://github.com/janfri/multi_exiftool"
20
20
  s.licenses = ["MIT"]
21
- s.post_install_message = "\n+-----------------------------------------------------------------------+\n| Please ensure you have installed exiftool version 7.65 or higher and |\n| it's found in your PATH (Try \"exiftool -ver\" on your commandline). |\n| For more details see |\n| http://www.sno.phy.queensu.ca/~phil/exiftool/install.html |\n+-----------------------------------------------------------------------+\n "
21
+ s.post_install_message = "\n+-----------------------------------------------------------------------+\n| Please ensure you have installed exiftool version 7.65 or higher and |\n| it's found in your PATH (Try \"exiftool -ver\" on your commandline). |\n| For more details see |\n| https://exiftool.org/install.html |\n+-----------------------------------------------------------------------+\n "
22
22
  s.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
23
23
  s.requirements = ["exiftool, version 7.65 or higher"]
24
24
  s.rubygems_version = "3.1.2"
25
- s.summary = "This library is a wrapper for the ExifTool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool)."
25
+ s.summary = "This library is a wrapper for the ExifTool command-line application (https://exiftool.org)."
26
26
 
27
27
  if s.respond_to? :specification_version then
28
28
  s.specification_version = 4
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'helper'
5
+
6
+ class TestBatch < Test::Unit::TestCase
7
+
8
+ MANDATORY_WRITER_ARGS = MultiExiftool::Writer.mandatory_args
9
+
10
+ context 'exiftool_args method' do
11
+
12
+ setup do
13
+ @filenames = %w(a.jpg b.jpg c.jpg)
14
+ @multiple_values = @filenames.map do |filename|
15
+ {author: 'janfri', comment: "Comment for file #{filename}"}
16
+ end
17
+ end
18
+
19
+ test 'only filenames and values' do
20
+ filenames = @filenames
21
+ multiple_values = @multiple_values
22
+ batch = MultiExiftool::Batch.new do
23
+ filenames.zip multiple_values do |filename, values|
24
+ write filename, values
25
+ end
26
+ end
27
+ exiftool_args = filenames.zip(multiple_values).map do |filename, values|
28
+ [MANDATORY_WRITER_ARGS, '-author=janfri', "-comment=Comment for file #{filename}", filename, '-execute']
29
+ end.flatten
30
+ assert_equal exiftool_args, batch.exiftool_args
31
+ end
32
+
33
+ test 'filenames, values and options' do
34
+ filenames = @filenames
35
+ multiple_values = @multiple_values
36
+ options = {overwrite_original: true}
37
+ batch = MultiExiftool::Batch.new do
38
+ filenames.zip multiple_values do |filename, values|
39
+ write filename, values, options
40
+ end
41
+ end
42
+ exiftool_args = filenames.zip(multiple_values).map do |filename, _values|
43
+ [MANDATORY_WRITER_ARGS, '-overwrite_original', '-author=janfri', "-comment=Comment for file #{filename}", filename, '-execute']
44
+ end.flatten
45
+ assert_equal exiftool_args, batch.exiftool_args
46
+ end
47
+ end
48
+ end
@@ -188,4 +188,51 @@ class TestFunctionalApi < Test::Unit::TestCase
188
188
 
189
189
  end
190
190
 
191
+ context 'batch' do
192
+ setup do
193
+ @filenames = %w(a.jpg b.jpg c.jpg)
194
+ @multiple_values = @filenames.map do |fn|
195
+ {author: 'Jan Friedrich', comment: "Comment for file #{fn}"}
196
+ end
197
+ end
198
+
199
+ test 'only filenames and values' do
200
+ run_in_temp_dir do
201
+ filenames = @filenames
202
+ multiple_values = @multiple_values
203
+ errors = MultiExiftool.batch do
204
+ filenames.zip multiple_values do |filename, values|
205
+ write filename, values
206
+ end
207
+ end
208
+ assert_equal [], errors
209
+ values, errors = MultiExiftool.read(@filenames)
210
+ assert_equal ['Jan Friedrich'] * 3, values.map {|e| e['Author']}
211
+ assert_equal ['Comment for file a.jpg', 'Comment for file b.jpg', 'Comment for file c.jpg'], values.map {|e| e['Comment']}
212
+ assert_equal [], errors
213
+ assert_equal 3, Dir['*_original'].size
214
+ end
215
+ end
216
+
217
+ test 'options with boolean argument' do
218
+ run_in_temp_dir do
219
+ filenames = @filenames
220
+ multiple_values = @multiple_values
221
+ options = {overwrite_original: true}
222
+ errors = MultiExiftool.batch do
223
+ filenames.zip multiple_values do |filename, values|
224
+ write filename, values, options
225
+ end
226
+ end
227
+ assert_equal [], errors
228
+ values, errors = MultiExiftool.read(@filenames)
229
+ assert_equal ['Jan Friedrich'] * 3, values.map {|e| e['Author']}
230
+ assert_equal ['Comment for file a.jpg', 'Comment for file b.jpg', 'Comment for file c.jpg'], values.map {|e| e['Comment']}
231
+ assert_equal [], errors
232
+ assert_equal [], Dir['*_original']
233
+ end
234
+ end
235
+
236
+ end
237
+
191
238
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_exiftool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-02 00:00:00.000000000 Z
11
+ date: 2020-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2'
83
- description: This library a is wrapper for the ExifTool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool)
83
+ description: This library a is wrapper for the ExifTool command-line application (https://exiftool.org)
84
84
  written by Phil Harvey. It is designed for dealing with multiple files at once by
85
85
  creating commands to call exiftool with various arguments, call it and parsing the
86
86
  results.
@@ -96,6 +96,7 @@ files:
96
96
  - README.md
97
97
  - Rakefile
98
98
  - lib/multi_exiftool.rb
99
+ - lib/multi_exiftool/batch.rb
99
100
  - lib/multi_exiftool/executable.rb
100
101
  - lib/multi_exiftool/reader.rb
101
102
  - lib/multi_exiftool/values.rb
@@ -108,6 +109,7 @@ files:
108
109
  - test/data/b.jpg
109
110
  - test/data/c.jpg
110
111
  - test/helper.rb
112
+ - test/test_batch.rb
111
113
  - test/test_executable.rb
112
114
  - test/test_exiftool_stuff.rb
113
115
  - test/test_functional_api.rb
@@ -123,7 +125,7 @@ metadata: {}
123
125
  post_install_message: "\n+-----------------------------------------------------------------------+\n|
124
126
  Please ensure you have installed exiftool version 7.65 or higher and |\n| it's
125
127
  found in your PATH (Try \"exiftool -ver\" on your commandline). |\n| For more
126
- details see |\n| http://www.sno.phy.queensu.ca/~phil/exiftool/install.html
128
+ details see |\n| https://exiftool.org/install.html
127
129
  \ |\n+-----------------------------------------------------------------------+\n
128
130
  \ "
129
131
  rdoc_options: []
@@ -144,5 +146,5 @@ requirements:
144
146
  rubygems_version: 3.1.2
145
147
  signing_key:
146
148
  specification_version: 4
147
- summary: This library is a wrapper for the ExifTool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool).
149
+ summary: This library is a wrapper for the ExifTool command-line application (https://exiftool.org).
148
150
  test_files: []