mini_exiftool 2.6.0 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdeb9b98998342750a3fcbae84d333e667292f58
4
- data.tar.gz: c71bdba7f4db16bc4ef8b939d97fbce7bc595117
3
+ metadata.gz: 8a1a8c6d521b719133ac256c568185efbb46b261
4
+ data.tar.gz: 538c8f074435883a599b39a522e4e24d15c8a7d6
5
5
  SHA512:
6
- metadata.gz: a9d3353b6a770152ae4a914699bfa633ef5d2943ce610b2c72c5fb316a827aa2ac46cb5b93ae66d14fe7ee6d14aad2cee750a94ca540ab83dc9f5227f152a78f
7
- data.tar.gz: ee36b1a1febb01b4c83904a55eb5c6539efe24a7749379d6a25107f5445f61d28fbb96b5b65eede550acd8f03ecaf4b379f57b02641bcdcf783d45c33cdabaf6
6
+ metadata.gz: cd2cbfa6f6b5b0f11d30dec2c7a0b4cbd6566120d7a86065d62340607ba746bd0ea0ec7d07d45f1a88c77d96357cca9750b1ba49be72bc135a9f51d2520bda5a
7
+ data.tar.gz: 1ae605775fb808b8e26b486c6addd8c99c0b5d859b0c159fadbd888578b5aa7f09eeafdff2c9dd958e2174e86b3537af4c375f420178bc948e91b2ee3fe5fd79
data/Changelog CHANGED
@@ -1,7 +1,16 @@
1
+ 2.7.0
2
+ - Use duck typing to determine if filename_or_io is a filename or an IO
3
+ instance.
4
+ - New option :fast2.
5
+ - Add example show_speedup_with_fast_option.
6
+ - Update docs.
7
+
1
8
  2.6.0
2
9
  - Support reading from IO instances.
10
+ Thanks to Gaelan <gbs@canishe.com> for the idea.
3
11
  - New option :fast to increase speed when extracting information from JPEG
4
12
  images which are piped across a slow network connection.
13
+ Thanks to Felipe Cypriano <felipe@cypriano.me> for the idea.
5
14
  - Refactoring: Use Open3 for all command-line calls.
6
15
 
7
16
  2.5.1
data/README.rdoc CHANGED
@@ -48,10 +48,14 @@ after require 'mini_exiftool'.
48
48
 
49
49
  In general MiniExiftool is very intuitive to use as the following examples show:
50
50
 
51
- # Reading meta data
51
+ # Reading meta data from a file
52
52
  photo = MiniExiftool.new 'photo.jpg'
53
53
  puts photo.title
54
54
 
55
+ # Alternative reading meta data from an IO instance
56
+ photo = MiniExiftool.new io
57
+ puts photo.title
58
+
55
59
  # Writing meta data
56
60
  photo = MiniExiftool.new 'photo.jpg'
57
61
  photo.title = 'This is the new title'
data/Tutorial.rdoc CHANGED
@@ -17,7 +17,6 @@
17
17
  photo = MiniExiftool.new 'photo.jpg'
18
18
  puts photo['DateTimeOriginal']
19
19
 
20
-
21
20
  === Smart Tag Names
22
21
  In the example above we use <code>photo['DateTimeOriginal']</code> to
23
22
  get the value for the time the photo was taken. But tag names are not
@@ -41,7 +40,6 @@ using dynamic method access. You can write:
41
40
  or also
42
41
  photo.date_time_original
43
42
 
44
-
45
43
  === Value Types
46
44
 
47
45
  Following types of values are at the moment supported:
@@ -52,7 +50,7 @@ Following types of values are at the moment supported:
52
50
  * Time (e. g. DateTimeOriginal => 2005:09:13 20:08:50)
53
51
 
54
52
  Be aware, if there is only one value in a tag which can hold multiple
55
- values the result is'nt an array! But you can get one with the Array
53
+ values the result isn't an array! But you can get one with the Array
56
54
  method:
57
55
  # only _one_ keyword
58
56
  p1 = MiniExiftool.new 'p1.jpg'
@@ -103,18 +101,43 @@ Further options are
103
101
  * <code>:coord_format</code> set format for GPS coordinates (See
104
102
  -c-option of the exiftool command-line application, default is +nil+
105
103
  that means exiftool standard)
104
+ * <code>:fast</code> useful when reading JPEGs over a slow network connection
105
+ (See -fast-option of the exiftool command-line application, default is +false+)
106
+ * <code>:fast2</code> useful when reading JPEGs over a slow network connection
107
+ (See -fast2-option of the exiftool command-line application, default is +false+)
106
108
  * <code>:replace_invalid_chars</code> replace string for invalid
107
109
  UTF-8 characters or +false+ if no replacing should be done,
108
110
  default is +false+
111
+ * <code>:exif_encoding</code>, <code>:iptc_encoding</code>,
112
+ <code>:xmp_encoding</code>, <code>:png_encoding</code>,
113
+ <code>:id3_encoding</code>, <code>:pdf_encoding</code>,
114
+ <code>:photoshop_encoding</code>, <code>:quicktime_encoding</code>,
115
+ <code>:aiff_encoding</code>, <code>:mie_encoding</code>,
116
+ <code>:vorbis_encoding</code> to set this specific encoding (see
117
+ -charset option of the exiftool command-line application, default is
118
+ +nil+: no encoding specified)
109
119
 
110
- === Further Example
120
+ === Using an IO instance
111
121
 
112
- For understanding reading access to meta data also have a look at the
113
- example file <code>print_portraits.rb</code> in the +examples+
114
- directory.
122
+ require 'mini_exiftool'
123
+ require 'open3'
115
124
 
116
- == Lesson 2: Writing Meta Data
125
+ # Using external curl command
126
+ input, output = Open3.popen2("curl -s http://www.url.of.a.photo")
127
+ input.close
128
+ photo = MiniExiftool.new output
129
+ puts photo['ISO']
117
130
 
131
+ The kind of the parameter +filename_or_io+ is determined via duck typing:
132
+ if the argument responds to +to_str+ it is interpreted as filename, if it
133
+ responds to +read+ it is interpreted es IO instance.
134
+ Attention: If you use an IO instance then writing of values is not supported!
135
+
136
+ Look at the show_speedup_with_fast_option example in the MiniExiftool examples
137
+ directory for more details about using an IO instance.
138
+
139
+
140
+ == Lesson 2: Writing Meta Data
118
141
 
119
142
  === Also A Very Simple Example
120
143
 
@@ -127,12 +150,12 @@ directory.
127
150
 
128
151
  === Save Is Atomar
129
152
 
130
- If you have changed serval values and call the +save+-method either
153
+ If you have changed several values and call the +save+-method either
131
154
  all changes will be written to the file or nothing. The return value
132
155
  of the +save+-method is +true+ if all values are written to the file
133
156
  otherwise save returns +false+. In the last case you can use the
134
157
  +errors+-method which returns a hash of the tags which values couldn't
135
- be writed with an error message for each of them.
158
+ be written with an error message for each of them.
136
159
 
137
160
 
138
161
  === Interesting Methods
@@ -144,10 +167,6 @@ specific tag or in general all changes.
144
167
 
145
168
  You should also look at the rdoc information of MiniExiftool.
146
169
 
147
- === Further Examples
148
-
149
- Have a look in the examples folder of MiniExiftool.
150
-
151
170
 
152
171
  == Lesson 3: Copying Meta Data
153
172
 
@@ -167,6 +186,9 @@ Have a look in the examples folder of MiniExiftool.
167
186
  # Further more than one tag can be copied at once
168
187
  photo.copy_tags_from('another_photo', %w[author copyright])
169
188
 
170
- === Further Example
171
-
172
189
  Look at the file copy_icc_profile.rb in the examples folder of MiniExiftool.
190
+
191
+
192
+ == Further Examples
193
+
194
+ Have a look in the examples folder of MiniExiftool.
data/lib/mini_exiftool.rb CHANGED
@@ -26,14 +26,15 @@ require 'time'
26
26
  # Simple OO access to the Exiftool command-line application.
27
27
  class MiniExiftool
28
28
 
29
- VERSION = '2.6.0'
29
+ VERSION = '2.7.0'
30
30
 
31
31
  # Name of the Exiftool command-line application
32
32
  @@cmd = 'exiftool'
33
33
 
34
34
  # Hash of the standard options used when call MiniExiftool.new
35
- @@opts = { :numerical => false, :composite => true, :fast => false, :ignore_minor_errors => false,
36
- :replace_invalid_chars => false, :timestamps => Time }
35
+ @@opts = { :numerical => false, :composite => true, :fast => false, :fast2 => false,
36
+ :ignore_minor_errors => false, :replace_invalid_chars => false,
37
+ :timestamps => Time }
37
38
 
38
39
  # Encoding of the filesystem (filenames in command line)
39
40
  @@fs_enc = Encoding.find('filesystem')
@@ -64,6 +65,12 @@ class MiniExiftool
64
65
  opts_accessor encoding_opt(enc_type)
65
66
  end
66
67
 
68
+ # +filename_or_io+ The kind of the parameter is determined via duck typing:
69
+ # if the argument responds to +to_str+ it is interpreted as filename, if it
70
+ # responds to +read+ it is interpreted es IO instance.
71
+ #
72
+ # <b>ATTENTION:</b> If using an IO instance writing of meta data is not supported!
73
+ #
67
74
  # +opts+ support at the moment
68
75
  # * <code>:numerical</code> for numerical values, default is +false+
69
76
  # * <code>:composite</code> for including composite tags while loading,
@@ -75,6 +82,8 @@ class MiniExiftool
75
82
  # that means exiftool standard)
76
83
  # * <code>:fast</code> useful when reading JPEGs over a slow network connection
77
84
  # (See -fast-option of the exiftool command-line application, default is +false+)
85
+ # * <code>:fast2</code> useful when reading JPEGs over a slow network connection
86
+ # (See -fast2-option of the exiftool command-line application, default is +false+)
78
87
  # * <code>:replace_invalid_chars</code> replace string for invalid
79
88
  # UTF-8 characters or +false+ if no replacing should be done,
80
89
  # default is +false+
@@ -121,16 +130,15 @@ class MiniExiftool
121
130
 
122
131
  # Load the tags of filename or io.
123
132
  def load filename_or_io
124
- case filename_or_io
125
- when String
133
+ if filename_or_io.respond_to? :to_str # String-like
126
134
  unless filename_or_io && File.exist?(filename_or_io)
127
135
  raise MiniExiftool::Error.new("File '#{filename_or_io}' does not exist.")
128
136
  end
129
137
  if File.directory?(filename_or_io)
130
138
  raise MiniExiftool::Error.new("'#{filename_or_io}' is a directory.")
131
139
  end
132
- @filename = filename_or_io
133
- when IO
140
+ @filename = filename_or_io.to_str
141
+ elsif filename_or_io.respond_to? :read # IO-like
134
142
  @io = filename_or_io
135
143
  @filename = '-'
136
144
  else
@@ -143,6 +151,7 @@ class MiniExiftool
143
151
  params << (@opts[:composite] ? '' : '-e ')
144
152
  params << (@opts[:coord_format] ? "-c \"#{@opts[:coord_format]}\"" : '')
145
153
  params << (@opts[:fast] ? '-fast ' : '')
154
+ params << (@opts[:fast2] ? '-fast2 ' : '')
146
155
  params << generate_encoding_params
147
156
  if run(cmd_gen(params, @filename))
148
157
  parse_output
@@ -384,11 +393,12 @@ class MiniExiftool
384
393
  status = Open3.popen3(cmd) do |inp, out, err, thr|
385
394
  if @io
386
395
  begin
387
- data = @io.read
388
- rescue Exception
396
+ IO.copy_stream @io, inp
397
+ rescue Errno::EPIPE
398
+ # Output closed, no problem
399
+ rescue ::IOError => e
389
400
  raise MiniExiftool::Error.new("IO is not readable.")
390
401
  end
391
- inp.write data
392
402
  @io.close
393
403
  inp.close
394
404
  end
data/test/test_io.rb CHANGED
@@ -36,7 +36,7 @@ class TestIo < TestCase
36
36
  end
37
37
  end
38
38
 
39
- def test_fast_option
39
+ def test_fast_options
40
40
  $DEBUG = true
41
41
  s = StringIO.new
42
42
  $stderr = s
@@ -48,6 +48,11 @@ class TestIo < TestCase
48
48
  MiniExiftool.new open_real_io, :fast => true
49
49
  s.rewind
50
50
  assert_equal 'exiftool -j -fast "-"', s.read.chomp
51
+ s = StringIO.new
52
+ $stderr = s
53
+ MiniExiftool.new open_real_io, :fast2 => true
54
+ s.rewind
55
+ assert_equal 'exiftool -j -fast2 "-"', s.read.chomp
51
56
  ensure
52
57
  $DEBUG = false
53
58
  $stderr = STDERR
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.6.0
4
+ version: 2.7.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: 2016-04-04 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rim