media_archiver 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/media_archiver/cli.rb +17 -8
- data/lib/media_archiver/media_file.rb +5 -19
- data/lib/media_archiver/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b989a4e5cda660b386280c064560963b9a42603
|
4
|
+
data.tar.gz: 58e679df4a7651ea2e6d936b2d1f5ddcb6bddc0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10d96ee3da9d9ab082108584e894db5e3da27a6a5f5892daf80aff85e4525463ed44e46f318746fd4a8e5bc44f4287de808f8f6a9e3be6380b11b80918162c2a
|
7
|
+
data.tar.gz: fc8cb9ca9da4d1c99c7dde978aa7f53ada35ec32a2d88fad9dd681d9a95c65485759a13babe6e49e0b3aa439042710189afa28c31eddf5fe2cfe0ebf8200c1ca
|
data/lib/media_archiver/cli.rb
CHANGED
@@ -4,10 +4,12 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
module MediaArchiver
|
6
6
|
class CLI < Thor
|
7
|
+
DEFAULT_OUTPUT_TEMPLATE = ':DateTimeOriginal/:Make/:Model'
|
8
|
+
|
7
9
|
desc 'copy [DIR] [OUTPUT_DIR]', 'Scans a folder and archives media files'
|
8
10
|
option :output_dir, aliases: :o
|
9
11
|
option :recursive, aliases: :r, type: :boolean, default: true
|
10
|
-
option :output_template
|
12
|
+
option :output_template
|
11
13
|
option :configuration_file, aliases: :c
|
12
14
|
def copy(path = Dir.pwd)
|
13
15
|
config = configurations(options)
|
@@ -33,21 +35,25 @@ module MediaArchiver
|
|
33
35
|
private
|
34
36
|
|
35
37
|
def configurations(options)
|
36
|
-
|
37
|
-
|
38
|
+
conf = system_configurations.merge symbolize_keys!(options)
|
39
|
+
|
40
|
+
# Defaults that we don't want to set via Thor
|
41
|
+
conf[:output_template] = DEFAULT_OUTPUT_TEMPLATE unless conf[:output_template]
|
42
|
+
|
43
|
+
conf
|
38
44
|
end
|
39
45
|
|
40
46
|
def system_configurations
|
41
|
-
|
47
|
+
config_file = [
|
42
48
|
File.expand_path(Dir.pwd),
|
43
49
|
Dir.home
|
44
50
|
].map { |path| File.join(path, '.media_archiver_conf.yml') }
|
45
51
|
.keep_if { |f| File.file? f }
|
46
52
|
.first
|
47
53
|
|
48
|
-
return {} unless
|
54
|
+
return {} unless config_file
|
49
55
|
|
50
|
-
load_config_file
|
56
|
+
load_config_file config_file
|
51
57
|
end
|
52
58
|
|
53
59
|
def load_config_file(path)
|
@@ -58,7 +64,10 @@ module MediaArchiver
|
|
58
64
|
output = [output_path]
|
59
65
|
|
60
66
|
output += output_template_parts(template).map do |key|
|
61
|
-
|
67
|
+
value = file.exif_tags[key.to_s.downcase]
|
68
|
+
value = value.to_date.to_s if value.is_a?(Time)
|
69
|
+
|
70
|
+
value
|
62
71
|
end
|
63
72
|
output << file.file_name
|
64
73
|
|
@@ -76,7 +85,7 @@ module MediaArchiver
|
|
76
85
|
end
|
77
86
|
|
78
87
|
def symbolize_keys!(hash)
|
79
|
-
hash.each_with_object({}) { |(k,v),acc| acc[k.to_sym] = v }
|
88
|
+
hash.each_with_object({}) { |(k, v), acc| acc[k.to_sym] = v }
|
80
89
|
end
|
81
90
|
end
|
82
91
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module MediaArchiver
|
2
2
|
class MediaFile
|
3
|
-
attr_reader :path, :file_name
|
3
|
+
attr_reader :path, :file_name, :exif_tags
|
4
4
|
|
5
5
|
def initialize(file_path)
|
6
6
|
@path = file_path
|
@@ -8,30 +8,16 @@ module MediaArchiver
|
|
8
8
|
|
9
9
|
begin
|
10
10
|
@file = MiniExiftool.new(file_path)
|
11
|
-
@
|
11
|
+
@exif_tags = @file.to_hash.each_with_object({}) do |(k, v), acc|
|
12
|
+
acc[k.downcase] = v if k
|
13
|
+
end
|
12
14
|
rescue MiniExiftool::Error
|
13
15
|
nil
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def valid?
|
18
|
-
@file
|
19
|
-
end
|
20
|
-
|
21
|
-
def exif_tags
|
22
|
-
@info
|
23
|
-
end
|
24
|
-
|
25
|
-
def date_created
|
26
|
-
exif_tags['DateTimeOriginal'].to_date.to_s if exif_tags['DateTimeOriginal']
|
27
|
-
end
|
28
|
-
|
29
|
-
def camera_maker
|
30
|
-
exif_tags['Make']
|
31
|
-
end
|
32
|
-
|
33
|
-
def camera_model
|
34
|
-
exif_tags['Model']
|
20
|
+
@file && @exif_tags
|
35
21
|
end
|
36
22
|
end
|
37
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: media_archiver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Ramalho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|