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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fb345542f74c17fbaef7bd148c622c3cfe4a1ce
4
- data.tar.gz: 8f6faca76ea979861b1d2093ed27035c03691d79
3
+ metadata.gz: 5627d18c7b10a93eb703a8a22a338720d540f23e
4
+ data.tar.gz: e9375180c33347f38d9467b1f1a8217cf3c36498
5
5
  SHA512:
6
- metadata.gz: cd92c02f3072661839a38945505cad591526770ef27b6797966b1f4910994722ee702e6d2f27383cf07f4b006075c348265114ced2bfe278daadea47b25ab39b
7
- data.tar.gz: a60c9e3ffcf5c2a3ceee71d29eea02f2d310f6d33a564ec61c2b7dce5f3eee327a38cf8acd0d5989b52d1f59235fb4bd6cb49335b31c394d8fe4756d6cdc4011
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
- Find.find(ARGV[0]) do |entry|
12
- next if FileTest.directory?(entry)
13
- begin
14
- date_extractor.rename(entry)
15
- rescue StandardError => e
16
- puts "Error: #{e}"
17
- end
18
- end
19
- puts "Processed #{date_extractor.counters[:total]} files, renamed #{date_extractor.counters[:renamed]}"
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
- date_extractor.rename(ARGV[0])
50
+ date_extractor.rename(ARGV[0])
22
51
  end
@@ -1,3 +1,3 @@
1
1
  module ExifDatify
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
- DATETIME_FORMAT = "%Y-%m-%d_%H-%M-%S_"
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(DATETIME_FORMAT)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exif_datify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harold Waterkeyn