imagebackup 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -16
- data/lib/classes/filetypes.csv +4 -2
- data/lib/imagebackup.rb +40 -19
- data/lib/imagebackup/version.rb +1 -1
- data/lib/methods/copy_pic.rb +25 -7
- data/lib/methods/display_help.rb +82 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc81529419a0623c0598dabfbba9e4b5806b62a9dfa8ccd3eb9310912157b11b
|
4
|
+
data.tar.gz: 650bfa77a3adfadc530c9466261f077b901f9b00e693180dd00d93978586ddfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad5fe5bf394bb6282b772683aac8c66a18ff9b4fb58ea67bfaed17f0a19ff844ff6f77afa72cd1c0e5bfa8c463ca0d9de317f1c43e8b88089c918a1f9ac148ef
|
7
|
+
data.tar.gz: b1fb8c3bf729427c2de5f34a79bb924ec465679f1b85b68d0acecf0b8fb9282468777bcaa0ca93f2e988cf479f5c8dc649bf66006a7becc973de24ffb619ca55
|
data/README.md
CHANGED
@@ -2,34 +2,83 @@
|
|
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
|
|
7
8
|
|
8
|
-
##
|
9
|
-
|
10
|
-
|
11
|
-
- exiv2
|
12
|
-
- ffprober
|
9
|
+
## Options:
|
10
|
+
-n, --dry-run
|
11
|
+
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.
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
-a, --add-filetype *extension* *type*
|
14
|
+
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.
|
15
|
+
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.
|
17
16
|
|
18
|
-
|
19
|
-
```bash
|
20
|
-
$ gem install exiv2 ffprober
|
21
|
-
```
|
17
|
+
-m will move (deleting the original), which is probably not a good idea in most cases but still useful at times.
|
22
18
|
|
23
19
|
## Usage:
|
24
20
|
|
21
|
+
### To backup a camera card:
|
22
|
+
|
25
23
|
```bash
|
26
24
|
$ cd /media/username/EOS_DIGITAL/DCIM
|
27
|
-
$ imagebackup ~/Photos/raw
|
25
|
+
$ imagebackup.rb ~/Photos/raw
|
28
26
|
```
|
27
|
+
|
29
28
|
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
29
|
It will then copy them to a folder of the form ```~/Photos/raw/<yyyy>-<mm>-<dd>```
|
31
30
|
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
31
|
|
32
|
+
### To register a new file type:
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
```bash
|
35
|
+
$ imagebackup.rb --add-filetype orf pic
|
36
|
+
```
|
37
|
+
or
|
38
|
+
```bash
|
39
|
+
$ imagebackup.rb -a orf pic
|
40
|
+
```
|
41
|
+
This will work with ```*.ORF```, ```orf```, ```".orf"``` as it will strip off any unnecessary characters. It is case-insensitive.
|
42
|
+
|
43
|
+
### To do a dry run, checking each file and destination but not actually copying:
|
44
|
+
|
45
|
+
```bash
|
46
|
+
$ imagebackup.rb -n ~/Photos/raw
|
47
|
+
```
|
48
|
+
or
|
49
|
+
```bash
|
50
|
+
$ imagebackup.rb ~/Photos/raw --dry-run
|
51
|
+
```
|
52
|
+
|
53
|
+
### To move files instead of copying them (careful!):
|
54
|
+
```bash
|
55
|
+
$ imagebackup.rb -m ~/Photos/raw
|
56
|
+
```
|
57
|
+
or
|
58
|
+
```bash
|
59
|
+
$ imagebackup.rb --move ~/Photos/raw
|
60
|
+
```
|
61
|
+
|
62
|
+
### To make symbolic links instead of copying files:
|
63
|
+
```bash
|
64
|
+
$ imagebackup.rb -l ~/Photos/raw
|
65
|
+
```
|
66
|
+
or
|
67
|
+
```bash
|
68
|
+
$ imagebackup.rb --link ~/Photos/raw
|
69
|
+
```
|
70
|
+
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.
|
71
|
+
|
72
|
+
## Dependencies:
|
73
|
+
|
74
|
+
**Ruby** v2.3.0 or greater, plus gems:
|
75
|
+
- exiv2
|
76
|
+
- ffprober
|
77
|
+
|
78
|
+
Ruby modules:
|
79
|
+
- fileutils.rb
|
80
|
+
|
81
|
+
Bundler should handle all these dependencies. If for some reason it doesn't you can run this in terminal:
|
82
|
+
```bash
|
83
|
+
$ gem install exiv2 ffprober
|
84
|
+
```
|
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/imagebackup.rb
CHANGED
@@ -5,14 +5,13 @@ require_relative 'classes/filetypes'
|
|
5
5
|
require_relative 'methods/build_paths'
|
6
6
|
require_relative 'methods/get_dates'
|
7
7
|
require_relative 'methods/copy_pic'
|
8
|
+
require_relative 'methods/display_help'
|
8
9
|
|
9
10
|
require 'exiv2'
|
10
11
|
require 'fileutils'
|
11
12
|
require 'ffprober'
|
12
|
-
require 'json'
|
13
|
-
require 'getoptlong'
|
14
13
|
|
15
|
-
def main_loop(dest,dryrun=true)
|
14
|
+
def main_loop(dest,dryrun=true,file_op="copy")#,move=nil,link=nil)
|
16
15
|
file_types = FileTypes.list
|
17
16
|
Dir.glob(file_types).reverse_each do |f|
|
18
17
|
|
@@ -22,28 +21,31 @@ def main_loop(dest,dryrun=true)
|
|
22
21
|
outfile = parms[0]
|
23
22
|
destpath = parms[1]
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
else
|
28
|
-
copy_pic(file,outfile,destpath,dryrun)
|
29
|
-
end
|
24
|
+
copy_pic(file,outfile,destpath,dryrun,file_op)#,move,link)
|
25
|
+
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
33
29
|
# main_loop(ARGV[0])
|
34
30
|
|
35
31
|
dryrun = true
|
32
|
+
# link = false
|
33
|
+
# move = false
|
34
|
+
file_op = "cp" # or "mv" or "ln_s"
|
36
35
|
|
37
|
-
if (ARGV & ['-
|
38
|
-
|
39
|
-
|
40
|
-
ARGV.delete('
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
if (ARGV & ['-m','--move']).any?
|
37
|
+
# move = true
|
38
|
+
file_op = "mv"
|
39
|
+
ARGV.delete('-m')
|
40
|
+
ARGV.delete('--move')
|
41
|
+
end
|
42
|
+
if (ARGV & ['-l','--link']).any?
|
43
|
+
# link = true
|
44
|
+
file_op = "ln_s"
|
45
|
+
ARGV.delete('-l')
|
46
|
+
ARGV.delete('--link')
|
45
47
|
end
|
46
|
-
if ARGV.include?('-a')
|
48
|
+
if ARGV.include?('-a')
|
47
49
|
ext=ARGV[ARGV.index('-a')+1]
|
48
50
|
type=ARGV[ARGV.index('-a')+2]
|
49
51
|
ARGV.slice!(ARGV.index('-a')..ARGV.index('-a')+2)
|
@@ -56,7 +58,26 @@ end
|
|
56
58
|
if ext
|
57
59
|
FileTypes.add(ext,type)
|
58
60
|
end
|
61
|
+
if (ARGV & ['-n','--dry-run']).any?
|
62
|
+
dryrun = true
|
63
|
+
puts "Doing a dry run - no operations will happen."
|
64
|
+
sleep 1
|
65
|
+
ARGV.delete('-n')
|
66
|
+
ARGV.delete('--dry-run')
|
67
|
+
else
|
68
|
+
dryrun = false
|
69
|
+
end
|
59
70
|
|
60
|
-
if ARGV
|
61
|
-
|
71
|
+
if (ARGV & ['-h','--help','-?']).any?
|
72
|
+
display_help()
|
73
|
+
end
|
74
|
+
|
75
|
+
if ARGV[0].to_s == ''
|
76
|
+
display_help()
|
77
|
+
else
|
78
|
+
if File.exist?(ARGV[0])
|
79
|
+
main_loop(ARGV[0],dryrun,file_op)
|
80
|
+
else
|
81
|
+
puts "Specified destination does not exist. Please create this folder first."
|
82
|
+
end
|
62
83
|
end
|
data/lib/imagebackup/version.rb
CHANGED
data/lib/methods/copy_pic.rb
CHANGED
@@ -1,11 +1,29 @@
|
|
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 #{file_op} \"#{file} to #{outfile}\""
|
6
4
|
else
|
7
|
-
puts "
|
8
|
-
FileUtils.
|
9
|
-
FileUtils.
|
5
|
+
puts "#{file_op}-ing \"#{file} to #{outfile}\"..."
|
6
|
+
FileUtils.public_send(file_op,file,outfile)
|
7
|
+
FileUtils.public_send(file_op,"#{file}.xmp",outfile,:force => true)
|
8
|
+
if file_op == "cp"
|
9
|
+
FileUtils.public_send(file_op,"#{file}.xmp",outfile)
|
10
|
+
else
|
11
|
+
FileUtils.public_send(file_op,"#{file}.xmp",outfile,:force => true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy_pic(file,outfile,destpath,dryrun=nil,file_op="cp") #,move=nil,link=nil)
|
17
|
+
unless File.exist?(outfile)
|
18
|
+
unless dryrun
|
19
|
+
unless File.exist?(destpath)
|
20
|
+
puts "creating folder \"#{destpath}\""
|
21
|
+
FileUtils.mkdir_p(destpath)
|
22
|
+
else
|
23
|
+
end
|
24
|
+
end
|
25
|
+
process_file(file,outfile,dryrun,file_op)
|
26
|
+
else
|
27
|
+
puts "\"#{outfile}\" already exists. Skipping..."
|
10
28
|
end
|
11
29
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
def display_help
|
2
|
+
print <<EOF
|
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 will move (deleting the original), which is probably not a
|
26
|
+
good idea in most cases but still useful at times.
|
27
|
+
|
28
|
+
Usage:
|
29
|
+
|
30
|
+
- To backup a camera card:
|
31
|
+
|
32
|
+
$ cd /media/username/EOS_DIGITAL/DCIM
|
33
|
+
$ imagebackup.rb ~/Photos/raw
|
34
|
+
|
35
|
+
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.
|
36
|
+
It will then copy them to a folder of the form ~/Photos/raw/<yyyy>-<mm>-<dd>
|
37
|
+
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.
|
38
|
+
|
39
|
+
- To register a new file type:
|
40
|
+
|
41
|
+
$ imagebackup.rb --add-filetype orf pic
|
42
|
+
or
|
43
|
+
$ imagebackup.rb -a orf pic
|
44
|
+
|
45
|
+
This will work with *.ORF, orf, ".orf" as it will strip off any unnecessary characters. It is case-insensitive.
|
46
|
+
|
47
|
+
- To do a dry run, checking each file and destination but not actually copying:
|
48
|
+
|
49
|
+
$ imagebackup.rb -n ~/Photos/raw
|
50
|
+
or
|
51
|
+
$ imagebackup.rb ~/Photos/raw --dry-run
|
52
|
+
|
53
|
+
- To move files instead of copying them (careful!):
|
54
|
+
|
55
|
+
$ imagebackup.rb -m ~/Photos/raw
|
56
|
+
or
|
57
|
+
$ imagebackup.rb --move ~/Photos/raw
|
58
|
+
|
59
|
+
- To make symbolic links instead of copying files:
|
60
|
+
|
61
|
+
$ imagebackup.rb -l ~/Photos/raw
|
62
|
+
or
|
63
|
+
$ imagebackup.rb --link ~/Photos/raw
|
64
|
+
|
65
|
+
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.
|
66
|
+
|
67
|
+
Dependencies:
|
68
|
+
|
69
|
+
Ruby v2.3.0 or greater, plus gems:
|
70
|
+
- exiv2
|
71
|
+
- ffprober
|
72
|
+
|
73
|
+
Ruby modules:
|
74
|
+
- fileutils
|
75
|
+
|
76
|
+
Bundler should handle all these dependencies. If for some reason it doesn't you can run this in terminal:
|
77
|
+
$ gem install exiv2 ffprober
|
78
|
+
|
79
|
+
EOF
|
80
|
+
|
81
|
+
exit(0)
|
82
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imagebackup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: exiv2
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/imagebackup/version.rb
|
62
62
|
- lib/methods/build_paths.rb
|
63
63
|
- lib/methods/copy_pic.rb
|
64
|
+
- lib/methods/display_help.rb
|
64
65
|
- lib/methods/get_dates.rb
|
65
66
|
homepage: https://github.com/adrian-sal-kennedy/imagebackup
|
66
67
|
licenses:
|