imagebackup 0.2.0 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile +5 -3
- data/README.md +68 -16
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/imagebackup.gemspec +15 -12
- data/lib/classes/filetypes.csv +4 -2
- data/lib/classes/filetypes.rb +11 -9
- data/lib/imagebackup.rb +47 -32
- data/lib/imagebackup/version.rb +1 -1
- data/lib/methods/build_paths.rb +6 -4
- data/lib/methods/copy_pic.rb +21 -7
- data/lib/methods/display_help.rb +71 -0
- data/lib/methods/get_dates.rb +7 -7
- data/tests/bad_exif/DSC03688.JPG +0 -0
- data/tests/corrupt/test.cr2 +0 -0
- data/tests/truncated/IMG_9372.CR2 +0 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ff05d8110aa15c4add99cca0b1d41174fd3978e59e5d744a2411012e7a8e838
|
4
|
+
data.tar.gz: 3ef406408a286734d760175db13b1255cf1b6c025792cd5daa6e32152a9fc134
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac5e4ede52a1a770419472068e66c64e02ef7688616c1c44be1a76e384ecc242e9cbfd05517a5bd2876153202af793e473f157fe382bcfb7a2e939763a6e0d62
|
7
|
+
data.tar.gz: f77229df988fa05d9b653d438edf106a3bafcdca787b64838927e4081e44bcedcd6f1bc41f62c8e1d13d214929dbf9a73d60381ef09723fe47e6686c679c5f91
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in imagebackup.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
gem
|
7
|
-
gem
|
8
|
+
gem 'rake', '~> 12.0'
|
9
|
+
gem 'rspec', '~> 3.0'
|
data/README.md
CHANGED
@@ -2,34 +2,86 @@
|
|
2
2
|
|
3
3
|
## Keep your photos and videos organized by date.
|
4
4
|
|
5
|
-
### A simple terminal app to crawl a folder (usually a camera card's DCIM folder) for pictures and videos, and pop them in dated folders to your destination folder of choice. Uses exif data when available, creation_time, or the file's own creation date if nothing better is present.
|
5
|
+
### A simple terminal app to crawl a folder (usually a camera card's DCIM folder) for pictures and videos, and pop them in dated folders to your destination folder of choice. Uses exif data when available, creation_time, or the file's own creation date if nothing better is present.
|
6
|
+
### Will also copy over any xmp sidecar files found, not overwriting.
|
6
7
|
|
8
|
+
Source is available here: [https://github.com/adrian-sal-kennedy/imagebackup]()
|
7
9
|
|
8
|
-
##
|
10
|
+
## Options:
|
11
|
+
-n, --dry-run
|
12
|
+
Run without actually doing anything. Good for making sure things are working properly. This will also give you console output which helps identify unreadable files.
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
-a, --add-filetype *extension* *type*
|
15
|
+
This will add a custom file type to the list of files it's looking for. If you have an arcane digital camera (we currently support canon, sony, pentax but new stuff comes out all the time), this will allow you to add your raw files.
|
16
|
+
You can also access *filetypes.csv* and add them manually, but ensure there's a blank line at the end or this program may behave badly.
|
13
17
|
|
14
|
-
|
15
|
-
- fileutils.rb
|
16
|
-
- json
|
17
|
-
|
18
|
-
Bundler should handle all these dependencies. If for some reason it doesn't you can run this in terminal:
|
19
|
-
```bash
|
20
|
-
$ gem install exiv2 ffprober
|
21
|
-
```
|
18
|
+
-m will move (deleting the original), which is probably not a good idea in most cases but still useful at times.
|
22
19
|
|
23
20
|
## Usage:
|
24
21
|
|
22
|
+
### To backup a camera card:
|
23
|
+
|
25
24
|
```bash
|
26
25
|
$ cd /media/username/EOS_DIGITAL/DCIM
|
27
|
-
$ imagebackup ~/Photos/raw
|
26
|
+
$ imagebackup.rb ~/Photos/raw
|
28
27
|
```
|
28
|
+
|
29
29
|
This will search all files within the DCIM folder, check them with either exiv2 (for stills) or ffprobe (for videos) and retrieve their creation dates.
|
30
30
|
It will then copy them to a folder of the form ```~/Photos/raw/<yyyy>-<mm>-<dd>```
|
31
31
|
If it's unable to find metadata in a file it will look at the file's creation time attribute, which is less reliable but usually ok.
|
32
32
|
|
33
|
+
### To register a new file type:
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
```bash
|
36
|
+
$ imagebackup.rb --add-filetype orf pic
|
37
|
+
```
|
38
|
+
or
|
39
|
+
```bash
|
40
|
+
$ imagebackup.rb -a orf pic
|
41
|
+
```
|
42
|
+
This will work with ```*.ORF```, ```orf```, ```".orf"``` as it will strip off any unnecessary characters. It is case-insensitive.
|
43
|
+
|
44
|
+
### To do a dry run, checking each file and destination but not actually copying:
|
45
|
+
|
46
|
+
```bash
|
47
|
+
$ imagebackup.rb -n ~/Photos/raw
|
48
|
+
```
|
49
|
+
or
|
50
|
+
```bash
|
51
|
+
$ imagebackup.rb ~/Photos/raw --dry-run
|
52
|
+
```
|
53
|
+
|
54
|
+
### To move files instead of copying them (careful!):
|
55
|
+
```bash
|
56
|
+
$ imagebackup.rb -m ~/Photos/raw
|
57
|
+
```
|
58
|
+
or
|
59
|
+
```bash
|
60
|
+
$ imagebackup.rb --move ~/Photos/raw
|
61
|
+
```
|
62
|
+
|
63
|
+
### To make symbolic links instead of copying files:
|
64
|
+
```bash
|
65
|
+
$ imagebackup.rb -l ~/Photos/raw
|
66
|
+
```
|
67
|
+
or
|
68
|
+
```bash
|
69
|
+
$ imagebackup.rb --link ~/Photos/raw
|
70
|
+
```
|
71
|
+
This mode can be useful if you want to operate on the files in one place but keep them on their media. Particularly useful for large movie files.
|
72
|
+
|
73
|
+
## Dependencies:
|
74
|
+
|
75
|
+
**Ruby** v2.3.0 or greater, plus gems:
|
76
|
+
- [exiv2](https://rubygems.org/gems/exiv2/versions/0.0.8) to retrieve EXIF date/time.
|
77
|
+
- [ffprober](https://github.com/beanieboi/ffprober) to retrieve video container date/time tags if present.
|
78
|
+
- [colorize](https://github.com/fazibear/colorize) to make output a little more readable and engaging.
|
79
|
+
|
80
|
+
Ruby modules:
|
81
|
+
- [fileutils](https://ruby-doc.org/stdlib-2.4.1/libdoc/fileutils/rdoc/FileUtils.html) to manage file operations (get attributes, copy, move, link).
|
82
|
+
- [csv](https://ruby-doc.org/stdlib-2.6.1/libdoc/csv/rdoc/CSV.html) to process the list of available file types.
|
83
|
+
|
84
|
+
Bundler should handle all these dependencies. If for some reason it doesn't you can run this in terminal:
|
85
|
+
```bash
|
86
|
+
$ gem install exiv2 ffprober colorize
|
87
|
+
```
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'imagebackup'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "imagebackup"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/imagebackup.gemspec
CHANGED
@@ -1,32 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/imagebackup/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
6
|
+
spec.name = 'imagebackup'
|
5
7
|
spec.version = Imagebackup::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
+
spec.authors = ['adrian-sal-kennedy']
|
9
|
+
spec.email = ['adrian.sal.kennedy@gmail.com']
|
8
10
|
|
9
|
-
spec.summary =
|
10
|
-
spec.description =
|
11
|
-
spec.homepage =
|
12
|
-
spec.license =
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
11
|
+
spec.summary = 'A simple CLI app to backup all pics and vids from current folder to a destination in yyyy-mm-dd folders.'
|
12
|
+
spec.description = 'Uses Exiv2 and ffprobe to find creation dates for media types it finds.'
|
13
|
+
spec.homepage = 'https://github.com/adrian-sal-kennedy/imagebackup'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
14
16
|
|
15
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
18
|
|
17
|
-
spec.metadata[
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
20
|
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
19
21
|
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
22
|
|
21
23
|
# Specify which files should be added to the gem when it is released.
|
22
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
27
|
end
|
26
|
-
spec.bindir =
|
28
|
+
spec.bindir = 'exe'
|
27
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
30
|
+
spec.require_paths = ['lib']
|
29
31
|
|
32
|
+
spec.add_dependency 'colorize'
|
30
33
|
spec.add_dependency 'exiv2'
|
31
34
|
spec.add_dependency 'ffprober'
|
32
35
|
end
|
data/lib/classes/filetypes.csv
CHANGED
@@ -3,9 +3,13 @@ mp4,movie
|
|
3
3
|
avi,movie
|
4
4
|
mpg,movie
|
5
5
|
vob,movie
|
6
|
+
m2ts,movie
|
6
7
|
3gp,movie
|
7
8
|
mxf,movie
|
8
9
|
mlv,movie
|
10
|
+
webm,movie
|
11
|
+
mkv,movie
|
12
|
+
ogm,movie
|
9
13
|
dng,pic
|
10
14
|
tif,pic
|
11
15
|
jpg,pic
|
@@ -15,5 +19,3 @@ cr2,pic
|
|
15
19
|
arw,pic
|
16
20
|
raw,pic
|
17
21
|
gif,pic
|
18
|
-
gif,pic
|
19
|
-
gif,pic
|
data/lib/classes/filetypes.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require 'csv'
|
2
1
|
|
2
|
+
# FileTypes is a very simple file class to store and retrieve the list of files
|
3
|
+
# we are interested in backing up.
|
3
4
|
class FileTypes
|
4
5
|
def self.list
|
5
6
|
file_list = []
|
@@ -7,11 +8,11 @@ class FileTypes
|
|
7
8
|
file_list << "**/*.#{csv[0]}"
|
8
9
|
file_list << "**/*.#{csv[0].upcase}"
|
9
10
|
end
|
10
|
-
|
11
|
+
file_list
|
11
12
|
end
|
12
13
|
|
13
|
-
def self.add(ext=nil,type=nil)
|
14
|
-
unless ext
|
14
|
+
def self.add(ext = nil, type = nil)
|
15
|
+
unless ext
|
15
16
|
puts 'please enter the file type\'s extension, with or without the dot.'
|
16
17
|
ext = gets.strip
|
17
18
|
end
|
@@ -19,12 +20,13 @@ class FileTypes
|
|
19
20
|
puts 'please enter "movie" or "pic" so we know what we\'re working with.'
|
20
21
|
type = gets.strip
|
21
22
|
end
|
22
|
-
ext = ext.to_s.gsub(/[*."]/,'')
|
23
|
-
|
24
|
-
type = (type.downcase.include?('m')) ? "movie" : "pic"
|
23
|
+
ext = ext.to_s.gsub(/[*."]/, '')
|
24
|
+
type = type.downcase.include?('m') ? 'movie' : 'pic'
|
25
25
|
puts "opening file \"#{File.dirname(__FILE__)}/filetypes.csv\""
|
26
|
-
CSV.open("#{File.dirname(__FILE__)}/filetypes.csv",
|
27
|
-
|
26
|
+
CSV.open("#{File.dirname(__FILE__)}/filetypes.csv", 'a') do |csv|
|
27
|
+
csv << [ext, type]
|
28
28
|
end
|
29
|
+
puts 'New file types registered.'
|
30
|
+
exit
|
29
31
|
end
|
30
32
|
end
|
data/lib/imagebackup.rb
CHANGED
@@ -1,62 +1,77 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
2
3
|
require_relative 'imagebackup/version'
|
3
4
|
|
4
5
|
require_relative 'classes/filetypes'
|
5
6
|
require_relative 'methods/build_paths'
|
6
7
|
require_relative 'methods/get_dates'
|
7
8
|
require_relative 'methods/copy_pic'
|
9
|
+
require_relative 'methods/display_help'
|
8
10
|
|
11
|
+
require 'colorize'
|
9
12
|
require 'exiv2'
|
10
13
|
require 'fileutils'
|
11
14
|
require 'ffprober'
|
12
|
-
require '
|
13
|
-
require 'getoptlong'
|
15
|
+
require 'csv'
|
14
16
|
|
15
|
-
def main_loop(dest,dryrun=true)
|
17
|
+
def main_loop(dest, dryrun = true, file_op = 'copy')
|
16
18
|
file_types = FileTypes.list
|
17
19
|
Dir.glob(file_types).reverse_each do |f|
|
18
|
-
|
19
20
|
file = "#{Dir.pwd}/#{f}"
|
20
21
|
|
21
|
-
parms = build_paths(dest,file,get_dates(file))
|
22
|
+
parms = build_paths(dest, file, get_dates(file))
|
22
23
|
outfile = parms[0]
|
23
24
|
destpath = parms[1]
|
24
25
|
|
25
|
-
|
26
|
-
puts "\"#{outfile}\" already exists."
|
27
|
-
else
|
28
|
-
copy_pic(file,outfile,destpath,dryrun)
|
29
|
-
end
|
26
|
+
copy_pic(file, outfile, destpath, dryrun, file_op)
|
30
27
|
end
|
28
|
+
puts "\nFinished!\n".colorize(:light_green)
|
31
29
|
end
|
32
30
|
|
33
|
-
# main_loop(ARGV[0])
|
34
|
-
|
35
31
|
dryrun = true
|
32
|
+
file_op = 'cp' # or "mv" or "ln_s"
|
36
33
|
|
37
|
-
if (ARGV & ['-
|
38
|
-
|
39
|
-
ARGV.delete('-
|
40
|
-
ARGV.delete('--
|
41
|
-
else
|
42
|
-
# FIXME: THIS IS REVERSED TO ALWAYS BE TRUE WHILE I'M TESTING. CHANGE BELOW TO false BEFORE DEPLOYMENT
|
43
|
-
dryrun = true
|
44
|
-
puts "dry run is disabled! i'm really going to mess with your files!"
|
34
|
+
if (ARGV & ['-m', '--move']).any?
|
35
|
+
file_op = 'mv'
|
36
|
+
ARGV.delete('-m')
|
37
|
+
ARGV.delete('--move')
|
45
38
|
end
|
46
|
-
if ARGV
|
47
|
-
|
48
|
-
|
49
|
-
ARGV.
|
39
|
+
if (ARGV & ['-l', '--link']).any?
|
40
|
+
file_op = 'ln_s'
|
41
|
+
ARGV.delete('-l')
|
42
|
+
ARGV.delete('--link')
|
43
|
+
end
|
44
|
+
if ARGV.include?('-a')
|
45
|
+
ext = ARGV[ARGV.index('-a') + 1]
|
46
|
+
type = ARGV[ARGV.index('-a') + 2]
|
47
|
+
ARGV.slice!(ARGV.index('-a')..ARGV.index('-a') + 2)
|
48
|
+
FileTypes.add(ext, type)
|
50
49
|
end
|
51
50
|
if ARGV.include?('--add-filetype')
|
52
|
-
ext=ARGV[ARGV.index('--add-filetype')+1]
|
53
|
-
type=ARGV[ARGV.index('--add-filetype')+2]
|
54
|
-
ARGV.slice!(ARGV.index('--add-filetype')..ARGV.index('--add-filetype')+2)
|
51
|
+
ext = ARGV[ARGV.index('--add-filetype') + 1]
|
52
|
+
type = ARGV[ARGV.index('--add-filetype') + 2]
|
53
|
+
ARGV.slice!(ARGV.index('--add-filetype')..ARGV.index('--add-filetype') + 2)
|
54
|
+
FileTypes.add(ext, type)
|
55
55
|
end
|
56
|
-
if
|
57
|
-
|
56
|
+
if (ARGV & ['-n', '--dry-run']).any?
|
57
|
+
dryrun = true
|
58
|
+
puts 'Doing a dry run - no operations will happen.'.colorize(:light_magenta)
|
59
|
+
sleep 1
|
60
|
+
ARGV.delete('-n')
|
61
|
+
ARGV.delete('--dry-run')
|
62
|
+
else
|
63
|
+
dryrun = false
|
58
64
|
end
|
59
65
|
|
60
|
-
if ARGV
|
61
|
-
|
62
|
-
|
66
|
+
display_help("Exited normally",:light_green) if (ARGV & ['-h', '--help', '-?']).any?
|
67
|
+
|
68
|
+
if ARGV[0].to_s == ''
|
69
|
+
display_help
|
70
|
+
elsif File.exist?(ARGV[0])
|
71
|
+
main_loop(ARGV[0], dryrun, file_op)
|
72
|
+
elsif ARGV[0][0] == '-'
|
73
|
+
puts "Invalid option!\n-----\n\n"
|
74
|
+
display_help("\n-----\nInvalid option: \"#{ARGV[0]}\"!\n\n",:red)
|
75
|
+
else
|
76
|
+
puts 'Specified destination does not exist. Please create this folder first.'
|
77
|
+
end
|
data/lib/imagebackup/version.rb
CHANGED
data/lib/methods/build_paths.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def build_paths(dest, file, date)
|
2
4
|
date = get_dates(file)
|
3
5
|
destpath = "#{dest}/#{date}"
|
4
|
-
destpath = destpath.gsub('//','/')
|
6
|
+
destpath = destpath.gsub('//', '/')
|
5
7
|
outfile = "#{destpath}/#{File.basename(file)}"
|
6
|
-
|
7
|
-
end
|
8
|
+
[outfile, destpath]
|
9
|
+
end
|
data/lib/methods/copy_pic.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
|
-
def
|
1
|
+
def process_file(file, outfile, dryrun = nil, file_op = 'cp')
|
2
2
|
if dryrun
|
3
|
-
puts "pretending to
|
4
|
-
puts "FileUtils.mkdir_p(#{destpath})"
|
5
|
-
puts "FileUtils.cp(#{file},#{outfile})"
|
3
|
+
puts "#{"pretending to ".colorize(:light_green)}#{file_op} \"#{file}\"#{" to ".colorize(:light_green)}\"#{outfile}\""
|
6
4
|
else
|
7
|
-
puts "
|
8
|
-
FileUtils.
|
9
|
-
|
5
|
+
puts "#{file_op}-ing \"#{file} to #{outfile}\"..."
|
6
|
+
FileUtils.public_send(file_op, file, outfile)
|
7
|
+
if File.exist?("#{file}.xmp")
|
8
|
+
FileUtils.public_send(file_op, "#{file}.xmp", "#{outfile}.xmp")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_pic(file, outfile, destpath, dryrun = nil, file_op = 'cp')
|
14
|
+
if File.exist?(outfile)
|
15
|
+
puts "\"#{outfile}\" #{"already exists. Skipping...".colorize(:light_blue)}."
|
16
|
+
else
|
17
|
+
unless dryrun
|
18
|
+
unless File.exist?(destpath)
|
19
|
+
puts "creating folder \"#{destpath}\""
|
20
|
+
FileUtils.mkdir_p(destpath)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
process_file(file, outfile, dryrun, file_op)
|
10
24
|
end
|
11
25
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
def display_help(err=nil,color=nil)
|
2
|
+
print <<~HELPFILE
|
3
|
+
===== ImageBackup =====
|
4
|
+
|
5
|
+
Keep your photos and videos organized by date.
|
6
|
+
|
7
|
+
A simple terminal app to crawl a folder (usually a camera card's DCIM folder) for pictures and videos, and pop them in dated folders to your destination folder of choice. Uses exif data when available, creation_time, or the file's own creation date if nothing better is present.
|
8
|
+
|
9
|
+
Will also copy over any xmp sidecar files found, not overwriting.
|
10
|
+
|
11
|
+
Options:
|
12
|
+
|
13
|
+
-n, --dry-run Run without actually doing anything. Good for making sure
|
14
|
+
things are working properly. This will also give you console
|
15
|
+
output which helps identify unreadable files.
|
16
|
+
|
17
|
+
-a, --add-filetype <extension> <type> This will add a custom file type to the list of files it's
|
18
|
+
looking for. If you have an arcane digital camera (we
|
19
|
+
currently support canon, sony, pentax but new stuff comes out
|
20
|
+
all the time), this will allow you to add your raw files.
|
21
|
+
You can also access *filetypes.csv* and add them manually,
|
22
|
+
but ensure there's a blank line at the end or this program
|
23
|
+
may behave badly.
|
24
|
+
|
25
|
+
-m, --move Will move (deleting the original), which is probably not a
|
26
|
+
good idea in most cases but still useful at times.
|
27
|
+
-l, --link Create symbolic links instead of copying or moving
|
28
|
+
actual files. Useful for large videos.
|
29
|
+
|
30
|
+
Usage:
|
31
|
+
|
32
|
+
- To backup a camera card:
|
33
|
+
|
34
|
+
$ cd /media/username/EOS_DIGITAL/DCIM
|
35
|
+
$ imagebackup.rb ~/Photos/raw
|
36
|
+
|
37
|
+
This will search all files within the DCIM folder, check them with either exiv2 (for stills) or ffprobe (for videos) and retrieve their creation dates.
|
38
|
+
It will then copy them to a folder of the form ~/Photos/raw/<yyyy>-<mm>-<dd>
|
39
|
+
If it's unable to find metadata in a file it will look at the file's creation time attribute, which is less reliable but usually ok.
|
40
|
+
|
41
|
+
- To register a new file type:
|
42
|
+
|
43
|
+
$ imagebackup.rb --add-filetype orf pic
|
44
|
+
or
|
45
|
+
$ imagebackup.rb -a orf pic
|
46
|
+
|
47
|
+
This will work with *.ORF, orf, ".orf" as it will strip off any unnecessary characters. It is case-insensitive.
|
48
|
+
|
49
|
+
- To do a dry run, checking each file and destination but not actually copying:
|
50
|
+
|
51
|
+
$ imagebackup.rb -n ~/Photos/raw
|
52
|
+
or
|
53
|
+
$ imagebackup.rb ~/Photos/raw --dry-run
|
54
|
+
|
55
|
+
- To move files instead of copying them (careful!):
|
56
|
+
|
57
|
+
$ imagebackup.rb -m ~/Photos/raw
|
58
|
+
or
|
59
|
+
$ imagebackup.rb --move ~/Photos/raw
|
60
|
+
|
61
|
+
- To make symbolic links instead of copying files:
|
62
|
+
|
63
|
+
$ imagebackup.rb -l ~/Photos/raw
|
64
|
+
or
|
65
|
+
$ imagebackup.rb --link ~/Photos/raw
|
66
|
+
|
67
|
+
This mode can be useful if you want to operate on the files in one place but keep them on their media. Particularly useful for large movie files.
|
68
|
+
HELPFILE
|
69
|
+
puts err.to_s.colorize(color)
|
70
|
+
exit(0)
|
71
|
+
end
|
data/lib/methods/get_dates.rb
CHANGED
@@ -3,15 +3,15 @@ def get_dates(file)
|
|
3
3
|
image = Exiv2::ImageFactory.open(file)
|
4
4
|
image.read_metadata
|
5
5
|
date = image.exif_data.find { |v| v[0] == 'Exif.Image.DateTime' }
|
6
|
-
date = date[1].split[0].gsub(':','-')
|
7
|
-
rescue
|
6
|
+
date = date[1].split[0].gsub(':', '-')
|
7
|
+
rescue StandardError
|
8
8
|
begin
|
9
9
|
probe = Ffprober::Parser.from_file(file)
|
10
|
-
date = probe.format.tags[:creation_time].split(
|
11
|
-
rescue
|
10
|
+
date = probe.format.tags[:creation_time].split(/[T ]/)[0]
|
11
|
+
rescue StandardError
|
12
12
|
fileobj = File.new(file)
|
13
|
-
date = "#{fileobj.stat.ctime.year}-#{fileobj.stat.ctime.month}-#{fileobj.stat.ctime.day}"
|
13
|
+
date = "#{"%04d" % fileobj.stat.ctime.year}-#{"%02d" % fileobj.stat.ctime.month}-#{"%02d" % fileobj.stat.ctime.day}"
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
17
|
-
end
|
16
|
+
date
|
17
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imagebackup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- adrian-sal-kennedy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: exiv2
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,7 +75,11 @@ files:
|
|
61
75
|
- lib/imagebackup/version.rb
|
62
76
|
- lib/methods/build_paths.rb
|
63
77
|
- lib/methods/copy_pic.rb
|
78
|
+
- lib/methods/display_help.rb
|
64
79
|
- lib/methods/get_dates.rb
|
80
|
+
- tests/bad_exif/DSC03688.JPG
|
81
|
+
- tests/corrupt/test.cr2
|
82
|
+
- tests/truncated/IMG_9372.CR2
|
65
83
|
homepage: https://github.com/adrian-sal-kennedy/imagebackup
|
66
84
|
licenses:
|
67
85
|
- MIT
|