multi_exiftool 0.1.3 → 0.2.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 +3 -0
- data/LICENSE +1 -1
- data/Manifest +3 -0
- data/README +7 -7
- data/examples/04_writing_using_groups.rb +33 -0
- data/lib/multi_exiftool/executable.rb +7 -5
- data/lib/multi_exiftool/reader.rb +4 -0
- data/lib/multi_exiftool/writer.rb +19 -5
- data/multi_exiftool.gemspec +17 -24
- data/test/test_executable.rb +24 -0
- data/test/test_reader.rb +6 -0
- data/test/test_writer.rb +22 -1
- data/test/test_writer_groups.rb +43 -0
- metadata +15 -5
data/CHANGELOG
CHANGED
data/LICENSE
CHANGED
data/Manifest
CHANGED
@@ -6,13 +6,16 @@ Rakefile
|
|
6
6
|
examples/01_simple_reading.rb
|
7
7
|
examples/02_simple_writing.rb
|
8
8
|
examples/03_reading_using_groups.rb
|
9
|
+
examples/04_writing_using_groups.rb
|
9
10
|
lib/multi_exiftool.rb
|
10
11
|
lib/multi_exiftool/executable.rb
|
11
12
|
lib/multi_exiftool/reader.rb
|
12
13
|
lib/multi_exiftool/values.rb
|
13
14
|
lib/multi_exiftool/writer.rb
|
14
15
|
test/helper.rb
|
16
|
+
test/test_executable.rb
|
15
17
|
test/test_reader.rb
|
16
18
|
test/test_values.rb
|
17
19
|
test/test_values_using_groups.rb
|
18
20
|
test/test_writer.rb
|
21
|
+
test/test_writer_groups.rb
|
data/README
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
This library is wrapper for the Exiftool command-line application
|
6
6
|
(http://www.sno.phy.queensu.ca/~phil/exiftool) written by Phil Harvey.
|
7
|
-
It is designed for dealing with multiple files at once by creating
|
7
|
+
It is designed for dealing with multiple files at once by creating
|
8
8
|
commands to call exiftool with various arguments, call it and parsing
|
9
9
|
the results.
|
10
10
|
|
@@ -24,7 +24,7 @@ the results.
|
|
24
24
|
=== Writing
|
25
25
|
|
26
26
|
require 'multi_exiftool'
|
27
|
-
|
27
|
+
|
28
28
|
writer = MultiExiftool::Writer.new
|
29
29
|
writer.filenames = Dir['*.jpg']
|
30
30
|
writer.values = {creator: 'Jan Friedrich', copyright: 'Public Domain'}
|
@@ -67,19 +67,19 @@ Jan Friedrich (janfri26 AT gmail DOT com)
|
|
67
67
|
== Copyright / License
|
68
68
|
|
69
69
|
The MIT License
|
70
|
-
|
71
|
-
Copyright (c) 2009-
|
72
|
-
|
70
|
+
|
71
|
+
Copyright (c) 2009-2012 Jan Friedrich
|
72
|
+
|
73
73
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
74
74
|
of this software and associated documentation files (the "Software"), to deal
|
75
75
|
in the Software without restriction, including without limitation the rights
|
76
76
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
77
77
|
copies of the Software, and to permit persons to whom the Software is
|
78
78
|
furnished to do so, subject to the following conditions:
|
79
|
-
|
79
|
+
|
80
80
|
The above copyright notice and this permission notice shall be included in
|
81
81
|
all copies or substantial portions of the Software.
|
82
|
-
|
82
|
+
|
83
83
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
84
84
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
85
85
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'multi_exiftool'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
if ARGV.empty?
|
5
|
+
$stderr.puts 'No filenames given.'
|
6
|
+
exit -1
|
7
|
+
end
|
8
|
+
|
9
|
+
puts 'Please enter a description for the given files:'
|
10
|
+
description = $stdin.gets.chomp
|
11
|
+
|
12
|
+
puts 'Please enter a caption for the given files:'
|
13
|
+
caption = $stdin.gets.chomp
|
14
|
+
|
15
|
+
writer = MultiExiftool::Writer.new
|
16
|
+
writer.filenames = ARGV
|
17
|
+
|
18
|
+
# specifying group by prefix
|
19
|
+
writer.values = {'exif:imagedescription' => description, 'xmp:description' => description}
|
20
|
+
|
21
|
+
# specifying group hierarchical
|
22
|
+
writer.values.merge! YAML.load <<-END
|
23
|
+
iptc:
|
24
|
+
caption-abstract: #{caption}
|
25
|
+
xmp:
|
26
|
+
caption: #{caption}
|
27
|
+
END
|
28
|
+
|
29
|
+
if writer.write
|
30
|
+
puts 'ok'
|
31
|
+
else
|
32
|
+
puts writer.errors.join
|
33
|
+
end
|
@@ -7,12 +7,14 @@ module MultiExiftool
|
|
7
7
|
# Mixin for Reader and Writer.
|
8
8
|
module Executable
|
9
9
|
|
10
|
+
attr_reader :filenames
|
10
11
|
attr_accessor :exiftool_command, :errors, :numerical
|
11
|
-
attr_writer :options
|
12
|
+
attr_writer :options
|
12
13
|
|
13
14
|
def initialize
|
14
15
|
@exiftool_command = 'exiftool'
|
15
16
|
@options = {}
|
17
|
+
@filenames = []
|
16
18
|
end
|
17
19
|
|
18
20
|
def options
|
@@ -21,8 +23,8 @@ module MultiExiftool
|
|
21
23
|
opts
|
22
24
|
end
|
23
25
|
|
24
|
-
def filenames
|
25
|
-
Array(
|
26
|
+
def filenames= value
|
27
|
+
@filenames = Array(value)
|
26
28
|
end
|
27
29
|
|
28
30
|
def execute # :nodoc:
|
@@ -34,12 +36,12 @@ module MultiExiftool
|
|
34
36
|
private
|
35
37
|
|
36
38
|
def escape str
|
37
|
-
Shellwords.escape(str)
|
39
|
+
Shellwords.escape(str.to_s)
|
38
40
|
end
|
39
41
|
|
40
42
|
def escaped_filenames
|
41
43
|
raise MultiExiftool::Error.new('No filenames.') if filenames.empty?
|
42
|
-
|
44
|
+
filenames.map { |fn| Shellwords.escape(fn) }
|
43
45
|
end
|
44
46
|
|
45
47
|
def options_args
|
@@ -8,13 +8,13 @@ module MultiExiftool
|
|
8
8
|
# possible errors.
|
9
9
|
class Writer
|
10
10
|
|
11
|
-
attr_accessor :overwrite_original
|
12
|
-
attr_writer :values
|
11
|
+
attr_accessor :overwrite_original, :values
|
13
12
|
|
14
13
|
include Executable
|
15
14
|
|
16
|
-
def
|
17
|
-
|
15
|
+
def initialize
|
16
|
+
super
|
17
|
+
@values = {}
|
18
18
|
end
|
19
19
|
|
20
20
|
# Options to use with the exiftool command.
|
@@ -42,7 +42,21 @@ module MultiExiftool
|
|
42
42
|
|
43
43
|
def values_args
|
44
44
|
raise MultiExiftool::Error.new('No values.') if values.empty?
|
45
|
-
@values.map {|
|
45
|
+
values_to_param_array(@values).map {|arg| "-#{arg}"}
|
46
|
+
end
|
47
|
+
|
48
|
+
def values_to_param_array hash
|
49
|
+
res = []
|
50
|
+
hash.each do |tag, val|
|
51
|
+
if val.respond_to? :to_hash
|
52
|
+
res << values_to_param_array(val.to_hash).map {|arg| "#{tag}:#{arg}"}
|
53
|
+
elsif val.respond_to? :to_ary
|
54
|
+
res << val.map {|v| "#{tag}=#{escape(v)}"}
|
55
|
+
else
|
56
|
+
res << "#{tag}=#{escape(val)}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
res.flatten
|
46
60
|
end
|
47
61
|
|
48
62
|
def parse_results
|
data/multi_exiftool.gemspec
CHANGED
@@ -1,33 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.
|
4
|
+
s.name = "multi_exiftool"
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
s.files = [
|
14
|
-
s.homepage =
|
15
|
-
s.post_install_message =
|
16
|
-
|
17
|
-
|
18
|
-
| it's found in your PATH (Try "exiftool -ver" on your commandline). |
|
19
|
-
| For more details see |
|
20
|
-
| http://www.sno.phy.queensu.ca/~phil/exiftool/install.html |
|
21
|
-
+-----------------------------------------------------------------------+
|
22
|
-
}
|
23
|
-
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Multi_exiftool}, %q{--main}, %q{README}]
|
24
|
-
s.require_paths = [%q{lib}]
|
8
|
+
s.authors = ["Jan Friedrich"]
|
9
|
+
s.date = "2012-05-11"
|
10
|
+
s.description = "This library is wrapper for the Exiftool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool) written by Phil Harvey. It is designed for dealing with multiple files at once by creating commands to call exiftool with various arguments, call it and parsing the results."
|
11
|
+
s.email = "janfri26@gmail.com"
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/multi_exiftool.rb", "lib/multi_exiftool/executable.rb", "lib/multi_exiftool/reader.rb", "lib/multi_exiftool/values.rb", "lib/multi_exiftool/writer.rb"]
|
13
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "examples/01_simple_reading.rb", "examples/02_simple_writing.rb", "examples/03_reading_using_groups.rb", "examples/04_writing_using_groups.rb", "lib/multi_exiftool.rb", "lib/multi_exiftool/executable.rb", "lib/multi_exiftool/reader.rb", "lib/multi_exiftool/values.rb", "lib/multi_exiftool/writer.rb", "test/helper.rb", "test/test_executable.rb", "test/test_reader.rb", "test/test_values.rb", "test/test_values_using_groups.rb", "test/test_writer.rb", "test/test_writer_groups.rb", "multi_exiftool.gemspec"]
|
14
|
+
s.homepage = "http://gitorious.org/multi_exiftool"
|
15
|
+
s.post_install_message = "\n+-----------------------------------------------------------------------+\n| Please ensure you have installed exiftool version 7.65 or higher and |\n| it's found in your PATH (Try \"exiftool -ver\" on your commandline). |\n| For more details see |\n| http://www.sno.phy.queensu.ca/~phil/exiftool/install.html |\n+-----------------------------------------------------------------------+\n "
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Multi_exiftool", "--main", "README"]
|
17
|
+
s.require_paths = ["lib"]
|
25
18
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
|
26
|
-
s.requirements = [
|
27
|
-
s.rubyforge_project =
|
28
|
-
s.rubygems_version =
|
29
|
-
s.summary =
|
30
|
-
s.test_files = [
|
19
|
+
s.requirements = ["exiftool, version 7.65 or higher"]
|
20
|
+
s.rubyforge_project = "multi_exiftool"
|
21
|
+
s.rubygems_version = "1.8.21"
|
22
|
+
s.summary = "This library is wrapper for the Exiftool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool)."
|
23
|
+
s.test_files = ["test/test_executable.rb", "test/test_reader.rb", "test/test_values.rb", "test/test_values_using_groups.rb", "test/test_writer.rb", "test/test_writer_groups.rb"]
|
31
24
|
|
32
25
|
if s.respond_to? :specification_version then
|
33
26
|
s.specification_version = 3
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'helper'
|
3
|
+
|
4
|
+
class TestExecutable < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class Exec
|
7
|
+
include MultiExiftool::Executable
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
setup do
|
14
|
+
@executable = Exec.new
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'appending to filenames' do
|
18
|
+
@executable.filenames << 'a.jpg'
|
19
|
+
assert_equal %w(a.jpg), @executable.filenames
|
20
|
+
@executable.filenames << 'b.jpg'
|
21
|
+
assert_equal %W(a.jpg b.jpg), @executable.filenames
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/test/test_reader.rb
CHANGED
@@ -25,6 +25,12 @@ class TestReader < Test::Unit::TestCase
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
test 'one filename as string' do
|
29
|
+
@reader.filenames = 'a.jpg'
|
30
|
+
command = 'exiftool -J a.jpg'
|
31
|
+
assert_equal command, @reader.command
|
32
|
+
end
|
33
|
+
|
28
34
|
test 'filenames with spaces' do
|
29
35
|
@reader.filenames = ['one file with spaces.jpg', 'another file with spaces.tif']
|
30
36
|
command = 'exiftool -J one\ file\ with\ spaces.jpg another\ file\ with\ spaces.tif'
|
data/test/test_writer.rb
CHANGED
@@ -27,12 +27,19 @@ class TestWriter < Test::Unit::TestCase
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
test 'one filename as string' do
|
31
|
+
@writer.values = {:author => 'janfri'}
|
32
|
+
@writer.filenames = 'a.jpg'
|
33
|
+
command = 'exiftool -author=janfri a.jpg'
|
34
|
+
assert_equal command, @writer.command
|
35
|
+
end
|
36
|
+
|
30
37
|
test 'no values set' do
|
31
38
|
@writer.filenames = %w(a.jpg b.tif c.bmp)
|
32
39
|
assert_raises MultiExiftool::Error do
|
33
40
|
@writer.command
|
34
41
|
end
|
35
|
-
@writer.values =
|
42
|
+
@writer.values = {}
|
36
43
|
assert_raises MultiExiftool::Error do
|
37
44
|
@writer.command
|
38
45
|
end
|
@@ -45,6 +52,20 @@ class TestWriter < Test::Unit::TestCase
|
|
45
52
|
assert_equal command, @writer.command
|
46
53
|
end
|
47
54
|
|
55
|
+
test 'tags with rational value' do
|
56
|
+
@writer.filenames = %w(a.jpg b.tif c.bmp)
|
57
|
+
@writer.values ={shutterspeed: Rational(1, 125)}
|
58
|
+
command = 'exiftool -shutterspeed=1/125 a.jpg b.tif c.bmp'
|
59
|
+
assert_equal command, @writer.command
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'tags with array-like values' do
|
63
|
+
@writer.filenames = %w(a.jpg b.tif c.bmp)
|
64
|
+
@writer.values = {keywords: ['one', 'two', 'and three']}
|
65
|
+
command = 'exiftool -keywords=one -keywords=two -keywords=and\ three a.jpg b.tif c.bmp'
|
66
|
+
assert_equal command, @writer.command
|
67
|
+
end
|
68
|
+
|
48
69
|
test 'filenames with spaces' do
|
49
70
|
@writer.filenames = ['one file with spaces.jpg', 'another file with spaces.tif']
|
50
71
|
@writer.values = {:author => 'janfri'}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'helper'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class TestWriterGroups < Test::Unit::TestCase
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@writer = MultiExiftool::Writer.new
|
9
|
+
@writer.filenames = %w(a.jpg b.bmp c.tif)
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'simple case' do
|
13
|
+
@writer.values = {:exif => {:comment => 'test'} }
|
14
|
+
command = 'exiftool -exif:comment=test a.jpg b.bmp c.tif'
|
15
|
+
assert_equal command, @writer.command
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'more than one groups and tags' do
|
19
|
+
@writer.values = YAML.load <<-END
|
20
|
+
exif:
|
21
|
+
author: janfri
|
22
|
+
comment: some comment
|
23
|
+
xmp:
|
24
|
+
author: janfri
|
25
|
+
subjectlocation: somewhere else
|
26
|
+
END
|
27
|
+
command = 'exiftool -exif:author=janfri -exif:comment=some\ comment -xmp:author=janfri -xmp:subjectlocation=somewhere\ else a.jpg b.bmp c.tif'
|
28
|
+
assert_equal command, @writer.command
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'tags with array-like values' do
|
32
|
+
@writer.values = YAML.load <<-END
|
33
|
+
exif:
|
34
|
+
keywords:
|
35
|
+
- one
|
36
|
+
- two
|
37
|
+
- and three
|
38
|
+
END
|
39
|
+
command = 'exiftool -exif:keywords=one -exif:keywords=two -exif:keywords=and\ three a.jpg b.bmp c.tif'
|
40
|
+
assert_equal command, @writer.command
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_exiftool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: contest
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: This library is wrapper for the Exiftool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool)
|
26
31
|
written by Phil Harvey. It is designed for dealing with multiple files at once by
|
27
32
|
creating commands to call exiftool with various arguments, call it and parsing the
|
@@ -47,16 +52,19 @@ files:
|
|
47
52
|
- examples/01_simple_reading.rb
|
48
53
|
- examples/02_simple_writing.rb
|
49
54
|
- examples/03_reading_using_groups.rb
|
55
|
+
- examples/04_writing_using_groups.rb
|
50
56
|
- lib/multi_exiftool.rb
|
51
57
|
- lib/multi_exiftool/executable.rb
|
52
58
|
- lib/multi_exiftool/reader.rb
|
53
59
|
- lib/multi_exiftool/values.rb
|
54
60
|
- lib/multi_exiftool/writer.rb
|
55
61
|
- test/helper.rb
|
62
|
+
- test/test_executable.rb
|
56
63
|
- test/test_reader.rb
|
57
64
|
- test/test_values.rb
|
58
65
|
- test/test_values_using_groups.rb
|
59
66
|
- test/test_writer.rb
|
67
|
+
- test/test_writer_groups.rb
|
60
68
|
- multi_exiftool.gemspec
|
61
69
|
homepage: http://gitorious.org/multi_exiftool
|
62
70
|
licenses: []
|
@@ -90,12 +98,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
98
|
requirements:
|
91
99
|
- exiftool, version 7.65 or higher
|
92
100
|
rubyforge_project: multi_exiftool
|
93
|
-
rubygems_version: 1.8.
|
101
|
+
rubygems_version: 1.8.21
|
94
102
|
signing_key:
|
95
103
|
specification_version: 3
|
96
104
|
summary: This library is wrapper for the Exiftool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool).
|
97
105
|
test_files:
|
106
|
+
- test/test_executable.rb
|
98
107
|
- test/test_reader.rb
|
99
108
|
- test/test_values.rb
|
100
109
|
- test/test_values_using_groups.rb
|
101
110
|
- test/test_writer.rb
|
111
|
+
- test/test_writer_groups.rb
|