image_mover 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea04978990f5e797415f26d5fd658be33c57d2ff
4
+ data.tar.gz: 9ec52f6ca85fe28d9cdb858fcd8a45dca6c09dcb
5
+ SHA512:
6
+ metadata.gz: 4c62aac672385a865771867cb60b8641864ee9ddbd378943d23f5fd417c15ae7c2ce9c42cc18a1cb5838951c3d24bc9ea2bbcef4a47b40c022ff59ddf1d7a3d0
7
+ data.tar.gz: c66ed056d4077cf9768d73c4c5140e812423bf915b78bebf963383fedf136e3984f35bc0bc7fb0432ff88ea07bb2776610fb4d2856abaee6fd68089b6efd9cdb
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Image Mover
2
+
3
+ ### Moves and renames your images files based on the Exif info
data/bin/image_mover ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'image_mover'
4
+
5
+ image_mover = ImageMover.new ARGV[0], ARGV[1]
6
+ image_mover.move
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'image_mover'
7
+ s.version = '0.0.1'
8
+ s.date = '2015-04-04'
9
+ s.summary = 'Organizes your image files'
10
+ s.description = 'Moves and renames your images files based on the Exif info'
11
+ s.authors = ['Robert Jan de Gelder']
12
+ s.email = ['rjdegelder@gmail.com']
13
+ s.homepage = 'http://github.com/rjdegelder/image_mover'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+
19
+ s.add_dependency 'exifr', '1.2.1'
20
+ end
@@ -0,0 +1,58 @@
1
+ require 'fileutils'
2
+ require 'exifr'
3
+
4
+ class ImageMover
5
+
6
+ attr_reader :source_path, :destination_path
7
+
8
+ # ImageMover.new("/Users/robertjan/Pictures/Foto's/camera", "/Volumes/pictures/photos/Import").move
9
+ def initialize source_path, destination_path
10
+ @source_path = source_path
11
+ @destination_path = destination_path
12
+ end
13
+
14
+ def move
15
+ Dir.glob("#{source_path}/**/*.jpg").each do |filename|
16
+ move_file filename
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def move_file filename
23
+ if File.file?(filename) && !(File.basename(filename) =~ /\.jpg$/i).nil?
24
+ exif_data = EXIFR::JPEG.new(filename)
25
+ date_time = exif_data.date_time_original || exif_data.date_time || File.mtime(filename)
26
+
27
+ year_dir = File.join [destination_path, date_time.strftime("%Y")]
28
+ month_dir = File.join [year_dir, date_time.strftime("%m")]
29
+ date_dir = File.join [month_dir, date_time.strftime("%Y-%m-%d")]
30
+ new_filename = File.join [date_dir, File.basename(filename)]
31
+
32
+ if File.file?(new_filename)
33
+ puts "Removing already existing file: #{filename}"
34
+ FileUtils.rm(filename)
35
+ else
36
+ unless File.directory?(year_dir)
37
+ puts "Creating directory: #{year_dir}"
38
+ FileUtils.mkdir(year_dir)
39
+ end
40
+
41
+ unless File.directory?(month_dir)
42
+ puts "Creating directory: #{month_dir}"
43
+ FileUtils.mkdir(month_dir)
44
+ end
45
+
46
+ unless File.directory?(date_dir)
47
+ puts "Creating directory: #{date_dir}"
48
+ FileUtils.mkdir(date_dir)
49
+ end
50
+
51
+ puts "Moving: #{File.basename(filename)} to: #{new_filename}"
52
+ FileUtils.mv(filename, new_filename)
53
+ end
54
+ end
55
+ rescue => e
56
+ puts "Error with #{filename}: #{e.message}"
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: image_mover
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert Jan de Gelder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: exifr
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.1
27
+ description: Moves and renames your images files based on the Exif info
28
+ email:
29
+ - rjdegelder@gmail.com
30
+ executables:
31
+ - image_mover
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - README.md
37
+ - bin/image_mover
38
+ - image_mover.gemspec
39
+ - lib/image_mover.rb
40
+ homepage: http://github.com/rjdegelder/image_mover
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.4.6
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Organizes your image files
64
+ test_files: []