mini_exiftool 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1503e85ca2e2cb25cee0dc50a680d6c1641c8000
4
- data.tar.gz: 01bc4385657a026eb0fe93a5a8969c1ceb14665e
3
+ metadata.gz: 945fdce2c08a3ae7c09603eb14156ccc853ad8c8
4
+ data.tar.gz: 29a87004f5057d4b647a17a0818c02d98700b92f
5
5
  SHA512:
6
- metadata.gz: 40d2c11befb48e3e024b45d770d572ead5dbc088bc8497f10ff9fad5a930bffdbea19ded6da5248f376d7a5442758ed4ff5739cf78dedbfee3161eac98ba04e6
7
- data.tar.gz: d4f821e8f2c389e7b0f32f54eea60db3b9d72f1b1bddfbbaba421287550c03181f325348f906e4becd432f25592f0a8f615789545a80b30c799787efaad0dbf2
6
+ metadata.gz: 468bd686cc92722e3b516e046681a8ae1854a68ea9089beaa4cbdd51aa2eddcb120e8f3776d3ab66db6f0ca1105f6a36aabc5dd83f13594e3d453b1057e5cf20
7
+ data.tar.gz: 9400b0fdfc174246734c2071e4e76a9f0253215c70c4d89eb317327fe1f9f65af34e8e97f54c8d8518ad3c4f7927888024590aa54837f7184026d1a9289f008a
data/Changelog CHANGED
@@ -1,3 +1,12 @@
1
+ 2.4.0
2
+ - New method MiniExiftool#copy_tags_from.
3
+ Many thanks to cgat for the hint and implementing a first
4
+ approach.
5
+ - Saver handling of encoding problems.
6
+ - Approving documentation.
7
+ - Using regtest for integration testing.
8
+ - Some internal refactorings.
9
+
1
10
  2.3.0
2
11
  - New options :exif_encoding, :iptc_encodings,
3
12
  :xmp_encodings etc. to change specific encodings
data/README.rdoc CHANGED
@@ -23,21 +23,36 @@ http://rubygems.org/gems/mini_exiftool_vendored .
23
23
  First you need Exiftool (see under Requirements above). Then you can simply
24
24
  install the gem with
25
25
  gem install mini_exiftool
26
- respectively (on *nix sytems)
27
- sudo gem install mini_exiftool
28
26
 
29
- If you need support of older versione (see Requirements above)
27
+ If you need to support older versions of Ruby or exiftool (see Requirements above)
30
28
  gem install --version "< 2.0.0" mini_exiftool
31
29
 
32
- Alternative you can download the tarball or zip file and run
33
- ruby setup.rb config
34
- ruby setup.rb setup
35
- sudo ruby setup.rb install
30
+ == Usage
31
+
32
+ In general MiniExiftool is very intuitive to use as the following examples show:
33
+
34
+ # Reading meta data
35
+ photo = MiniExiftool.new 'photo.jpg'
36
+ puts photo.title
37
+
38
+ # Writing meta data
39
+ photo = MiniExiftool.new 'photo.jpg'
40
+ photo.title = 'This is the new title'
41
+ photo.save
42
+
43
+ # Copying meta data
44
+ photo = MiniExiftool.new('photo.jpg')
45
+ photo.copy_tags_from('another_photo.jpg', :author)
46
+
47
+
48
+ For further information about using MiniExiftool read the Tutorial.rdoc
49
+ in the project root folder and have a look at the examples in directory
50
+ examples.
36
51
 
37
52
  == Contribution
38
53
 
39
- The code is also hostet in a git repository on Gitorious at
40
- http://gitorious.org/projects/mini_exiftool
54
+ The code is hostet in a git repository on Gitorious at
55
+ http://gitorious.org/mini_exiftool
41
56
  and github at
42
57
  https://github.com/janfri/mini_exiftool
43
58
  feel free to contribute!
@@ -50,9 +65,3 @@ Copyright (c) 2007-2013 by Jan Friedrich
50
65
 
51
66
  Licensed under terms of the GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1,
52
67
  February 1999 (see file COPYING for more details)
53
-
54
- == Usage
55
-
56
- For further information about using MiniExiftool read the Tutorial.rdoc
57
- in the project root folder and have a look at the examples in directory
58
- examples.
data/Rakefile CHANGED
@@ -2,6 +2,7 @@ require 'rim'
2
2
  require 'rim/check_version'
3
3
  require 'rim/gem'
4
4
  require 'rim/test'
5
+ require 'regtest/task'
5
6
 
6
7
  $:.unshift 'lib'
7
8
  require 'mini_exiftool'
data/Tutorial.rdoc CHANGED
@@ -12,7 +12,6 @@
12
12
 
13
13
  === A Simple Example
14
14
 
15
- require 'rubygems'
16
15
  require 'mini_exiftool'
17
16
 
18
17
  photo = MiniExiftool.new 'photo.jpg'
@@ -119,7 +118,6 @@ directory.
119
118
 
120
119
  === Also A Very Simple Example
121
120
 
122
- require 'rubygems'
123
121
  require 'mini_exiftool'
124
122
 
125
123
  photo = MiniExiftool.new 'photo.jpg'
@@ -149,3 +147,26 @@ You should also look at the rdoc information of MiniExiftool.
149
147
  === Further Examples
150
148
 
151
149
  Have a look in the examples folder of MiniExiftool.
150
+
151
+
152
+ == Lesson 3: Copying Meta Data
153
+
154
+ === Examples
155
+
156
+ require 'mini_exiftool'
157
+
158
+ photo = MiniExiftool.new('photo.jpg')
159
+
160
+ # Update the author tag of photo.jpg with the value of the author tag
161
+ # of another_photo.jpg
162
+ photo.copy_tags_from('another_photo.jpg', 'Author')
163
+
164
+ # It's also possible to use symbols and case is also not meaningful
165
+ photo.copy_tags_from('another_photo.jpg', :author)
166
+
167
+ # Further more than one tag can be copied at once
168
+ photo.copy_tags_from('another_photo', %w[author copyright])
169
+
170
+ === Further Example
171
+
172
+ Look at the file copy_icc_profile.rb in the examples folder of MiniExiftool.
data/lib/mini_exiftool.rb CHANGED
@@ -8,7 +8,7 @@
8
8
  # Read and write access is done in a clean OO manner.
9
9
  #
10
10
  # Author: Jan Friedrich
11
- # Copyright (c) 2007-2013 by Jan Friedrich
11
+ # Copyright (c) 2007-2014 by Jan Friedrich
12
12
  # Licensed under the GNU LESSER GENERAL PUBLIC LICENSE,
13
13
  # Version 2.1, February 1999
14
14
  #
@@ -25,7 +25,7 @@ require 'time'
25
25
  # Simple OO access to the Exiftool command-line application.
26
26
  class MiniExiftool
27
27
 
28
- VERSION = '2.3.0'
28
+ VERSION = '2.4.0'
29
29
 
30
30
  # Name of the Exiftool command-line application
31
31
  @@cmd = 'exiftool'
@@ -102,10 +102,8 @@ class MiniExiftool
102
102
  end
103
103
 
104
104
  def initialize_from_hash hash # :nodoc:
105
- hash.each_pair do |tag,value|
106
- set_value tag, convert_after_load(tag, value)
107
- end
108
- set_attributes_by_heuristic
105
+ set_values hash
106
+ set_opts_by_heuristic
109
107
  self
110
108
  end
111
109
 
@@ -236,6 +234,20 @@ class MiniExiftool
236
234
  end
237
235
  end
238
236
 
237
+ def copy_tags_from(source_filename, tags)
238
+ @errors.clear
239
+ unless File.exist?(source_filename)
240
+ raise MiniExiftool::Error.new("Source file #{source_filename} does not exist!")
241
+ end
242
+ params = '-q -P -overwrite_original '
243
+ tags_params = Array(tags).map {|t| '-' << t.to_s}.join(' ')
244
+ cmd = [@@cmd, params, '-tagsFromFile', escape(source_filename).encode(@@fs_enc), tags_params.encode('UTF-8'), escape(filename).encode(@@fs_enc)].join(' ')
245
+ cmd.force_encoding('UTF-8')
246
+ result = run(cmd)
247
+ reload
248
+ result
249
+ end
250
+
239
251
  # Returns a hash of the original loaded values of the MiniExiftool
240
252
  # instance.
241
253
  def to_hash
@@ -254,8 +266,8 @@ class MiniExiftool
254
266
 
255
267
  # Create a MiniExiftool instance from a hash. Default value
256
268
  # conversions will be applied if neccesary.
257
- def self.from_hash hash
258
- instance = MiniExiftool.new
269
+ def self.from_hash hash, opts={}
270
+ instance = MiniExiftool.new nil, opts
259
271
  instance.initialize_from_hash hash
260
272
  instance
261
273
  end
@@ -270,8 +282,8 @@ class MiniExiftool
270
282
 
271
283
  # Create a MiniExiftool instance from YAML data created with
272
284
  # MiniExiftool#to_yaml
273
- def self.from_yaml yaml
274
- MiniExiftool.from_hash YAML.load(yaml)
285
+ def self.from_yaml yaml, opts={}
286
+ MiniExiftool.from_hash YAML.load(yaml), opts
275
287
  end
276
288
 
277
289
  # Returns the command name of the called Exiftool application.
@@ -379,22 +391,20 @@ class MiniExiftool
379
391
  end
380
392
 
381
393
  def parse_output
394
+ adapt_encoding
395
+ set_values JSON.parse(@output).first
396
+ end
397
+
398
+ def adapt_encoding
382
399
  @output.force_encoding('UTF-8')
383
400
  if @opts[:replace_invalid_chars] && !@output.valid_encoding?
384
401
  @output.encode!('UTF-16le', invalid: :replace, replace: @opts[:replace_invalid_chars]).encode!('UTF-8')
385
402
  end
386
- JSON.parse(@output)[0].each do |tag,value|
387
- value = convert_after_load(tag, value)
388
- set_value tag, value
389
- end
390
403
  end
391
404
 
392
405
  def convert_after_load tag, value
393
406
  return value unless value.kind_of?(String)
394
- if %w(sourcefile filename directory).include?(MiniExiftool.unify(tag))
395
- # ignore filesystem relevant tags to avoid encoding problems
396
- return nil
397
- end
407
+ return value unless value.valid_encoding?
398
408
  case value
399
409
  when /^\d{4}:\d\d:\d\d \d\d:\d\d:\d\d/
400
410
  s = value.sub(/^(\d+):(\d+):/, '\1-\2-')
@@ -423,14 +433,27 @@ class MiniExiftool
423
433
  value
424
434
  end
425
435
 
426
- def set_value tag, value
427
- @values[tag] = value
436
+ def set_values hash
437
+ hash.each_pair do |tag,val|
438
+ @values[tag] = convert_after_load(tag, val)
439
+ end
440
+ # Remove filename specific tags use attr_reader
441
+ # MiniExiftool#filename instead
442
+ # Cause: value of tag filename and attribute
443
+ # filename have different content, the latter
444
+ # holds the filename with full path (like the
445
+ # sourcefile tag) and the former the basename
446
+ # of the filename also there is no official
447
+ # "original tag name" for sourcefile
448
+ %w(directory filename sourcefile).each do |t|
449
+ @values.delete(t)
450
+ end
428
451
  end
429
452
 
430
- def set_attributes_by_heuristic
431
- self.composite = tags.include?('ImageSize') ? true : false
432
- self.numerical = self.file_size.kind_of?(Integer) ? true : false
433
- self.timestamps = self.FileModifyDate.kind_of?(DateTime) ? DateTime : Time
453
+ def set_opts_by_heuristic
454
+ @opts[:composite] = tags.include?('ImageSize')
455
+ @opts[:numerical] = self.file_size.kind_of?(Integer)
456
+ @opts[:timestamps] = self.FileModifyDate.kind_of?(DateTime) ? DateTime : Time
434
457
  end
435
458
 
436
459
  def self.pstore_get attribute
@@ -25,4 +25,9 @@ module TempfileTest
25
25
  def teardown
26
26
  @temp_file.close
27
27
  end
28
+
29
+ def assert_md5 md5, filename
30
+ assert_equal md5, Digest::MD5.hexdigest(File.read(filename))
31
+ end
32
+
28
33
  end
@@ -0,0 +1,55 @@
1
+ # -- encoding: utf-8 --
2
+ require 'helpers_for_test'
3
+
4
+ class TestCopyTagsFrom < TestCase
5
+
6
+ include TempfileTest
7
+
8
+ def setup
9
+ super
10
+ @canon_filename = @data_dir + '/Canon.jpg'
11
+ FileUtils.cp(@canon_filename, @temp_filename)
12
+ @mini_exiftool = MiniExiftool.new(@temp_filename)
13
+ @source_filename = @data_dir + '/test.jpg'
14
+ @canon_md5 = Digest::MD5.hexdigest(File.read(@canon_filename))
15
+ @source_md5 = Digest::MD5.hexdigest(File.read(@source_filename))
16
+ end
17
+
18
+ def test_single_tag
19
+ assert_nil @mini_exiftool.title
20
+ res = @mini_exiftool.copy_tags_from(@source_filename, :title)
21
+ assert res
22
+ assert_equal 'Abenddämmerung', @mini_exiftool.title
23
+ assert_md5 @source_md5, @source_filename
24
+ end
25
+
26
+ def test_more_than_one_tag
27
+ assert_nil @mini_exiftool.title
28
+ assert_nil @mini_exiftool.keywords
29
+ res = @mini_exiftool.copy_tags_from(@source_filename, %w[title keywords])
30
+ assert res
31
+ assert_equal 'Abenddämmerung', @mini_exiftool.title
32
+ assert_equal %w[Orange Rot], @mini_exiftool.keywords
33
+ assert_md5 @source_md5, @source_filename
34
+ end
35
+
36
+ def test_non_existing_sourcefile
37
+ assert_raises MiniExiftool::Error do
38
+ @mini_exiftool.copy_tags_from('non_existend_file', :title)
39
+ end
40
+ assert_md5 @source_md5, @source_filename
41
+ end
42
+
43
+ def test_non_existend_tag
44
+ @mini_exiftool.copy_tags_from(@source_filename, :non_existend_tag)
45
+ assert_md5 @canon_md5, @canon_filename
46
+ assert_md5 @source_md5, @source_filename
47
+ end
48
+
49
+ def test_non_writable_tag
50
+ @mini_exiftool.copy_tags_from(@source_filename, 'JFIF')
51
+ assert_md5 @canon_md5, @canon_filename
52
+ assert_md5 @source_md5, @source_filename
53
+ end
54
+
55
+ end
data/test/test_dumping.rb CHANGED
@@ -16,15 +16,16 @@ class TestDumping < TestCase
16
16
  assert_equal @mini_exiftool.tags.size, hash.size, 'Size of Hash is not correct.'
17
17
  assert_not_nil hash['ExifToolVersion'], 'Original name of exiftool tag is not preserved.'
18
18
  all_ok = true
19
- diffenent_tag = ''
19
+ different_tag = ''
20
+ v = ''
20
21
  hash.each do |k,v|
21
22
  unless @mini_exiftool[k] == v
22
23
  all_ok = false
23
- diffenent_tag = k
24
+ different_tag = k
24
25
  break
25
26
  end
26
27
  end
27
- assert all_ok, "Tag #{diffenent_tag}: expected: #{@mini_exiftool[diffenent_tag]}, actual: v"
28
+ assert all_ok, "Tag #{different_tag.inspect}: expected: #{@mini_exiftool[different_tag].inspect}, actual: #{v.inspect}"
28
29
  end
29
30
 
30
31
  def test_from_hash
@@ -33,15 +34,15 @@ class TestDumping < TestCase
33
34
  assert_equal MiniExiftool, mini_exiftool_new.class
34
35
  assert_equal @mini_exiftool.tags.size, mini_exiftool_new.tags.size
35
36
  all_ok = true
36
- diffenent_tag = ''
37
+ different_tag = ''
37
38
  @mini_exiftool.tags.each do |tag|
38
39
  unless @mini_exiftool[tag] == mini_exiftool_new[tag]
39
40
  all_ok = false
40
- diffenent_tag = tag
41
+ different_tag = tag
41
42
  break
42
43
  end
43
44
  end
44
- assert all_ok, "Tag #{diffenent_tag}: expected: #{@mini_exiftool[diffenent_tag]}, actual: #{mini_exiftool_new[diffenent_tag]}"
45
+ assert all_ok, "Tag #{different_tag.inspect}: expected: #{@mini_exiftool[different_tag].inspect}, actual: #{mini_exiftool_new[different_tag].inspect}"
45
46
 
46
47
  end
47
48
 
@@ -11,9 +11,10 @@ class TestInvalidByteSequenceInUtf8 < TestCase
11
11
  @json = File.read(File.dirname(__FILE__) + '/data/invalid_byte_sequence_in_utf8.json')
12
12
  end
13
13
 
14
- def test_invalid_byte_sequence_in_utf8_cause_error
15
- assert_raises ArgumentError do
16
- MiniExiftool.from_json(@json)
14
+ def test_invalid_byte_sequence_gets_unconverted_value_with_invalid_encoding
15
+ assert_nothing_raised do
16
+ mini_exiftool = MiniExiftool.from_json(@json)
17
+ assert_equal 1561, mini_exiftool.color_balance_unknown.size
17
18
  end
18
19
  end
19
20
 
metadata CHANGED
@@ -1,39 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_exiftool
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.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-07-05 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rim
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.7.0
19
+ version: 1.8.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.7.0
26
+ version: 1.8.1
27
27
  description: ''
28
28
  email: janfri26@gmail.com
29
29
  executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - README.rdoc
34
- - Changelog
35
33
  - COPYING
34
+ - Changelog
35
+ - README.rdoc
36
36
  - Rakefile
37
+ - Tutorial.rdoc
37
38
  - lib/mini_exiftool.rb
38
39
  - test/data/Bad_PreviewIFD.jpg
39
40
  - test/data/Canon.jpg
@@ -48,6 +49,7 @@ files:
48
49
  - test/test_bad_preview_ifd.rb
49
50
  - test/test_class_methods.rb
50
51
  - test/test_composite.rb
52
+ - test/test_cop_tags_from.rb
51
53
  - test/test_dumping.rb
52
54
  - test/test_encodings.rb
53
55
  - test/test_filename_access.rb
@@ -60,7 +62,6 @@ files:
60
62
  - test/test_special.rb
61
63
  - test/test_special_dates.rb
62
64
  - test/test_write.rb
63
- - Tutorial.rdoc
64
65
  homepage: http://gitorious.org/mini_exiftool
65
66
  licenses: []
66
67
  metadata: {}
@@ -77,17 +78,17 @@ require_paths:
77
78
  - lib
78
79
  required_ruby_version: !ruby/object:Gem::Requirement
79
80
  requirements:
80
- - - '>='
81
+ - - ">="
81
82
  - !ruby/object:Gem::Version
82
83
  version: '0'
83
84
  required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  requirements:
85
- - - '>='
86
+ - - ">="
86
87
  - !ruby/object:Gem::Version
87
88
  version: '0'
88
89
  requirements: []
89
90
  rubyforge_project:
90
- rubygems_version: 2.0.3
91
+ rubygems_version: 2.2.2
91
92
  signing_key:
92
93
  specification_version: 4
93
94
  summary: This library is wrapper for the Exiftool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool).