mini_exiftool 2.2.1 → 2.3.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 +7 -0
- data/Rakefile +0 -2
- data/lib/mini_exiftool.rb +52 -26
- data/test/data/test_encodings.jpg +0 -0
- data/test/test_encodings.rb +19 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1503e85ca2e2cb25cee0dc50a680d6c1641c8000
|
4
|
+
data.tar.gz: 01bc4385657a026eb0fe93a5a8969c1ceb14665e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40d2c11befb48e3e024b45d770d572ead5dbc088bc8497f10ff9fad5a930bffdbea19ded6da5248f376d7a5442758ed4ff5739cf78dedbfee3161eac98ba04e6
|
7
|
+
data.tar.gz: d4f821e8f2c389e7b0f32f54eea60db3b9d72f1b1bddfbbaba421287550c03181f325348f906e4becd432f25592f0a8f615789545a80b30c799787efaad0dbf2
|
data/Changelog
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
2.3.0
|
2
|
+
- New options :exif_encoding, :iptc_encodings,
|
3
|
+
:xmp_encodings etc. to change specific encodings
|
4
|
+
See -charset option of the exiftool commandline
|
5
|
+
application
|
6
|
+
- Some internal improvements
|
7
|
+
|
1
8
|
2.2.1
|
2
9
|
- Bugfix: Ignore filename specific tags to avoid encoding
|
3
10
|
confusions.
|
data/Rakefile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'rim'
|
2
2
|
require 'rim/check_version'
|
3
3
|
require 'rim/gem'
|
4
|
-
require 'rim/rdoc'
|
5
4
|
require 'rim/test'
|
6
5
|
|
7
6
|
$:.unshift 'lib'
|
@@ -15,7 +14,6 @@ Rim.setup do |p|
|
|
15
14
|
p.summary = 'This library is wrapper for the Exiftool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool).'
|
16
15
|
p.homepage = 'http://gitorious.org/mini_exiftool'
|
17
16
|
p.gem_files << 'Tutorial.rdoc'
|
18
|
-
p.rdoc_files << 'Tutorial.rdoc'
|
19
17
|
p.install_message = %q{
|
20
18
|
+-----------------------------------------------------------------------+
|
21
19
|
| Please ensure you have installed exiftool at least version 7.65 |
|
data/lib/mini_exiftool.rb
CHANGED
@@ -25,6 +25,8 @@ require 'time'
|
|
25
25
|
# Simple OO access to the Exiftool command-line application.
|
26
26
|
class MiniExiftool
|
27
27
|
|
28
|
+
VERSION = '2.3.0'
|
29
|
+
|
28
30
|
# Name of the Exiftool command-line application
|
29
31
|
@@cmd = 'exiftool'
|
30
32
|
|
@@ -35,11 +37,31 @@ class MiniExiftool
|
|
35
37
|
# Encoding of the filesystem (filenames in command line)
|
36
38
|
@@fs_enc = Encoding.find('filesystem')
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
def self.opts_accessor *attrs
|
41
|
+
attrs.each do |a|
|
42
|
+
define_method a do
|
43
|
+
@opts[a]
|
44
|
+
end
|
45
|
+
define_method "#{a}=" do |val|
|
46
|
+
@opts[a] = val
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
attr_reader :filename, :errors
|
52
|
+
|
53
|
+
opts_accessor :numerical, :composite, :ignore_minor_errors,
|
40
54
|
:replace_invalid_chars, :timestamps
|
41
55
|
|
42
|
-
|
56
|
+
@@encoding_types = %w(exif iptc xmp png id3 pdf photoshop quicktime aiff mie vorbis)
|
57
|
+
|
58
|
+
def self.encoding_opt enc_type
|
59
|
+
(enc_type.to_s + '_encoding').to_sym
|
60
|
+
end
|
61
|
+
|
62
|
+
@@encoding_types.each do |enc_type|
|
63
|
+
opts_accessor encoding_opt(enc_type)
|
64
|
+
end
|
43
65
|
|
44
66
|
# +opts+ support at the moment
|
45
67
|
# * <code>:numerical</code> for numerical values, default is +false+
|
@@ -59,20 +81,21 @@ class MiniExiftool
|
|
59
81
|
# <b>ATTENTION:</b> Time objects are created using <code>Time.local</code>
|
60
82
|
# therefore they use <em>your local timezone</em>, DateTime objects instead
|
61
83
|
# are created <em>without timezone</em>!
|
84
|
+
# * <code>:exif_encoding</code>, <code>:iptc_encoding</code>,
|
85
|
+
# <code>:xmp_encoding</code>, <code>:png_encoding</code>,
|
86
|
+
# <code>:id3_encoding</code>, <code>:pdf_encoding</code>,
|
87
|
+
# <code>:photoshop_encoding</code>, <code>:quicktime_encoding</code>,
|
88
|
+
# <code>:aiff_encoding</code>, <code>:mie_encoding</code>,
|
89
|
+
# <code>:vorbis_encoding</code> to set this specific encoding (see
|
90
|
+
# -charset option of the exiftool command-line application, default is
|
91
|
+
# +nil+: no encoding specified)
|
62
92
|
def initialize filename=nil, opts={}
|
63
|
-
opts = @@opts.merge opts
|
64
|
-
@
|
65
|
-
@composite = opts[:composite]
|
66
|
-
if opts[:convert_encoding]
|
93
|
+
@opts = @@opts.merge opts
|
94
|
+
if @opts[:convert_encoding]
|
67
95
|
warn 'Option :convert_encoding is not longer supported!'
|
68
96
|
warn 'Please use the String#encod* methods.'
|
69
97
|
end
|
70
|
-
@ignore_minor_errors = opts[:ignore_minor_errors]
|
71
|
-
@timestamps = opts[:timestamps]
|
72
|
-
@coord_format = opts[:coord_format]
|
73
|
-
@replace_invalid_chars = opts[:replace_invalid_chars]
|
74
98
|
@values = TagHash.new
|
75
|
-
@tag_names = TagHash.new
|
76
99
|
@changed_values = TagHash.new
|
77
100
|
@errors = TagHash.new
|
78
101
|
load filename unless filename.nil?
|
@@ -104,12 +127,16 @@ class MiniExiftool
|
|
104
127
|
end
|
105
128
|
@filename = filename
|
106
129
|
@values.clear
|
107
|
-
@tag_names.clear
|
108
130
|
@changed_values.clear
|
109
131
|
params = '-j '
|
110
|
-
params << (@numerical ? '-n ' : '')
|
111
|
-
params << (@composite ? '' : '-e ')
|
112
|
-
params << (@coord_format ? "-c \"#{@coord_format}\"" : '')
|
132
|
+
params << (@opts[:numerical] ? '-n ' : '')
|
133
|
+
params << (@opts[:composite] ? '' : '-e ')
|
134
|
+
params << (@opts[:coord_format] ? "-c \"#{@opts[:coord_format]}\"" : '')
|
135
|
+
@@encoding_types.each do |enc_type|
|
136
|
+
if enc_val = @opts[MiniExiftool.encoding_opt(enc_type)]
|
137
|
+
params << "-charset #{enc_type}=#{enc_val} "
|
138
|
+
end
|
139
|
+
end
|
113
140
|
if run(cmd_gen(params, @filename))
|
114
141
|
parse_output
|
115
142
|
else
|
@@ -157,7 +184,7 @@ class MiniExiftool
|
|
157
184
|
|
158
185
|
# Returns an array of the tags (original tag names) of the read file.
|
159
186
|
def tags
|
160
|
-
@values.keys.map { |key|
|
187
|
+
@values.keys.map { |key| MiniExiftool.original_tag(key) }
|
161
188
|
end
|
162
189
|
|
163
190
|
# Returns an array of all changed tags.
|
@@ -181,7 +208,7 @@ class MiniExiftool
|
|
181
208
|
arr_val.map! {|e| convert_before_save(e)}
|
182
209
|
params = '-q -P -overwrite_original '
|
183
210
|
params << (arr_val.detect {|x| x.kind_of?(Numeric)} ? '-n ' : '')
|
184
|
-
params << (@ignore_minor_errors ? '-m ' : '')
|
211
|
+
params << (@opts[:ignore_minor_errors] ? '-m ' : '')
|
185
212
|
arr_val.each do |v|
|
186
213
|
params << %Q(-#{original_tag}=#{escape(v)} )
|
187
214
|
end
|
@@ -202,7 +229,7 @@ class MiniExiftool
|
|
202
229
|
def save!
|
203
230
|
unless save
|
204
231
|
err = []
|
205
|
-
|
232
|
+
@errors.each do |key, value|
|
206
233
|
err << "(#{key}) #{value}"
|
207
234
|
end
|
208
235
|
raise MiniExiftool::Error.new("MiniExiftool couldn't save. The following errors occurred: #{err.empty? ? "None" : err.join(", ")}")
|
@@ -214,7 +241,7 @@ class MiniExiftool
|
|
214
241
|
def to_hash
|
215
242
|
result = {}
|
216
243
|
@values.each do |k,v|
|
217
|
-
result[
|
244
|
+
result[MiniExiftool.original_tag(k)] = v
|
218
245
|
end
|
219
246
|
result
|
220
247
|
end
|
@@ -353,8 +380,8 @@ class MiniExiftool
|
|
353
380
|
|
354
381
|
def parse_output
|
355
382
|
@output.force_encoding('UTF-8')
|
356
|
-
if @replace_invalid_chars && !@output.valid_encoding?
|
357
|
-
@output.encode!('UTF-16le', invalid: :replace, replace: @replace_invalid_chars).encode!('UTF-8')
|
383
|
+
if @opts[:replace_invalid_chars] && !@output.valid_encoding?
|
384
|
+
@output.encode!('UTF-16le', invalid: :replace, replace: @opts[:replace_invalid_chars]).encode!('UTF-8')
|
358
385
|
end
|
359
386
|
JSON.parse(@output)[0].each do |tag,value|
|
360
387
|
value = convert_after_load(tag, value)
|
@@ -372,12 +399,12 @@ class MiniExiftool
|
|
372
399
|
when /^\d{4}:\d\d:\d\d \d\d:\d\d:\d\d/
|
373
400
|
s = value.sub(/^(\d+):(\d+):/, '\1-\2-')
|
374
401
|
begin
|
375
|
-
if @timestamps == Time
|
402
|
+
if @opts[:timestamps] == Time
|
376
403
|
value = Time.parse(s)
|
377
|
-
elsif @timestamps == DateTime
|
404
|
+
elsif @opts[:timestamps] == DateTime
|
378
405
|
value = DateTime.parse(s)
|
379
406
|
else
|
380
|
-
raise MiniExiftool::Error.new("Value
|
407
|
+
raise MiniExiftool::Error.new("Value #{@opts[:timestamps]} not allowed for option timestamps.")
|
381
408
|
end
|
382
409
|
rescue ArgumentError
|
383
410
|
value = false
|
@@ -397,7 +424,6 @@ class MiniExiftool
|
|
397
424
|
end
|
398
425
|
|
399
426
|
def set_value tag, value
|
400
|
-
@tag_names[tag] = tag
|
401
427
|
@values[tag] = value
|
402
428
|
end
|
403
429
|
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -- encoding: utf-8 --
|
2
|
+
require 'helpers_for_test'
|
3
|
+
|
4
|
+
class TestEncodings < TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@data_dir = File.dirname(__FILE__) + '/data'
|
8
|
+
@filename_test = @data_dir + '/test_encodings.jpg'
|
9
|
+
@mini_exiftool = MiniExiftool.new @filename_test
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_iptc_encoding
|
13
|
+
object_name = "Möhre"
|
14
|
+
assert_not_equal object_name, @mini_exiftool.object_name
|
15
|
+
correct_iptc = MiniExiftool.new(@filename_test, iptc_encoding: 'MacRoman')
|
16
|
+
assert_equal object_name, correct_iptc.object_name
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_exiftool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.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: 2013-
|
11
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rim
|
@@ -42,12 +42,14 @@ files:
|
|
42
42
|
- test/data/test.jpg
|
43
43
|
- test/data/test.jpg.json
|
44
44
|
- test/data/test_coordinates.jpg
|
45
|
+
- test/data/test_encodings.jpg
|
45
46
|
- test/data/test_special_dates.jpg
|
46
47
|
- test/helpers_for_test.rb
|
47
48
|
- test/test_bad_preview_ifd.rb
|
48
49
|
- test/test_class_methods.rb
|
49
50
|
- test/test_composite.rb
|
50
51
|
- test/test_dumping.rb
|
52
|
+
- test/test_encodings.rb
|
51
53
|
- test/test_filename_access.rb
|
52
54
|
- test/test_from_hash.rb
|
53
55
|
- test/test_invalid_byte_sequence_in_utf8.rb
|