Skip to content
This repository
Browse code

Support -m option of the exiftool command-line application.

  • Loading branch information...
commit f218515ed5d9139aa5b5ca05f83c9e2ec02bd1a0 1 parent 70eb911
janfri authored May 31, 2012
10  lib/mini_exiftool.rb
@@ -27,10 +27,10 @@ class MiniExiftool
27 27
   @@cmd = 'exiftool'
28 28
 
29 29
   # Hash of the standard options used when call MiniExiftool.new
30  
-  @@opts = { :numerical => false, :composite => true, :convert_encoding => false, :timestamps => Time }
  30
+  @@opts = { :numerical => false, :composite => true, :convert_encoding => false, :ignore_minor_errors => false, :timestamps => Time }
31 31
 
32 32
   attr_reader :filename
33  
-  attr_accessor :numerical, :composite, :convert_encoding, :errors, :timestamps
  33
+  attr_accessor :numerical, :composite, :convert_encoding, :ignore_minor_errors, :errors, :timestamps
34 34
 
35 35
   VERSION = '1.4.4'
36 36
 
@@ -39,7 +39,9 @@ class MiniExiftool
39 39
   # * <code>:composite</code> for including composite tags while loading,
40 40
   #   default is +true+
41 41
   # * <code>:convert_encoding</code> convert encoding (See -L-option of
42  
-  #   the exiftool command-line application, default is +false+
  42
+  #   the exiftool command-line application, default is +false+)
  43
+  # * <code>:ignore_minor_errors</code> ignore minor errors (See -m-option
  44
+  # of the exiftool command-line application, default is +false+)
43 45
   # * <code>:timestamps</code> generating DateTime objects instead of
44 46
   #   Time objects if set to <code>DateTime</code>, default is +Time+
45 47
   #
@@ -51,6 +53,7 @@ def initialize filename=nil, opts={}
51 53
     @numerical = opts[:numerical]
52 54
     @composite = opts[:composite]
53 55
     @convert_encoding = opts[:convert_encoding]
  56
+    @ignore_minor_errors = opts[:ignore_minor_errors]
54 57
     @timestamps = opts[:timestamps]
55 58
     @values = TagHash.new
56 59
     @tag_names = TagHash.new
@@ -159,6 +162,7 @@ def save
159 162
       opt_params = ''
160 163
       opt_params << (arr_val.detect {|x| x.kind_of?(Numeric)} ? '-n ' : '')
161 164
       opt_params << (@convert_encoding ? '-L ' : '')
  165
+      opt_params << (@ignore_minor_errors ? '-m' : '')
162 166
       cmd = %Q(#@@cmd -q -P -overwrite_original #{opt_params} #{tag_params} #{temp_filename})
163 167
       if convert_encoding && cmd.respond_to?(:encode)
164 168
         cmd.encode('ISO-8859-1')
BIN  test/data/Bad_PreviewIFD.jpg
29  test/test_bad_preview_ifd.rb
... ...
@@ -0,0 +1,29 @@
  1
+# -- encoding: utf-8 --
  2
+require 'helpers_for_test'
  3
+
  4
+class TestBadPreviewIFD < TestCase
  5
+
  6
+  include TempfileTest
  7
+
  8
+  def setup
  9
+    super
  10
+    @org_filename = @data_dir + '/Bad_PreviewIFD.jpg'
  11
+    FileUtils.cp @org_filename, @temp_filename
  12
+    @bad_preview_ifd = MiniExiftool.new @temp_filename
  13
+  end
  14
+
  15
+  # Feature request rubyforge [#29587]
  16
+  # Thanks to Michael Grove for reporting
  17
+  def test_m_option
  18
+    title = 'anything'
  19
+    @bad_preview_ifd.title = title
  20
+    assert_equal false, @bad_preview_ifd.save, '-m option seems to be not neccessary'
  21
+    @bad_preview_ifd.reload
  22
+    @bad_preview_ifd.title = title
  23
+    @bad_preview_ifd.ignore_minor_errors = true
  24
+    assert_equal true, @bad_preview_ifd.save, 'Error while saving'
  25
+    @bad_preview_ifd.reload
  26
+    assert_equal title, @bad_preview_ifd.title
  27
+  end
  28
+
  29
+end
2  test/test_write.rb
@@ -90,7 +90,7 @@ def test_time_conversion
90 90
 
91 91
   def test_float_conversion
92 92
     assert_kind_of Float, @mini_exiftool_num['BrightnessValue']
93  
-    new_time = @mini_exiftool_num['BrightnessValue'] + 1 
  93
+    new_time = @mini_exiftool_num['BrightnessValue'] + 1
94 94
     @mini_exiftool_num['BrightnessValue'] = new_time
95 95
     assert_equal new_time, @mini_exiftool_num['BrightnessValue']
96 96
     assert_equal true, @mini_exiftool_num.changed_tags.include?('BrightnessValue')

0 notes on commit f218515

Please sign in to comment.
Something went wrong with that request. Please try again.