exif_datify 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/datify +41 -12
- data/lib/exif_datify/version.rb +1 -1
- data/lib/exif_datify.rb +7 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5627d18c7b10a93eb703a8a22a338720d540f23e
|
4
|
+
data.tar.gz: e9375180c33347f38d9467b1f1a8217cf3c36498
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fafebe664cfab261d70fc57d736cadfa465189522dccc4ca5b992f36f44fd9686431445b9e0718c1dfe4a966998f4414c0520efac9ed9dd63ab832cd7f20504
|
7
|
+
data.tar.gz: e34842e0ee4b4830f9dba477890ac3e24e1b5fce08854284124e72e7882ac46ba98017b283028890116c94b4e02bc7ab91529bd0e2596a0b9cebf21c3223a4c1
|
data/exe/datify
CHANGED
@@ -2,21 +2,50 @@
|
|
2
2
|
|
3
3
|
require 'exif_datify'
|
4
4
|
require 'find'
|
5
|
-
|
6
|
-
raise "First argument must be a file or a directory path." unless ARGV.size == 1
|
5
|
+
require 'optparse'
|
7
6
|
|
8
7
|
date_extractor = ExifDatify::DateExtractor.new
|
8
|
+
extensions = nil
|
9
|
+
|
10
|
+
opt_parser = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: datify [options] path"
|
12
|
+
|
13
|
+
opts.on("-e", "--ext jpg,mov,png", Array, "File extensions to process.", "All by defaults.") do |list|
|
14
|
+
extensions = list.map { |e| ".#{e.downcase}" }
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("-t", "--tags x,y,z", Array, "EXIF tags to use. Ordered by priority.", "Default is #{date_extractor.tags.join(',')}") do |list|
|
18
|
+
date_extractor.tags = list
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-f", "--format FORMAT", "Datetime format to use.", "Default is '#{date_extractor.datetime_format}'") do |f|
|
22
|
+
date_extractor.datetime_format = f
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-q", "--quiet", "Runs quietly") do |q|
|
26
|
+
date_extractor.quiet!
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-h", "--help", "Prints this help") do
|
30
|
+
puts opts
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
opt_parser.parse!(ARGV)
|
36
|
+
raise "First argument must be a file or a directory path." unless ARGV.size == 1
|
9
37
|
|
10
38
|
if File.directory?(ARGV[0])
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
39
|
+
Find.find(ARGV[0]) do |entry|
|
40
|
+
next if FileTest.directory?(entry)
|
41
|
+
next unless extensions.nil? or extensions.include?(File.extname(entry).downcase)
|
42
|
+
begin
|
43
|
+
date_extractor.rename(entry)
|
44
|
+
rescue StandardError => e
|
45
|
+
puts "Error: #{e}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
puts "Processed #{date_extractor.counters[:total]} files, renamed #{date_extractor.counters[:renamed]}"
|
20
49
|
else
|
21
|
-
|
50
|
+
date_extractor.rename(ARGV[0])
|
22
51
|
end
|
data/lib/exif_datify/version.rb
CHANGED
data/lib/exif_datify.rb
CHANGED
@@ -5,15 +5,20 @@ require 'json'
|
|
5
5
|
module ExifDatify
|
6
6
|
class DateExtractor
|
7
7
|
attr_reader :counters
|
8
|
-
|
8
|
+
attr_accessor :datetime_format, :tags
|
9
9
|
DATETIME_REGEX = /^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}/
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@tags = ['DateTimeOriginal', 'MediaCreateDate']
|
13
|
+
@datetime_format = "%Y-%m-%d_%H-%M-%S_"
|
13
14
|
@quiet = false
|
14
15
|
@counters = Hash.new(0)
|
15
16
|
end
|
16
17
|
|
18
|
+
def quiet!
|
19
|
+
@quiet = true
|
20
|
+
end
|
21
|
+
|
17
22
|
def extract_datetime(file_path)
|
18
23
|
meta = exiftool(file_path)
|
19
24
|
@tags.each do |tag|
|
@@ -37,7 +42,7 @@ module ExifDatify
|
|
37
42
|
if datetime.nil?
|
38
43
|
puts "Could not extract date from #{current_name}" unless @quiet
|
39
44
|
else
|
40
|
-
prefix = datetime.strftime(
|
45
|
+
prefix = datetime.strftime(@datetime_format)
|
41
46
|
unless current_name.start_with?(prefix)
|
42
47
|
prefixed_name = File.join(File.dirname(file_path), prefix + current_name)
|
43
48
|
if File.exist?(prefixed_name)
|