exif_datify 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6fb345542f74c17fbaef7bd148c622c3cfe4a1ce
4
+ data.tar.gz: 8f6faca76ea979861b1d2093ed27035c03691d79
5
+ SHA512:
6
+ metadata.gz: cd92c02f3072661839a38945505cad591526770ef27b6797966b1f4910994722ee702e6d2f27383cf07f4b006075c348265114ced2bfe278daadea47b25ab39b
7
+ data.tar.gz: a60c9e3ffcf5c2a3ceee71d29eea02f2d310f6d33a564ec61c2b7dce5f3eee327a38cf8acd0d5989b52d1f59235fb4bd6cb49335b31c394d8fe4756d6cdc4011
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exif_datify.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Harold Waterkeyn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # ExifDatify
2
+
3
+ Prepend files with date and time from exif information
4
+
5
+ ## Prerequisites
6
+
7
+ This gem requires `exiftool` to be installed.
8
+ On a Mac, this can be done with `brew install exiftool`.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'exif_datify'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install exif_datify
25
+
26
+ ## Usage
27
+
28
+ ```
29
+ datify photo.jpg
30
+ ```
31
+
32
+ or
33
+
34
+ ```
35
+ datify photo_directory
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies.
41
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hwaterke/exif_datify.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "exif_datify"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/datify ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'exif_datify'
4
+ require 'find'
5
+
6
+ raise "First argument must be a file or a directory path." unless ARGV.size == 1
7
+
8
+ date_extractor = ExifDatify::DateExtractor.new
9
+
10
+ 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]}"
20
+ else
21
+ date_extractor.rename(ARGV[0])
22
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'exif_datify/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "exif_datify"
8
+ spec.version = ExifDatify::VERSION
9
+ spec.authors = ["Harold Waterkeyn"]
10
+ spec.email = ["hwaterke@users.noreply.github.com"]
11
+
12
+ spec.summary = %q{Prepend files with date and time from exif information}
13
+ spec.description = %q{Name files based on exif information}
14
+ spec.homepage = "https://github.com/hwaterke/exif_datify"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,3 @@
1
+ module ExifDatify
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,60 @@
1
+ require "exif_datify/version"
2
+ require 'date'
3
+ require 'json'
4
+
5
+ module ExifDatify
6
+ class DateExtractor
7
+ attr_reader :counters
8
+ DATETIME_FORMAT = "%Y-%m-%d_%H-%M-%S_"
9
+ DATETIME_REGEX = /^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}/
10
+
11
+ def initialize
12
+ @tags = ['DateTimeOriginal', 'MediaCreateDate']
13
+ @quiet = false
14
+ @counters = Hash.new(0)
15
+ end
16
+
17
+ def extract_datetime(file_path)
18
+ meta = exiftool(file_path)
19
+ @tags.each do |tag|
20
+ return DateTime.parse(meta[tag]) if meta[tag]
21
+ end
22
+ nil
23
+ end
24
+
25
+ def rename(file_path)
26
+ @counters[:total] += 1
27
+ unless File.basename(file_path) =~ DATETIME_REGEX
28
+ prepend_date(file_path)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def prepend_date(file_path)
35
+ datetime = extract_datetime(file_path)
36
+ current_name = File.basename(file_path)
37
+ if datetime.nil?
38
+ puts "Could not extract date from #{current_name}" unless @quiet
39
+ else
40
+ prefix = datetime.strftime(DATETIME_FORMAT)
41
+ unless current_name.start_with?(prefix)
42
+ prefixed_name = File.join(File.dirname(file_path), prefix + current_name)
43
+ if File.exist?(prefixed_name)
44
+ raise "Cannot rename #{current_name}, #{prefixed_name} already exists."
45
+ else
46
+ File.rename(file_path, prefixed_name)
47
+ puts "Renamed #{current_name} to #{File.basename(prefixed_name)}." unless @quiet
48
+ @counters[:renamed] += 1
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ def exiftool(file_path)
55
+ raise "File #{file_path} does not exist" unless File.exist?(file_path)
56
+ result = %x(exiftool -u -d "%Y-%m-%d %H:%M:%S" -json "#{file_path}")
57
+ JSON.parse(result)[0]
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exif_datify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Harold Waterkeyn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Name files based on exif information
42
+ email:
43
+ - hwaterke@users.noreply.github.com
44
+ executables:
45
+ - datify
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - exe/datify
57
+ - exif_datify.gemspec
58
+ - lib/exif_datify.rb
59
+ - lib/exif_datify/version.rb
60
+ homepage: https://github.com/hwaterke/exif_datify
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.5.1
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Prepend files with date and time from exif information
84
+ test_files: []