vera 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +27 -1
- data/bin/vera +13 -1
- data/gif/renamer.gif +0 -0
- data/lib/vera.rb +1 -0
- data/lib/vera/exiftool.rb +4 -0
- data/lib/vera/renamer.rb +40 -0
- data/lib/vera/version.rb +1 -1
- data/spec/vera_spec.rb +30 -0
- data/vera-0.1.1.gem +0 -0
- metadata +4 -2
- data/vera-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 390655a8e0f68a6d79a054e7ded01e274d92336f9e47811f627a409fe2b4308e
|
4
|
+
data.tar.gz: 7d6b771345a524614f3396dbbc363f8fb305a34df36b20bbae946d487ffe3d2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8afcf42416bfc5c37662028d6e88ed842311aea724632338122b16dfc070947133c8ec990055ca6dc5dd57f2646fea70b154fd4dc7c3fb4e933a84f0efa7710
|
7
|
+
data.tar.gz: e8900f74ce81a63a6e6ed050c3c6b31226b467357d74c6127903afb7067f7e81ac2b201b507f0f7644654d9716dd141d92331be483336366b0e1d6e793489710
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,11 +26,37 @@ Once you have it installed you can use any of the following commands.
|
|
26
26
|
This command fixes the created date and the modified date of the media files. Run the following command in the folder where you have your photos and videos:
|
27
27
|
|
28
28
|
```bash
|
29
|
-
vera timestamp
|
29
|
+
vera timestamp --path ~/path/example
|
30
30
|
```
|
31
31
|
|
32
|
+
#### Options
|
33
|
+
|
34
|
+
| Parameter | Default Value | Descripción |
|
35
|
+
| ------------- | ----------------- | ------------------------------------------------------ |
|
36
|
+
| path (--path) | Current directory | Path where the command will be applied. Non-recursive. |
|
37
|
+
|
32
38
|
This command works on JPG, MOV, HEIC and ARW files.
|
33
39
|
|
40
|
+
### Rename
|
41
|
+
|
42
|
+
Prepends the creation date to the filename. This is useful to prevent having duplicate names in your files, as most cameras have a limited naming convention like IMG_0000.JPG to IMG_9999.JPG. As a result of this this command you will have file names like 2020-02-02-IMG_0000.JPG, which makes having duplicated file names almost impossible.
|
43
|
+
|
44
|
+
```bash
|
45
|
+
vera rename --path ~/path/example
|
46
|
+
```
|
47
|
+
|
48
|
+
#### Options
|
49
|
+
|
50
|
+
| Parameter | Default Value | Descripción |
|
51
|
+
| ------------- | ----------------- | ------------------------------------------------------ |
|
52
|
+
| path (--path) | Current directory | Path where the command will be applied. Non-recursive. |
|
53
|
+
|
54
|
+
This command works on JPG, MOV, HEIC and ARW files.
|
55
|
+
|
56
|
+
#### Example
|
57
|
+
|
58
|
+
![vera rename](gif/renamer.gif)
|
59
|
+
|
34
60
|
If you want to add more commands, feel free to contribute with a PR to Vera. In the next section I explain how to start working on it.
|
35
61
|
|
36
62
|
## Developement
|
data/bin/vera
CHANGED
@@ -11,11 +11,23 @@ program :version, Vera::VERSION
|
|
11
11
|
program :description, 'Organize media files'
|
12
12
|
|
13
13
|
command :timestamp do |c|
|
14
|
-
c.syntax = 'vera
|
14
|
+
c.syntax = 'vera timestamp [options]'
|
15
15
|
c.summary = 'Fix the timestamp of current folder\'s media'
|
16
16
|
c.description = 'Uses picture/movie creation date to change the created and modified date of the media file'
|
17
17
|
c.example 'description', 'vera timestamp'
|
18
|
+
c.option '--path PATH', 'Where to execute the command. Default value is the current directory.'
|
18
19
|
c.action do |_args, options|
|
19
20
|
Vera::Timestamp.execute(options)
|
20
21
|
end
|
21
22
|
end
|
23
|
+
|
24
|
+
command :rename do |c|
|
25
|
+
c.syntax = 'vera rename [options]'
|
26
|
+
c.summary = 'Rename files to include the date at the beggining of the file'
|
27
|
+
c.description = 'Converts IMG_2200.JPG to 2020-02-02-IMG_2200.JPG for all the media files in a folder.'
|
28
|
+
c.example 'description', 'vera rename PATH'
|
29
|
+
c.option '--path PATH', 'Where to execute the command. Default value is the current directory.'
|
30
|
+
c.action do |args, options|
|
31
|
+
Vera::Renamer::execute(options)
|
32
|
+
end
|
33
|
+
end
|
data/gif/renamer.gif
ADDED
Binary file
|
data/lib/vera.rb
CHANGED
data/lib/vera/exiftool.rb
CHANGED
@@ -9,5 +9,9 @@ module Vera
|
|
9
9
|
def self.is_installed?
|
10
10
|
system("which exiftool >/dev/null")
|
11
11
|
end
|
12
|
+
|
13
|
+
def self.change_filename_with_date(date_property, files_string)
|
14
|
+
system("exiftool '-FileName<$#{date_property}-$filename' -d \"%Y-%m-%d\" #{ files_string } 2>/dev/null")
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
data/lib/vera/renamer.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Vera
|
2
|
+
class Renamer
|
3
|
+
def self.execute(options)
|
4
|
+
unless Exiftool.is_installed?
|
5
|
+
puts """
|
6
|
+
You need to install exiftool to use vera. You can run the following command to do it:
|
7
|
+
bash <(curl -Ls https://git.io/JtbuH)
|
8
|
+
"""
|
9
|
+
return
|
10
|
+
end
|
11
|
+
path = options.path
|
12
|
+
path = Dir.pwd if options.path.nil?
|
13
|
+
path = File.expand_path(path)
|
14
|
+
rename path
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.rename path
|
18
|
+
rename_files_with_date path, "ARW", "DateTimeOriginal"
|
19
|
+
rename_files_with_date path, "JPG", "DateTimeOriginal"
|
20
|
+
rename_files_with_date path, "HEIC", "DateTimeOriginal"
|
21
|
+
rename_files_with_date path, "MOV", "CreationDate"
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.rename_files_with_date path, ext, date_property
|
25
|
+
puts "✅ Adding creation date to #{ext} files in the filename"
|
26
|
+
files = Lister.all_files(path, ext)
|
27
|
+
files = Renamer.exclude_already_renamed_files(files)
|
28
|
+
if files.empty?
|
29
|
+
puts "No files to rename for #{ext} file type."
|
30
|
+
return
|
31
|
+
end
|
32
|
+
files_string = files.map { |f| "\"#{f[:path]}\"" }.join(" ")
|
33
|
+
puts "❌Something went wrong" unless Exiftool.change_filename_with_date(date_property, files_string)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.exclude_already_renamed_files files
|
37
|
+
files.select { |f| f[:filename].match(/\d+\-\d+\-\d+\-/) == nil }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/vera/version.rb
CHANGED
data/spec/vera_spec.rb
CHANGED
@@ -31,3 +31,33 @@ RSpec.describe Vera::Timestamp do
|
|
31
31
|
Vera::Timestamp.execute(options)
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
RSpec.describe Vera::Renamer do
|
36
|
+
it 'skips files that are already renamed' do
|
37
|
+
files = [
|
38
|
+
{ filename: '2020-01-02-some.jpg', path: 'example/2020-01-02-some.jpg' },
|
39
|
+
{ filename: 'other.jpg', path: 'example/other.jpg' }
|
40
|
+
]
|
41
|
+
filtered_files = Vera::Renamer.exclude_already_renamed_files files
|
42
|
+
expect(filtered_files).to eq [
|
43
|
+
{ filename: 'other.jpg', path: 'example/other.jpg' }
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'renames files adding the date' do
|
48
|
+
expect(Vera::Lister).to receive(:all_files)
|
49
|
+
.exactly(4).times
|
50
|
+
.with(anything, anything) {
|
51
|
+
[
|
52
|
+
{ filename: 'some.jpg', path: 'example/some.jpg' },
|
53
|
+
{ filename: 'other.jpg', path: 'example/other.jpg' }
|
54
|
+
]
|
55
|
+
}
|
56
|
+
files = '"example/some.jpg" "example/other.jpg"'
|
57
|
+
expect(Vera::Exiftool).to receive(:change_filename_with_date)
|
58
|
+
.exactly(4).times
|
59
|
+
.with(anything, files)
|
60
|
+
options = OpenStruct.new({ path: 'example' })
|
61
|
+
Vera::Renamer.execute(options)
|
62
|
+
end
|
63
|
+
end
|
data/vera-0.1.1.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cortés
|
@@ -80,13 +80,15 @@ files:
|
|
80
80
|
- "./LICENSE.txt"
|
81
81
|
- "./README.md"
|
82
82
|
- "./Rakefile"
|
83
|
+
- "./gif/renamer.gif"
|
83
84
|
- "./install.sh"
|
84
85
|
- "./lib/vera.rb"
|
85
86
|
- "./lib/vera/exiftool.rb"
|
86
87
|
- "./lib/vera/lister.rb"
|
88
|
+
- "./lib/vera/renamer.rb"
|
87
89
|
- "./lib/vera/timestamp.rb"
|
88
90
|
- "./lib/vera/version.rb"
|
89
|
-
- "./vera-0.1.
|
91
|
+
- "./vera-0.1.1.gem"
|
90
92
|
- "./vera.gemspec"
|
91
93
|
- "./vera.jpg"
|
92
94
|
- bin/vera
|
data/vera-0.1.0.gem
DELETED
Binary file
|