multi_exiftool 0.18.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog +12 -0
- data/README.md +36 -27
- data/examples/01_simple_reading.rb +13 -0
- data/examples/02_simple_writing.rb +19 -0
- data/examples/03_reading_using_groups.rb +28 -0
- data/examples/04_writing_using_groups.rb +33 -0
- data/examples/05_functional_api.rb +37 -0
- data/lib/multi_exiftool/batch.rb +11 -2
- data/lib/multi_exiftool/executable.rb +22 -33
- data/lib/multi_exiftool/messages.rb +69 -0
- data/lib/multi_exiftool/options.rb +207 -0
- data/lib/multi_exiftool/reader.rb +12 -24
- data/lib/multi_exiftool/{values.rb → reader_values.rb} +16 -19
- data/lib/multi_exiftool/writer.rb +26 -30
- data/lib/multi_exiftool/writer_values.rb +91 -0
- data/lib/multi_exiftool.rb +36 -23
- metadata +54 -52
- data/.aspell.pws +0 -35
- data/Gemfile +0 -3
- data/Rakefile +0 -31
- data/multi_exiftool.gemspec +0 -34
- data/regtest/read_all_tags.rb +0 -6
- data/regtest/read_all_tags.yml +0 -112
- data/regtest/test.jpg +0 -0
- data/test/data/a.jpg +0 -0
- data/test/data/b.jpg +0 -0
- data/test/data/c.jpg +0 -0
- data/test/data/example.config +0 -363
- data/test/helper.rb +0 -27
- data/test/test_batch.rb +0 -42
- data/test/test_executable.rb +0 -26
- data/test/test_exiftool_stuff.rb +0 -37
- data/test/test_functional_api.rb +0 -290
- data/test/test_reader.rb +0 -168
- data/test/test_values.rb +0 -202
- data/test/test_values_using_groups.rb +0 -63
- data/test/test_writer.rb +0 -132
- data/test/test_writer_groups.rb +0 -50
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fbd60b9c3d3d1d3a0d3aec0787ace37ee29199e96c0a86d151382af9471842ad
|
|
4
|
+
data.tar.gz: 93982800c2ad3fa29454af2b1597c16930d64467f7c5c28f68b24a07b471326a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de743ed9fef2a208f75b27c4406894e777a0f1198cce55c377e4ab26f07df2cce839056b23811e0f7e1492647b9a193132375fee4040ca0c64cd3e44c60dbb2b
|
|
7
|
+
data.tar.gz: f1f729a77f830ba995f133f2681c942db81297ede87b4bae949cd644db86c24c1cf7a227c410128e477ed6d63843b91c90842aa64aa0361be025d53905c25668
|
data/Changelog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
1.0.0
|
|
2
|
+
Better API with flexible parameters.
|
|
3
|
+
|
|
4
|
+
Breaking changes:
|
|
5
|
+
- Ruby 2.3 or higher is required.
|
|
6
|
+
- Methods that previously returned an array of error strings now return a message object instead (e.g., change `errors = writer.write; puts errors` to `messages = writer.write; puts messages.errors_or_warnings`).
|
|
7
|
+
- Options in `Reader` or `Writer` instances are now accessible via the options or opts attribute readers (e.g., change `reader.numerical = true` to `reader.opts.numerical = true`).
|
|
8
|
+
|
|
9
|
+
0.19.0
|
|
10
|
+
Maintenance release: Upgrade to rim 3.0 for development and minimize gem file
|
|
11
|
+
size.
|
|
12
|
+
|
|
1
13
|
0.18.1
|
|
2
14
|
Fix a bug with large output which causes the hanging when reading data.
|
|
3
15
|
|
data/README.md
CHANGED
|
@@ -8,6 +8,14 @@ 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.
|
|
10
10
|
|
|
11
|
+
## Upgrade from multi_exiftool version < 1.0
|
|
12
|
+
|
|
13
|
+
- Starting with version 1.0, Ruby 2.3 or higher is required.
|
|
14
|
+
- Methods that previously returned an array of error strings now return a message object instead (e.g., change `errors = writer.write; puts errors` to `messages = writer.write; puts messages.errors_or_warnings`).
|
|
15
|
+
- Options in `Reader` or `Writer` instances are now accessible via the options or opts attribute readers (e.g., change `reader.numerical = true` to `reader.opts.numerical = true`).
|
|
16
|
+
|
|
17
|
+
See also the examples below and in the `examples` directory, as well as the test suite.
|
|
18
|
+
|
|
11
19
|
## Examples
|
|
12
20
|
|
|
13
21
|
### Reading
|
|
@@ -19,17 +27,18 @@ require 'multi_exiftool'
|
|
|
19
27
|
reader = MultiExiftool::Reader.new
|
|
20
28
|
reader.filenames = Dir['*.jpg']
|
|
21
29
|
results = reader.read
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
messages = reader.messages
|
|
31
|
+
if messages.errors_or_warnings?
|
|
32
|
+
$stderr.puts messages.errors_and_warnings
|
|
24
33
|
end
|
|
25
34
|
results.each do |values|
|
|
26
35
|
puts "#{values.file_name}: #{values.comment}"
|
|
27
36
|
end
|
|
28
37
|
|
|
29
38
|
# Functional approach
|
|
30
|
-
results,
|
|
31
|
-
|
|
32
|
-
$stderr.puts
|
|
39
|
+
results, messages = MultiExiftool.read(Dir['*.jpg'])
|
|
40
|
+
if messages.errors_or_warnings?
|
|
41
|
+
$stderr.puts messages.errors_and_warnings
|
|
33
42
|
end
|
|
34
43
|
results.each do |values|
|
|
35
44
|
puts "#{values.file_name}: #{values.comment}"
|
|
@@ -48,15 +57,15 @@ writer.values = {creator: 'Jan Friedrich', copyright: 'Public Domain'}
|
|
|
48
57
|
if writer.write
|
|
49
58
|
puts 'ok'
|
|
50
59
|
else
|
|
51
|
-
puts writer.
|
|
60
|
+
puts writer.messages.errors_and_warnings
|
|
52
61
|
end
|
|
53
62
|
|
|
54
63
|
# Functional approach
|
|
55
|
-
|
|
56
|
-
if
|
|
64
|
+
messages = MultiExiftool.write(Dir['*.jpg'], {creator: 'Jan Friedrich', copyright: 'Public Domain'})
|
|
65
|
+
if !messages.warnings_or_errors?
|
|
57
66
|
puts 'ok'
|
|
58
67
|
else
|
|
59
|
-
puts
|
|
68
|
+
puts messages.warnings_and_errors
|
|
60
69
|
end
|
|
61
70
|
```
|
|
62
71
|
|
|
@@ -75,32 +84,32 @@ end
|
|
|
75
84
|
if batch.execute
|
|
76
85
|
puts 'ok'
|
|
77
86
|
else
|
|
78
|
-
puts batch.
|
|
87
|
+
puts batch.messages.errors_and_warnings
|
|
79
88
|
end
|
|
80
89
|
|
|
81
90
|
# Functional approach
|
|
82
91
|
|
|
83
|
-
|
|
92
|
+
messages = MultiExiftool.batch do
|
|
84
93
|
Dir['*.jpg'].each_with_index do |filename, i|
|
|
85
94
|
values = {creator: 'Jan Friedrich', copyright: 'Public Domain', comment: "This is file number #{i+1}."}
|
|
86
95
|
write filename, values
|
|
87
96
|
end
|
|
88
97
|
end
|
|
89
|
-
if
|
|
98
|
+
if !messages.errors_or_warnings?
|
|
90
99
|
puts 'ok'
|
|
91
100
|
else
|
|
92
|
-
puts
|
|
101
|
+
puts messages.errors_and_warnings
|
|
93
102
|
end
|
|
94
103
|
|
|
95
104
|
# or alternative with block parameter as yielded Batch instance
|
|
96
105
|
|
|
97
|
-
|
|
106
|
+
messages = MultiExiftool.batch do |batch|
|
|
98
107
|
Dir['*.jpg'].each_with_index do |filename, i|
|
|
99
108
|
values = {creator: 'Jan Friedrich', copyright: 'Public Domain', comment: "This is file number #{i+1}."}
|
|
100
109
|
batch.write filename, values
|
|
101
110
|
end
|
|
102
111
|
end
|
|
103
|
-
if
|
|
112
|
+
if !messages.errors_or_warnings?
|
|
104
113
|
puts 'ok'
|
|
105
114
|
else
|
|
106
115
|
puts errors
|
|
@@ -112,19 +121,19 @@ end
|
|
|
112
121
|
|
|
113
122
|
```ruby
|
|
114
123
|
# Delete ALL values
|
|
115
|
-
|
|
116
|
-
if
|
|
124
|
+
messages = MultiExiftool.delete_values(Dir['*.jpg'])
|
|
125
|
+
if !messages.errors_or_warnings?
|
|
117
126
|
puts 'ok'
|
|
118
127
|
else
|
|
119
|
-
puts
|
|
128
|
+
puts messages.errors_and_warnings
|
|
120
129
|
end
|
|
121
130
|
|
|
122
131
|
# Delete values for tags Author and Title
|
|
123
|
-
|
|
124
|
-
if
|
|
132
|
+
messages = MultiExiftool.delete_values(Dir['*.jpg'], tags: %w(author title))
|
|
133
|
+
if !messages.warnings_or_errors?
|
|
125
134
|
puts 'ok'
|
|
126
135
|
else
|
|
127
|
-
puts
|
|
136
|
+
puts messages.errors_and_warnings
|
|
128
137
|
end
|
|
129
138
|
```
|
|
130
139
|
|
|
@@ -141,7 +150,7 @@ following conversions are implemented at the moment:
|
|
|
141
150
|
* Timestamps => Time (with local time zone of no one given)
|
|
142
151
|
* values of form "n/m" => Rational except PartOfSet and Track
|
|
143
152
|
|
|
144
|
-
The conversion is done in the method
|
|
153
|
+
The conversion is done in the method ReaderValues#convert. So you can change it's
|
|
145
154
|
behaviour as following examples show.
|
|
146
155
|
|
|
147
156
|
### Example 1
|
|
@@ -153,7 +162,7 @@ module MyConversion
|
|
|
153
162
|
end
|
|
154
163
|
end
|
|
155
164
|
|
|
156
|
-
MultiExiftool::
|
|
165
|
+
MultiExiftool::ReaderValues.prepend MyConversion
|
|
157
166
|
```
|
|
158
167
|
|
|
159
168
|
### Example 2
|
|
@@ -174,7 +183,7 @@ module MultiExiftool
|
|
|
174
183
|
end
|
|
175
184
|
end
|
|
176
185
|
|
|
177
|
-
|
|
186
|
+
ReaderValues.prepend MyConversion
|
|
178
187
|
end
|
|
179
188
|
```
|
|
180
189
|
|
|
@@ -183,17 +192,17 @@ end
|
|
|
183
192
|
```ruby
|
|
184
193
|
m = Module.new do
|
|
185
194
|
def convert tag, val
|
|
186
|
-
if val =~ MultiExiftool::
|
|
195
|
+
if val =~ MultiExiftool::ReaderValues::REGEXP_TIMESTAMP
|
|
187
196
|
val # no conversion
|
|
188
197
|
else
|
|
189
198
|
super # use default conversion
|
|
190
199
|
end
|
|
191
200
|
end
|
|
192
201
|
end
|
|
193
|
-
MultiExiftool::
|
|
202
|
+
MultiExiftool::ReaderValues.prepend m
|
|
194
203
|
```
|
|
195
204
|
|
|
196
|
-
The method
|
|
205
|
+
The method ReaderValues#convert is called each time a value is fetched.
|
|
197
206
|
|
|
198
207
|
|
|
199
208
|
## Requirements
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'multi_exiftool'
|
|
2
|
+
|
|
3
|
+
if ARGV.empty?
|
|
4
|
+
$stderr.puts 'No filenames given.'
|
|
5
|
+
exit -1
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
reader = MultiExiftool::Reader.new
|
|
9
|
+
reader.filenames = ARGV
|
|
10
|
+
results = reader.read
|
|
11
|
+
results.each do |values|
|
|
12
|
+
puts "#{values.file_name}: #{values.comment}"
|
|
13
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'multi_exiftool'
|
|
2
|
+
|
|
3
|
+
if ARGV.empty?
|
|
4
|
+
$stderr.puts 'No filenames given.'
|
|
5
|
+
exit -1
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
puts 'Please enter a comment for the given files:'
|
|
9
|
+
comment = $stdin.gets.chomp
|
|
10
|
+
|
|
11
|
+
writer = MultiExiftool::Writer.new
|
|
12
|
+
writer.filenames = ARGV
|
|
13
|
+
writer.options.overwrite_original = true
|
|
14
|
+
writer.values = {comment: comment}
|
|
15
|
+
if writer.write
|
|
16
|
+
puts 'ok'
|
|
17
|
+
else
|
|
18
|
+
puts writer.messages.warnings_and_errors.join("\n")
|
|
19
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'multi_exiftool'
|
|
2
|
+
|
|
3
|
+
if ARGV.empty?
|
|
4
|
+
$stderr.puts 'No filenames given.'
|
|
5
|
+
exit -1
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
reader = MultiExiftool::Reader.new
|
|
9
|
+
reader.filenames = ARGV
|
|
10
|
+
reader.opts.group = 0
|
|
11
|
+
results = reader.read
|
|
12
|
+
results.each do |values|
|
|
13
|
+
# direct access
|
|
14
|
+
puts values.file.filename
|
|
15
|
+
# access via block without parameter
|
|
16
|
+
values.iptc do
|
|
17
|
+
self.keywords do
|
|
18
|
+
puts " Keywords (IPCT): #{Array(self).join(', ')}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
# access via block with parameter
|
|
22
|
+
values.xmp do |xmp|
|
|
23
|
+
xmp.keywords do |kw|
|
|
24
|
+
puts " Keywords (XMP): #{Array(kw).join(', ')}"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'multi_exiftool'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
if ARGV.empty?
|
|
5
|
+
$stderr.puts 'No filenames given.'
|
|
6
|
+
exit -1
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
puts 'Please enter a description for the given files:'
|
|
10
|
+
description = $stdin.gets.chomp
|
|
11
|
+
|
|
12
|
+
puts 'Please enter a caption for the given files:'
|
|
13
|
+
caption = $stdin.gets.chomp
|
|
14
|
+
|
|
15
|
+
writer = MultiExiftool::Writer.new
|
|
16
|
+
writer.filenames = ARGV
|
|
17
|
+
|
|
18
|
+
# specifying group by prefix
|
|
19
|
+
writer.values = {'exif:imagedescription' => description, 'xmp:description' => description}
|
|
20
|
+
|
|
21
|
+
# specifying group hierarchical
|
|
22
|
+
writer.values.merge! YAML.load <<-END
|
|
23
|
+
iptc:
|
|
24
|
+
caption-abstract: #{caption}
|
|
25
|
+
xmp:
|
|
26
|
+
caption: #{caption}
|
|
27
|
+
END
|
|
28
|
+
|
|
29
|
+
if writer.write
|
|
30
|
+
puts 'ok'
|
|
31
|
+
else
|
|
32
|
+
puts writer.messages.warnings_and_errors.join("\n")
|
|
33
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'multi_exiftool'
|
|
2
|
+
|
|
3
|
+
if ARGV.empty?
|
|
4
|
+
$stderr.puts 'No filenames given.'
|
|
5
|
+
exit -1
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Reading only the tags Orientation and Rotation using the -n option of exiftool
|
|
9
|
+
results, messages = MultiExiftool.read(ARGV, tags: %w[orientation rotation], numerical: true)
|
|
10
|
+
|
|
11
|
+
if messages.errors_or_warnings?
|
|
12
|
+
$stderr.puts reader.messages.warnings_and_errors
|
|
13
|
+
exit 1
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Ensuring that for all files with EXIF rotation value of 76 the EXIF value orientation is 6
|
|
17
|
+
# and for EXIF rotation value 82 the EXIF orientation value is 8
|
|
18
|
+
|
|
19
|
+
# Determine the filenames
|
|
20
|
+
update_orientation_to_6 = results.select {|r| r.rotation == 76 && r.orientation != 6}.map {|r| r.sourcefile}
|
|
21
|
+
update_orientation_to_8 = results.select {|r| r.rotation == 82 && r.orientation != 8}.map {|r| r.sourcefile}
|
|
22
|
+
|
|
23
|
+
# Update
|
|
24
|
+
errors_and_warnings = []
|
|
25
|
+
unless update_orientation_to_6.empty?
|
|
26
|
+
messages = MultiExiftool.write(update_orientation_to_6, {orientation: 6}, numerical: true, overwrite_original: true)
|
|
27
|
+
errors_and_warnings += messages.errors_and_warnings
|
|
28
|
+
end
|
|
29
|
+
unless update_orientation_to_8.empty?
|
|
30
|
+
messages = MultiExiftool.write(update_orientation_to_8, {orientation: 8}, numerical: true, overwrite_original: true)
|
|
31
|
+
errors_and_warnings += messages.errors_and_warnings
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
unless errors_and_warnings.empty?
|
|
35
|
+
$stderr.puts reader.errors
|
|
36
|
+
exit 1
|
|
37
|
+
end
|
data/lib/multi_exiftool/batch.rb
CHANGED
|
@@ -13,13 +13,15 @@ module MultiExiftool
|
|
|
13
13
|
|
|
14
14
|
# Define batch operation inside a block
|
|
15
15
|
def initialize &blk
|
|
16
|
+
super()
|
|
16
17
|
@writers = []
|
|
17
18
|
instance_exec &blk if block_given?
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
# Define a write operation for the batch.
|
|
21
|
-
def write filenames, values,
|
|
22
|
-
w = MultiExiftool::Writer.new(filenames, values,
|
|
22
|
+
def write filenames=[], values=nil, **vals_and_opts
|
|
23
|
+
w = MultiExiftool::Writer.new(filenames, values, **vals_and_opts)
|
|
24
|
+
w.options = options.merge(w.options)
|
|
23
25
|
@writers << w
|
|
24
26
|
end
|
|
25
27
|
|
|
@@ -30,6 +32,13 @@ module MultiExiftool
|
|
|
30
32
|
@writers.map {|w| w.exiftool_args + ['-execute']}.flatten
|
|
31
33
|
end
|
|
32
34
|
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def prepare_execution
|
|
38
|
+
super
|
|
39
|
+
fail MultiExiftool::Error if @writers.empty?
|
|
40
|
+
end
|
|
41
|
+
|
|
33
42
|
end
|
|
34
43
|
|
|
35
44
|
end
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'options'
|
|
4
5
|
require 'open3'
|
|
5
6
|
|
|
7
|
+
require_relative 'messages'
|
|
8
|
+
|
|
6
9
|
module MultiExiftool
|
|
7
10
|
|
|
8
11
|
# Mixin for Reader and Writer.
|
|
9
12
|
module Executable
|
|
10
13
|
|
|
11
|
-
attr_reader :
|
|
12
|
-
attr_accessor :
|
|
14
|
+
attr_reader :messages
|
|
15
|
+
attr_accessor :filenames, :options
|
|
13
16
|
|
|
14
|
-
def initialize filenames=[], options
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@option_mapping = {numerical: :n}
|
|
18
|
-
if val = options.delete(:config)
|
|
19
|
-
@config = val
|
|
20
|
-
end
|
|
17
|
+
def initialize filenames=[], **options
|
|
18
|
+
self.options = options
|
|
19
|
+
self.filenames = filenames
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
def options
|
|
24
|
-
opts
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
def options= opts
|
|
23
|
+
unless opts.kind_of? Options
|
|
24
|
+
opts = Options.new(opts)
|
|
25
|
+
end
|
|
26
|
+
@options = opts
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def filenames= value
|
|
@@ -36,33 +36,22 @@ module MultiExiftool
|
|
|
36
36
|
parse_results
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
alias opts options
|
|
40
|
+
|
|
39
41
|
private
|
|
40
42
|
|
|
41
43
|
def exiftool_command
|
|
42
44
|
MultiExiftool.exiftool_command
|
|
43
45
|
end
|
|
44
46
|
|
|
45
|
-
def options_args
|
|
46
|
-
opts = options
|
|
47
|
-
return [] if opts.empty?
|
|
48
|
-
opts.map do |opt, val|
|
|
49
|
-
arg = @option_mapping[opt] || opt
|
|
50
|
-
if val == true
|
|
51
|
-
"-#{arg}"
|
|
52
|
-
else
|
|
53
|
-
%W[-#{arg} #{val}]
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
47
|
def prepare_execution
|
|
59
|
-
@
|
|
48
|
+
@messages = Messages.new([])
|
|
60
49
|
end
|
|
61
50
|
|
|
62
51
|
def execute_command
|
|
63
52
|
args = ['-@', '-']
|
|
64
|
-
if @config
|
|
65
|
-
args = ['-config',
|
|
53
|
+
if c = @options.config
|
|
54
|
+
args = ['-config', c] + args
|
|
66
55
|
end
|
|
67
56
|
stdin, @stdout, @stderr = Open3.popen3(exiftool_command, *args)
|
|
68
57
|
exiftool_args.each do |part|
|
|
@@ -73,12 +62,12 @@ module MultiExiftool
|
|
|
73
62
|
end
|
|
74
63
|
|
|
75
64
|
def parse_results
|
|
76
|
-
|
|
77
|
-
|
|
65
|
+
parse_messages
|
|
66
|
+
!@messages.errors_or_warnings?
|
|
78
67
|
end
|
|
79
68
|
|
|
80
|
-
def
|
|
81
|
-
@
|
|
69
|
+
def parse_messages
|
|
70
|
+
@messages = Messages.new(@stderr.readlines(chomp: true) + @stdout.readlines(chomp: true))
|
|
82
71
|
end
|
|
83
72
|
|
|
84
73
|
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module MultiExiftool
|
|
5
|
+
|
|
6
|
+
# Represents messages of different types of the execution of ExifTool calls
|
|
7
|
+
class Messages
|
|
8
|
+
|
|
9
|
+
attr_reader :all, :errors, :infos, :warnings
|
|
10
|
+
|
|
11
|
+
def initialize messages
|
|
12
|
+
@all = messages
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def errors
|
|
16
|
+
@errors ||= @all.select {|m| m =~ /^Error: /}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def infos
|
|
20
|
+
@infos ||= @all.reject {|m| m =~ /^(Error|Warning): /}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def warnings
|
|
24
|
+
@warnings ||= @all.select {|m| m =~ /^Warning: /}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def errors_and_warnings
|
|
28
|
+
@errors_and_warnings ||= @all.select {|m| m =~ /^(Error|Warning): /}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
alias warnings_and_errors errors_and_warnings
|
|
32
|
+
|
|
33
|
+
def deconstruct_keys keys
|
|
34
|
+
if keys.nil?
|
|
35
|
+
return deconstruct_keys(%i(all errors infos warnings errors_and_warnings warnings_and_errors))
|
|
36
|
+
end
|
|
37
|
+
res = {}
|
|
38
|
+
keys.each do |k|
|
|
39
|
+
if self.respond_to? k
|
|
40
|
+
res[k] = self.send(k)
|
|
41
|
+
else
|
|
42
|
+
return {}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
return res
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def errors?
|
|
49
|
+
!errors.empty?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def infos?
|
|
53
|
+
!infos.empty?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def warnings?
|
|
57
|
+
!warnings.empty?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def errors_or_warnings?
|
|
61
|
+
!errors_and_warnings.empty?
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
alias warnings_or_errors? errors_or_warnings?
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
end
|