multi_exiftool 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.aspell.pws +1 -1
- data/Changelog +3 -0
- data/README.md +20 -0
- data/lib/multi_exiftool.rb +64 -44
- data/multi_exiftool.gemspec +3 -3
- data/test/test_functional_api.rb +58 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99d1a39d6b7f86838edecca534c52316000eab5672381af22fd1917a0f0db2d5
|
4
|
+
data.tar.gz: bf6f42b5424c6f32c0f1e99b9869185ccb578e936d66df6799d3e24a53b8efc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb7d247b98ca7e00ed5f0380f1780ca91c0792bca46b24756d09984a5852b7fec216da28a960ac7c517593db62537c8f6bee21e228ac1ee4bc3a349de1961937
|
7
|
+
data.tar.gz: 8642935529ad89d65e9dea387b46a0ab340a7ef0ad7a816b18d4ef4d4665b8fe9f1cc2169c7e23f0ea0983c6114ed15d164e3c47fc0457cea71109024f0239ff
|
data/.aspell.pws
CHANGED
data/Changelog
CHANGED
data/README.md
CHANGED
@@ -60,6 +60,26 @@ else
|
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
63
|
+
### Deleting
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
# Delete ALL values
|
67
|
+
errors = MultiExiftool.delete_values(Dir['*.jpg'])
|
68
|
+
if errors.empty?
|
69
|
+
puts 'ok'
|
70
|
+
else
|
71
|
+
puts writer.errors
|
72
|
+
end
|
73
|
+
|
74
|
+
# Delete values for tags Author and Title
|
75
|
+
errors = MultiExiftool.delete_values(Dir['*.jpg'], tags: %w(author title))
|
76
|
+
if errors.empty?
|
77
|
+
puts 'ok'
|
78
|
+
else
|
79
|
+
puts writer.errors
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
63
83
|
### Further Examples
|
64
84
|
|
65
85
|
See the examples in the examples directory.
|
data/lib/multi_exiftool.rb
CHANGED
@@ -7,55 +7,73 @@ require_relative 'multi_exiftool/writer'
|
|
7
7
|
|
8
8
|
module MultiExiftool
|
9
9
|
|
10
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.9.0'
|
11
11
|
|
12
|
-
|
13
|
-
# Be aware: it returns an array of two elements:
|
14
|
-
# values, errors
|
15
|
-
#
|
16
|
-
# Example:
|
17
|
-
# values, errors = MultiExiftool.read(Dir['*.jpg'])
|
18
|
-
# if errors.empty?
|
19
|
-
# values.each {|val| do_something_with(val) }
|
20
|
-
# else
|
21
|
-
# # error handling
|
22
|
-
# end
|
23
|
-
def self.read(filenames, opts={})
|
24
|
-
reader = Reader.new
|
25
|
-
reader.filenames = filenames
|
26
|
-
if val = opts.delete(:tags)
|
27
|
-
reader.tags = val
|
28
|
-
end
|
29
|
-
if val = opts.delete(:group)
|
30
|
-
reader.group = val
|
31
|
-
end
|
32
|
-
reader.options = opts unless opts.empty?
|
33
|
-
values = reader.read
|
34
|
-
[values, reader.errors]
|
35
|
-
end
|
12
|
+
@exiftool_command = 'exiftool'
|
36
13
|
|
37
|
-
|
38
|
-
# Returns an array of the error messages
|
39
|
-
#
|
40
|
-
# Example:
|
41
|
-
# errors = MultiExiftool.write(Dir['*.jpg'], {author: 'Jan Friedrich'})
|
42
|
-
# unless errors.empty?
|
43
|
-
# # do error handling
|
44
|
-
# end
|
45
|
-
def self.write(filenames, values, opts={})
|
46
|
-
writer = Writer.new
|
47
|
-
writer.filenames = filenames
|
48
|
-
writer.values = values
|
49
|
-
writer.options = opts unless opts.empty?
|
50
|
-
writer.write
|
51
|
-
writer.errors
|
52
|
-
end
|
14
|
+
class << self
|
53
15
|
|
54
|
-
|
16
|
+
# Reading metadata
|
17
|
+
# Be aware: it returns an array of two elements:
|
18
|
+
# values, errors
|
19
|
+
#
|
20
|
+
# Example:
|
21
|
+
# values, errors = MultiExiftool.read(Dir['*.jpg'])
|
22
|
+
# if errors.empty?
|
23
|
+
# values.each {|val| do_something_with(val) }
|
24
|
+
# else
|
25
|
+
# # error handling
|
26
|
+
# end
|
27
|
+
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?
|
37
|
+
values = reader.read
|
38
|
+
[values, reader.errors]
|
39
|
+
end
|
55
40
|
|
56
|
-
|
41
|
+
# Writing metadata
|
42
|
+
# Returns an array of the error messages
|
43
|
+
#
|
44
|
+
# Example:
|
45
|
+
# errors = MultiExiftool.write(Dir['*.jpg'], {author: 'Jan Friedrich'})
|
46
|
+
# unless errors.empty?
|
47
|
+
# # do error handling
|
48
|
+
# end
|
49
|
+
def write filenames, values, opts={}
|
50
|
+
writer = Writer.new
|
51
|
+
writer.filenames = filenames
|
52
|
+
writer.values = values
|
53
|
+
writer.options = opts unless opts.empty?
|
54
|
+
writer.write
|
55
|
+
writer.errors
|
56
|
+
end
|
57
57
|
|
58
|
-
|
58
|
+
# Deleting metadata
|
59
|
+
# Returns an array of the error messages
|
60
|
+
#
|
61
|
+
# Examples:
|
62
|
+
# # delete values for all tags
|
63
|
+
# errors = MultiExiftool.delete_values(Dir['*.jpg'])
|
64
|
+
# unless errors.empty?
|
65
|
+
# # do error handling
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# # delete values for tags Author and Title
|
69
|
+
# errors = MultiExiftool.delete_values(Dir['*.jpg'], %w[author title])
|
70
|
+
# unless errors.empty?
|
71
|
+
# # do error handling
|
72
|
+
# end
|
73
|
+
def delete_values filenames, tags: :all
|
74
|
+
values = Array(tags).inject(Hash.new) {|h,tag| h[tag] = nil; h}
|
75
|
+
write(filenames, values)
|
76
|
+
end
|
59
77
|
|
60
78
|
attr_accessor :exiftool_command
|
61
79
|
attr_reader :exiftool_version
|
@@ -73,5 +91,7 @@ module MultiExiftool
|
|
73
91
|
|
74
92
|
end
|
75
93
|
|
94
|
+
class Error < ::StandardError; end
|
95
|
+
|
76
96
|
end
|
77
97
|
|
data/multi_exiftool.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: multi_exiftool 0.
|
2
|
+
# stub: multi_exiftool 0.9.0 ruby lib
|
3
3
|
#
|
4
4
|
# This file is automatically generated by rim.
|
5
5
|
# PLEASE DO NOT EDIT IT DIRECTLY!
|
@@ -7,12 +7,12 @@
|
|
7
7
|
|
8
8
|
Gem::Specification.new do |s|
|
9
9
|
s.name = "multi_exiftool"
|
10
|
-
s.version = "0.
|
10
|
+
s.version = "0.9.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 = "2018-04-
|
15
|
+
s.date = "2018-04-09"
|
16
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."
|
17
17
|
s.email = "janfri26@gmail.com"
|
18
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/temp", "test/temp/a.jpg", "test/temp/a.jpg_original", "test/temp/b.jpg", "test/temp/b.jpg_original", "test/temp/c.jpg", "test/temp/c.jpg_original", "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"]
|
data/test/test_functional_api.rb
CHANGED
@@ -32,7 +32,7 @@ class TestFunctionalApi < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
test 'successful reading of
|
35
|
+
test 'successful reading of hierarchical data' do
|
36
36
|
run_in_temp_dir do
|
37
37
|
values, errors = MultiExiftool.read(%w(a.jpg), group: 0)
|
38
38
|
res = values.first
|
@@ -131,4 +131,61 @@ class TestFunctionalApi < Test::Unit::TestCase
|
|
131
131
|
|
132
132
|
end
|
133
133
|
|
134
|
+
context 'deleting' do
|
135
|
+
|
136
|
+
setup do
|
137
|
+
@filenames = %w(a.jpg b.jpg c.jpg)
|
138
|
+
end
|
139
|
+
|
140
|
+
test 'delete all values' do
|
141
|
+
run_in_temp_dir do
|
142
|
+
errors = MultiExiftool.delete_values(@filenames)
|
143
|
+
assert_equal [], errors
|
144
|
+
values, errors = MultiExiftool.read(@filenames)
|
145
|
+
assert_equal [nil, nil, nil], values.map {|e| e['Author']}
|
146
|
+
assert_equal [nil, nil, nil], values.map {|e| e['FNumber']}
|
147
|
+
assert_equal [nil, nil, nil], values.map {|e| e['Title']}
|
148
|
+
assert_equal [], errors
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
test 'delete values for some tags' do
|
153
|
+
run_in_temp_dir do
|
154
|
+
errors = MultiExiftool.delete_values(@filenames, tags: %w(author title))
|
155
|
+
assert_equal [], errors
|
156
|
+
values, errors = MultiExiftool.read(@filenames)
|
157
|
+
assert_equal [nil, nil, nil], values.map {|e| e['Author']}
|
158
|
+
assert_equal [5.6, 6.7, 8], values.map {|e| e['FNumber']}
|
159
|
+
assert_equal [nil, nil, nil], values.map {|e| e['Title']}
|
160
|
+
assert_equal [], errors
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
test 'delete values for one tag' do
|
165
|
+
run_in_temp_dir do
|
166
|
+
errors = MultiExiftool.delete_values(@filenames, tags: :title)
|
167
|
+
assert_equal [], errors
|
168
|
+
values, errors = MultiExiftool.read(@filenames)
|
169
|
+
assert_equal ['Jan Friedrich'] * 3, values.map {|e| e['Author']}
|
170
|
+
assert_equal [5.6, 6.7, 8], values.map {|e| e['FNumber']}
|
171
|
+
assert_equal [nil, nil, nil], values.map {|e| e['Title']}
|
172
|
+
assert_equal [], errors
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
test 'error if tags do not exist' do
|
177
|
+
run_in_temp_dir do
|
178
|
+
errors = MultiExiftool.delete_values(@filenames, tags: %w[foo bar])
|
179
|
+
err1, err2, err3 = errors
|
180
|
+
expected1 = /^Warning: Tag 'foo' is not (defined|supported)$/
|
181
|
+
expected2 = /^Warning: Tag 'bar' is not (defined|supported)$/
|
182
|
+
expected3 = 'Nothing to do.'
|
183
|
+
assert_match expected1, err1
|
184
|
+
assert_match expected2, err2
|
185
|
+
assert_equal expected3, err3
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
134
191
|
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.
|
4
|
+
version: 0.9.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: 2018-04-
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|