mini_exiftool 0.6.0 → 0.7.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.
- data/Changelog +8 -0
- data/lib/mini_exiftool.rb +24 -16
- data/test/data/test.jpg +0 -0
- data/test/test_class_methods.rb +18 -0
- data/test/test_composite.rb +2 -2
- data/test/test_dumping.rb +5 -5
- data/test/test_read.rb +6 -0
- data/test/test_save.rb +13 -0
- metadata +3 -3
data/Changelog
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
Version 0.7.0
|
2
|
+
- Changing composite behaviour: Composite tags are now included as standard!
|
3
|
+
- New method MiniExiftool.opts which returns a hash of the standard
|
4
|
+
options used for MiniExiftool.new
|
5
|
+
- New option :convert_encoding for MiniExiftool.new which uses the -L-option
|
6
|
+
of the exiftool command-line application (see online documentation for it)
|
7
|
+
Thanks to Henning Kulander for the causing of this change.
|
8
|
+
|
1
9
|
Version 0.6.0
|
2
10
|
- New methods for serialization:
|
3
11
|
- MiniExiftool.from_hash
|
data/lib/mini_exiftool.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# Read and write access is done in a clean OO manner.
|
8
8
|
#
|
9
9
|
# Author: Jan Friedrich
|
10
|
-
# Copyright (c) 2007 by Jan Friedrich
|
10
|
+
# Copyright (c) 2007, 2008 by Jan Friedrich
|
11
11
|
# Licensed under the GNU LESSER GENERAL PUBLIC LICENSE,
|
12
12
|
# Version 2.1, February 1999
|
13
13
|
#
|
@@ -24,15 +24,20 @@ class MiniExiftool
|
|
24
24
|
# Name of the Exiftool command-line application
|
25
25
|
@@cmd = 'exiftool'
|
26
26
|
|
27
|
+
# Hash of the standard options used when call MiniExiftool.new
|
28
|
+
@@opts = { :numerical => false, :composite => true, :convert_encoding => false, :timestamps => Time }
|
29
|
+
|
27
30
|
attr_reader :filename
|
28
|
-
attr_accessor :numerical, :composite, :errors, :timestamps
|
31
|
+
attr_accessor :numerical, :composite, :convert_encoding, :errors, :timestamps
|
29
32
|
|
30
|
-
VERSION = '0.
|
33
|
+
VERSION = '0.7.0'
|
31
34
|
|
32
35
|
# +opts+ support at the moment
|
33
36
|
# * <code>:numerical</code> for numerical values, default is +false+
|
34
37
|
# * <code>:composite</code> for including composite tags while loading,
|
35
|
-
# default is +
|
38
|
+
# default is +true+
|
39
|
+
# * <code>:convert_encoding</code> convert encoding (See -L-option of
|
40
|
+
# the exiftool command-line application, default is +false+
|
36
41
|
# * <code>:timestamps</code> generating DateTime objects instead of
|
37
42
|
# Time objects if set to <code>DateTime</code>, default is +Time+
|
38
43
|
#
|
@@ -40,10 +45,10 @@ class MiniExiftool
|
|
40
45
|
# therefore they use <em>your local timezone</em>, DateTime objects instead
|
41
46
|
# are created <em>without timezone</em>!
|
42
47
|
def initialize filename=nil, opts={}
|
43
|
-
|
44
|
-
opts = std_opts.update opts
|
48
|
+
opts = @@opts.merge opts
|
45
49
|
@numerical = opts[:numerical]
|
46
50
|
@composite = opts[:composite]
|
51
|
+
@convert_encoding = opts[:convert_encoding]
|
47
52
|
@timestamps = opts[:timestamps]
|
48
53
|
@values = TagHash.new
|
49
54
|
@tag_names = TagHash.new
|
@@ -75,6 +80,7 @@ class MiniExiftool
|
|
75
80
|
opt_params = ''
|
76
81
|
opt_params << (@numerical ? '-n ' : '')
|
77
82
|
opt_params << (@composite ? '' : '-e ')
|
83
|
+
opt_params << (@convert_encoding ? '-L ' : '')
|
78
84
|
cmd = %Q(#@@cmd -q -q -s -t #{opt_params} "#{filename}")
|
79
85
|
if run(cmd)
|
80
86
|
parse_output
|
@@ -143,7 +149,9 @@ class MiniExiftool
|
|
143
149
|
@changed_values.each do |tag, val|
|
144
150
|
original_tag = MiniExiftool.original_tag(tag)
|
145
151
|
converted_val = convert val
|
146
|
-
opt_params =
|
152
|
+
opt_params = ''
|
153
|
+
opt_params << (converted_val.kind_of?(Numeric) ? '-n ' : '')
|
154
|
+
opt_params << (@convert_encoding ? '-L ' : '')
|
147
155
|
cmd = %Q(#@@cmd -q -P -overwrite_original #{opt_params} -#{original_tag}="#{converted_val}" "#{temp_filename}")
|
148
156
|
result = run(cmd)
|
149
157
|
unless result
|
@@ -198,6 +206,11 @@ class MiniExiftool
|
|
198
206
|
@@cmd = cmd
|
199
207
|
end
|
200
208
|
|
209
|
+
# Returns the options hash.
|
210
|
+
def self.opts
|
211
|
+
@@opts
|
212
|
+
end
|
213
|
+
|
201
214
|
# Returns a set of all known tags of Exiftool.
|
202
215
|
def self.all_tags
|
203
216
|
unless defined? @@all_tags
|
@@ -320,15 +333,10 @@ class MiniExiftool
|
|
320
333
|
end
|
321
334
|
|
322
335
|
def set_attributes_by_heuristic
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
self.numerical = true
|
328
|
-
end
|
329
|
-
if self.FileModifyDate.kind_of? DateTime
|
330
|
-
self.timestamps = DateTime
|
331
|
-
end
|
336
|
+
self.composite = tags.include?('ImageSize') ? true : false
|
337
|
+
self.numerical = self.file_size.kind_of?(Integer) ? true : false
|
338
|
+
# TODO: Is there a heuristic to determine @convert_encoding?
|
339
|
+
self.timestamps = self.FileModifyDate.kind_of?(DateTime) ? DateTime : Time
|
332
340
|
end
|
333
341
|
|
334
342
|
def temp_filename
|
data/test/data/test.jpg
CHANGED
Binary file
|
data/test/test_class_methods.rb
CHANGED
@@ -49,6 +49,24 @@ class TestClassMethods < TestCase
|
|
49
49
|
MiniExiftool.command = cmd
|
50
50
|
end
|
51
51
|
|
52
|
+
def test_opts
|
53
|
+
opts = MiniExiftool.opts
|
54
|
+
assert_kind_of Hash, opts
|
55
|
+
begin
|
56
|
+
org = MiniExiftool.opts[:composite]
|
57
|
+
met1 = MiniExiftool.new
|
58
|
+
MiniExiftool.opts[:composite] = !org
|
59
|
+
met2 = MiniExiftool.new
|
60
|
+
MiniExiftool.opts[:composite] = org
|
61
|
+
met3 = MiniExiftool.new
|
62
|
+
assert_equal org, met1.composite
|
63
|
+
assert_equal !org, met2.composite
|
64
|
+
assert_equal org, met1.composite
|
65
|
+
ensure
|
66
|
+
MiniExiftool.opts[:composite] = org
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
52
70
|
def test_all_tags
|
53
71
|
all_tags = MiniExiftool.all_tags
|
54
72
|
assert all_tags.include?('ISO')
|
data/test/test_composite.rb
CHANGED
@@ -5,8 +5,8 @@ class TestComposite < TestCase
|
|
5
5
|
def setup
|
6
6
|
@data_dir = File.dirname(__FILE__) + '/data'
|
7
7
|
@filename_test = @data_dir + '/test.jpg'
|
8
|
-
@mini_exiftool = MiniExiftool.new @filename_test
|
9
|
-
@mini_exiftool_c = MiniExiftool.new @filename_test
|
8
|
+
@mini_exiftool = MiniExiftool.new @filename_test, :composite => false
|
9
|
+
@mini_exiftool_c = MiniExiftool.new @filename_test
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_composite_tags
|
data/test/test_dumping.rb
CHANGED
@@ -60,11 +60,11 @@ class TestDumping < TestCase
|
|
60
60
|
|
61
61
|
def test_heuristics_for_restoring_composite
|
62
62
|
standard = @mini_exiftool.to_hash
|
63
|
-
|
64
|
-
assert_equal
|
65
|
-
assert_equal
|
66
|
-
assert_equal
|
67
|
-
assert_equal
|
63
|
+
no_composite = MiniExiftool.new(@filename_test, :composite => false).to_hash
|
64
|
+
assert_equal true, MiniExiftool.from_hash(standard).composite
|
65
|
+
assert_equal false, MiniExiftool.from_hash(no_composite).composite
|
66
|
+
assert_equal true, MiniExiftool.from_yaml(standard.to_yaml).composite
|
67
|
+
assert_equal false, MiniExiftool.from_yaml(no_composite.to_yaml).composite
|
68
68
|
end
|
69
69
|
|
70
70
|
def test_heuristics_for_restoring_numerical
|
data/test/test_read.rb
CHANGED
@@ -28,4 +28,10 @@ class TestRead < TestCase
|
|
28
28
|
assert_kind_of Array, @mini_exiftool['SubjectLocation']
|
29
29
|
end
|
30
30
|
|
31
|
+
def test_encoding_conversion
|
32
|
+
@mini_exiftool_converted = MiniExiftool.new @filename_test, :convert_encoding => true
|
33
|
+
assert_equal 'Abenddämmerung', @mini_exiftool.title
|
34
|
+
assert_equal "Abendd\344mmerung", @mini_exiftool_converted.title
|
35
|
+
end
|
36
|
+
|
31
37
|
end
|
data/test/test_save.rb
CHANGED
@@ -48,4 +48,17 @@ class TestSave < TestCase
|
|
48
48
|
assert_equal @org_md5, Digest::MD5.hexdigest(File.read(@temp_filename))
|
49
49
|
end
|
50
50
|
|
51
|
+
def test_encoding_conversion
|
52
|
+
special_string = 'ÄÖÜ'
|
53
|
+
@mini_exiftool.title = special_string
|
54
|
+
assert @mini_exiftool.save
|
55
|
+
assert_equal false, @mini_exiftool.convert_encoding
|
56
|
+
assert_equal special_string, @mini_exiftool.title
|
57
|
+
@mini_exiftool.convert_encoding = true
|
58
|
+
@mini_exiftool.title = special_string
|
59
|
+
assert @mini_exiftool.save
|
60
|
+
assert_equal true, @mini_exiftool.convert_encoding
|
61
|
+
assert_equal special_string, @mini_exiftool.title
|
62
|
+
end
|
63
|
+
|
51
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_exiftool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Friedrich
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-07 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements: []
|
73
73
|
|
74
74
|
rubyforge_project: miniexiftool
|
75
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.2.0
|
76
76
|
signing_key:
|
77
77
|
specification_version: 2
|
78
78
|
summary: A library for nice OO access to the Exiftool command-line application written by Phil Harvey.
|