mini_exiftool 2.5.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +6 -0
- data/README.rdoc +1 -1
- data/lib/mini_exiftool.rb +50 -37
- data/test/test_class_methods.rb +2 -2
- data/test/test_io.rb +62 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdeb9b98998342750a3fcbae84d333e667292f58
|
4
|
+
data.tar.gz: c71bdba7f4db16bc4ef8b939d97fbce7bc595117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9d3353b6a770152ae4a914699bfa633ef5d2943ce610b2c72c5fb316a827aa2ac46cb5b93ae66d14fe7ee6d14aad2cee750a94ca540ab83dc9f5227f152a78f
|
7
|
+
data.tar.gz: ee36b1a1febb01b4c83904a55eb5c6539efe24a7749379d6a25107f5445f61d28fbb96b5b65eede550acd8f03ecaf4b379f57b02641bcdcf783d45c33cdabaf6
|
data/Changelog
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
2.6.0
|
2
|
+
- Support reading from IO instances.
|
3
|
+
- New option :fast to increase speed when extracting information from JPEG
|
4
|
+
images which are piped across a slow network connection.
|
5
|
+
- Refactoring: Use Open3 for all command-line calls.
|
6
|
+
|
1
7
|
2.5.1
|
2
8
|
- Add gemspec.
|
3
9
|
|
data/README.rdoc
CHANGED
@@ -128,7 +128,7 @@ feel free to contribute!
|
|
128
128
|
Jan Friedrich <janfri26@gmail.com>
|
129
129
|
|
130
130
|
== Copyright / License
|
131
|
-
Copyright (c) 2007-
|
131
|
+
Copyright (c) 2007-2016 by Jan Friedrich
|
132
132
|
|
133
133
|
Licensed under terms of the GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1,
|
134
134
|
February 1999 (see file COPYING for more details)
|
data/lib/mini_exiftool.rb
CHANGED
@@ -8,13 +8,14 @@
|
|
8
8
|
# Read and write access is done in a clean OO manner.
|
9
9
|
#
|
10
10
|
# Author: Jan Friedrich
|
11
|
-
# Copyright (c) 2007-
|
11
|
+
# Copyright (c) 2007-2016 by Jan Friedrich
|
12
12
|
# Licensed under the GNU LESSER GENERAL PUBLIC LICENSE,
|
13
13
|
# Version 2.1, February 1999
|
14
14
|
#
|
15
15
|
|
16
16
|
require 'fileutils'
|
17
17
|
require 'json'
|
18
|
+
require 'open3'
|
18
19
|
require 'pstore'
|
19
20
|
require 'rational'
|
20
21
|
require 'rbconfig'
|
@@ -25,13 +26,13 @@ require 'time'
|
|
25
26
|
# Simple OO access to the Exiftool command-line application.
|
26
27
|
class MiniExiftool
|
27
28
|
|
28
|
-
VERSION = '2.
|
29
|
+
VERSION = '2.6.0'
|
29
30
|
|
30
31
|
# Name of the Exiftool command-line application
|
31
32
|
@@cmd = 'exiftool'
|
32
33
|
|
33
34
|
# Hash of the standard options used when call MiniExiftool.new
|
34
|
-
@@opts = { :numerical => false, :composite => true, :ignore_minor_errors => false,
|
35
|
+
@@opts = { :numerical => false, :composite => true, :fast => false, :ignore_minor_errors => false,
|
35
36
|
:replace_invalid_chars => false, :timestamps => Time }
|
36
37
|
|
37
38
|
# Encoding of the filesystem (filenames in command line)
|
@@ -48,7 +49,7 @@ class MiniExiftool
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
attr_reader :filename, :errors
|
52
|
+
attr_reader :filename, :errors, :io
|
52
53
|
|
53
54
|
opts_accessor :numerical, :composite, :ignore_minor_errors,
|
54
55
|
:replace_invalid_chars, :timestamps
|
@@ -72,6 +73,8 @@ class MiniExiftool
|
|
72
73
|
# * <code>:coord_format</code> set format for GPS coordinates (See
|
73
74
|
# -c-option of the exiftool command-line application, default is +nil+
|
74
75
|
# that means exiftool standard)
|
76
|
+
# * <code>:fast</code> useful when reading JPEGs over a slow network connection
|
77
|
+
# (See -fast-option of the exiftool command-line application, default is +false+)
|
75
78
|
# * <code>:replace_invalid_chars</code> replace string for invalid
|
76
79
|
# UTF-8 characters or +false+ if no replacing should be done,
|
77
80
|
# default is +false+
|
@@ -89,16 +92,18 @@ class MiniExiftool
|
|
89
92
|
# <code>:vorbis_encoding</code> to set this specific encoding (see
|
90
93
|
# -charset option of the exiftool command-line application, default is
|
91
94
|
# +nil+: no encoding specified)
|
92
|
-
def initialize
|
95
|
+
def initialize filename_or_io=nil, opts={}
|
93
96
|
@opts = @@opts.merge opts
|
94
97
|
if @opts[:convert_encoding]
|
95
98
|
warn 'Option :convert_encoding is not longer supported!'
|
96
99
|
warn 'Please use the String#encod* methods.'
|
97
100
|
end
|
101
|
+
@filename = nil
|
102
|
+
@io = nil
|
98
103
|
@values = TagHash.new
|
99
104
|
@changed_values = TagHash.new
|
100
105
|
@errors = TagHash.new
|
101
|
-
load
|
106
|
+
load filename_or_io unless filename_or_io.nil?
|
102
107
|
end
|
103
108
|
|
104
109
|
def initialize_from_hash hash # :nodoc:
|
@@ -114,22 +119,30 @@ class MiniExiftool
|
|
114
119
|
self
|
115
120
|
end
|
116
121
|
|
117
|
-
# Load the tags of filename.
|
118
|
-
def load
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
122
|
+
# Load the tags of filename or io.
|
123
|
+
def load filename_or_io
|
124
|
+
case filename_or_io
|
125
|
+
when String
|
126
|
+
unless filename_or_io && File.exist?(filename_or_io)
|
127
|
+
raise MiniExiftool::Error.new("File '#{filename_or_io}' does not exist.")
|
128
|
+
end
|
129
|
+
if File.directory?(filename_or_io)
|
130
|
+
raise MiniExiftool::Error.new("'#{filename_or_io}' is a directory.")
|
131
|
+
end
|
132
|
+
@filename = filename_or_io
|
133
|
+
when IO
|
134
|
+
@io = filename_or_io
|
135
|
+
@filename = '-'
|
136
|
+
else
|
137
|
+
raise MiniExiftool::Error.new("Could not open filename_or_io.")
|
125
138
|
end
|
126
|
-
@filename = filename
|
127
139
|
@values.clear
|
128
140
|
@changed_values.clear
|
129
141
|
params = '-j '
|
130
142
|
params << (@opts[:numerical] ? '-n ' : '')
|
131
143
|
params << (@opts[:composite] ? '' : '-e ')
|
132
144
|
params << (@opts[:coord_format] ? "-c \"#{@opts[:coord_format]}\"" : '')
|
145
|
+
params << (@opts[:fast] ? '-fast ' : '')
|
133
146
|
params << generate_encoding_params
|
134
147
|
if run(cmd_gen(params, @filename))
|
135
148
|
parse_output
|
@@ -188,7 +201,9 @@ class MiniExiftool
|
|
188
201
|
|
189
202
|
# Save the changes to the file.
|
190
203
|
def save
|
191
|
-
|
204
|
+
if @io
|
205
|
+
raise MiniExiftool::Error.new('No writing support when using an IO.')
|
206
|
+
end
|
192
207
|
return false if @changed_values.empty?
|
193
208
|
@errors.clear
|
194
209
|
temp_file = Tempfile.new('mini_exiftool')
|
@@ -324,11 +339,11 @@ class MiniExiftool
|
|
324
339
|
|
325
340
|
# Returns the version of the Exiftool command-line application.
|
326
341
|
def self.exiftool_version
|
327
|
-
|
328
|
-
|
329
|
-
raise MiniExiftool::Error.new("Command '#{MiniExiftool.command}' not found")
|
342
|
+
Open3.popen3 "#{MiniExiftool.command} -ver" do |_inp, out, _err, _thr|
|
343
|
+
out.read.chomp!
|
330
344
|
end
|
331
|
-
|
345
|
+
rescue SystemCallError
|
346
|
+
raise MiniExiftool::Error.new("Command '#{MiniExiftool.command}' not found")
|
332
347
|
end
|
333
348
|
|
334
349
|
def self.unify tag
|
@@ -358,14 +373,6 @@ class MiniExiftool
|
|
358
373
|
private
|
359
374
|
############################################################################
|
360
375
|
|
361
|
-
@@setup_done = false
|
362
|
-
def self.setup
|
363
|
-
return if @@setup_done
|
364
|
-
@@error_file = Tempfile.new 'errors'
|
365
|
-
@@error_file.close
|
366
|
-
@@setup_done = true
|
367
|
-
end
|
368
|
-
|
369
376
|
def cmd_gen arg_str='', filename
|
370
377
|
[@@cmd, arg_str.encode('UTF-8'), escape(filename.encode(@@fs_enc))].map {|s| s.force_encoding('UTF-8')}.join(' ')
|
371
378
|
end
|
@@ -374,16 +381,22 @@ class MiniExiftool
|
|
374
381
|
if $DEBUG
|
375
382
|
$stderr.puts cmd
|
376
383
|
end
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
384
|
+
status = Open3.popen3(cmd) do |inp, out, err, thr|
|
385
|
+
if @io
|
386
|
+
begin
|
387
|
+
data = @io.read
|
388
|
+
rescue Exception
|
389
|
+
raise MiniExiftool::Error.new("IO is not readable.")
|
390
|
+
end
|
391
|
+
inp.write data
|
392
|
+
@io.close
|
393
|
+
inp.close
|
394
|
+
end
|
395
|
+
@output = out.read
|
396
|
+
@error_text = err.read
|
397
|
+
thr.value.exitstatus
|
386
398
|
end
|
399
|
+
status == 0
|
387
400
|
end
|
388
401
|
|
389
402
|
def convert_before_save val
|
data/test/test_class_methods.rb
CHANGED
@@ -63,13 +63,13 @@ class TestClassMethods < TestCase
|
|
63
63
|
def test_all_tags
|
64
64
|
all_tags = MiniExiftool.all_tags
|
65
65
|
assert all_tags.include?('ISO')
|
66
|
-
assert all_tags.include?('
|
66
|
+
assert all_tags.include?('ExifToolVersion')
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_writable_tags
|
70
70
|
w_tags = MiniExiftool.writable_tags
|
71
71
|
assert w_tags.include?('ISO')
|
72
|
-
|
72
|
+
assert ! w_tags.include?('ExifToolVersion')
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_exiftool_version
|
data/test/test_io.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# -- encoding: utf-8 --
|
2
|
+
require 'helpers_for_test'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
class TestIo < TestCase
|
6
|
+
|
7
|
+
def test_simple_case
|
8
|
+
io = open_real_io
|
9
|
+
mini_exiftool = MiniExiftool.new(io)
|
10
|
+
assert io.closed?, 'IO should be closed after reading data.'
|
11
|
+
assert_equal 400, mini_exiftool.iso
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_non_readable_io
|
15
|
+
assert_raises MiniExiftool::Error do
|
16
|
+
begin
|
17
|
+
MiniExiftool.new($stdout)
|
18
|
+
rescue MiniExiftool::Error => e
|
19
|
+
assert_equal 'IO is not readable.', e.message
|
20
|
+
raise e
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_no_writing_when_using_io
|
26
|
+
io = open_real_io
|
27
|
+
m = MiniExiftool.new(io)
|
28
|
+
m.iso = 100
|
29
|
+
assert_raises MiniExiftool::Error do
|
30
|
+
begin
|
31
|
+
m.save
|
32
|
+
rescue MiniExiftool::Error => e
|
33
|
+
assert_equal 'No writing support when using an IO.', e.message
|
34
|
+
raise e
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_fast_option
|
40
|
+
$DEBUG = true
|
41
|
+
s = StringIO.new
|
42
|
+
$stderr = s
|
43
|
+
MiniExiftool.new open_real_io
|
44
|
+
s.rewind
|
45
|
+
assert_equal 'exiftool -j "-"', s.read.chomp
|
46
|
+
s = StringIO.new
|
47
|
+
$stderr = s
|
48
|
+
MiniExiftool.new open_real_io, :fast => true
|
49
|
+
s.rewind
|
50
|
+
assert_equal 'exiftool -j -fast "-"', s.read.chomp
|
51
|
+
ensure
|
52
|
+
$DEBUG = false
|
53
|
+
$stderr = STDERR
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
def open_real_io
|
59
|
+
File.open(File.join(File.dirname(__FILE__), 'data', 'test.jpg'), 'r')
|
60
|
+
end
|
61
|
+
|
62
|
+
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.6.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:
|
11
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rim
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- test/test_from_hash.rb
|
58
58
|
- test/test_invalid_byte_sequence_in_utf8.rb
|
59
59
|
- test/test_invalid_rational.rb
|
60
|
+
- test/test_io.rb
|
60
61
|
- test/test_pstore.rb
|
61
62
|
- test/test_read.rb
|
62
63
|
- test/test_read_coordinates.rb
|
@@ -92,9 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
95
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.6.2
|
96
97
|
signing_key:
|
97
98
|
specification_version: 4
|
98
99
|
summary: This library is wrapper for the Exiftool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool).
|
99
100
|
test_files: []
|
100
|
-
has_rdoc:
|