photo_rename 0.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/photo_rename +18 -0
  3. data/lib/photo_rename.rb +76 -0
  4. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a3c93639930f240896e907647d99aadd410be058
4
+ data.tar.gz: 2e8dcf1038c1c2395be8422a3181e4adb1b25d8a
5
+ SHA512:
6
+ metadata.gz: 30728f8d5cff8349ff06c9226deeb166c678e41efabd8af12c9983bc2fbe352a83336cc8b4470b53982efc1c81703e1509315dc30093c523e14b95fd5dca1122
7
+ data.tar.gz: f41d45b882d057b7c23961bbd7b27705dd1c1b4baada70f05e89bb6c452543376e6530e279addf7e97b8285856b394ed3a7ac8b1a2badbc13198b4223a8293a4
data/bin/photo_rename ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'photo_rename'
4
+
5
+ def main()
6
+ photo_rename = Photo_rename.new()
7
+ ARGV.length == 0 ? print_opts = true : print_opts = false
8
+ opts = photo_rename.parse_options(print_opts)
9
+
10
+ ARGV.each do |arg|
11
+ map = photo_rename.name_map(arg)
12
+ photo_rename.print_replace_names(arg, map)
13
+ end
14
+
15
+ end
16
+
17
+ main()
18
+
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # photo_renamer renames all .jpg files in a given directory to the form IMG_*yyyymmdd*_*hhmmss*.jpg
4
+ # Copyright (C) 2013 Tjaart van der Walt
5
+
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ require 'optparse'
20
+ require "rubygems"
21
+ require 'awesome_print'
22
+
23
+ class Photo_rename
24
+ def new_name(mdate)
25
+ ret_string = "IMG_"
26
+ ret_string += "#{mdate.year}#{("%02d" % mdate.month).to_s}#{("%02d" % mdate.day).to_s}"
27
+ ret_string += "_#{("%02d" % mdate.hour).to_s}#{("%02d" % mdate.min).to_s}#{("%02d" % mdate.sec).to_s}"
28
+ ret_string += ".jpg"
29
+ return ret_string
30
+ end
31
+
32
+ def name_map(dir_path)
33
+ name_map = {}
34
+ Dir.glob("#{dir_path}/*.[jJ][pP][gG]").sort.each do |f|
35
+ mdate = File.mtime(f)
36
+ name_map[f] = "#{dir_path}/#{new_name(mdate)}"
37
+ end
38
+ return name_map
39
+ end
40
+
41
+ def print_replace_names(dir_path, map)
42
+ puts "We will be renaming the following image files"
43
+ ap map
44
+ puts "Are you sure you want to continue renaming these files (Y/N)"
45
+ if STDIN.gets.chomp.downcase == "y"
46
+ map.each() do |key, value|
47
+ File.rename("#{key}", "#{value}")
48
+ end
49
+ end
50
+ end
51
+
52
+ def parse_options(print_opts)
53
+ options = {}
54
+
55
+ optparse = OptionParser.new do|opts|
56
+ opts.banner = "Usage: photo_renamer.rb [options] dir1 [dir2 ...]"
57
+
58
+ options[:batch] = false
59
+ opts.on( '-b', '--batch', 'Batch mode. Will not ask confirmation before renaming.' ) do
60
+ options[:batch] = true
61
+ end
62
+
63
+ opts.on( '-h', '--help', 'Display this screen' ) do
64
+ puts opts
65
+ exit
66
+ end
67
+ end
68
+
69
+ if print_opts
70
+ puts print_opts
71
+ puts optparse
72
+ end
73
+ optparse.parse!
74
+ return options
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: photo_rename
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tjaart van der Walt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Rename JPG images in a directory based on the date in the file's mtime
14
+ field. By default the target file names are in the same format as those created
15
+ by Android devices.
16
+ email: gem@tjaart.co.za
17
+ executables:
18
+ - photo_rename
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/photo_rename
23
+ - lib/photo_rename.rb
24
+ homepage: https://github.com/tjaartvdwalt/photo-renamer
25
+ licenses:
26
+ - GNU GPL
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.2.2
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Photo renamer
48
+ test_files: []