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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62eeb44c05bb40fd6c54cb66d830cd5282228ac8
4
- data.tar.gz: 5c3c96acf6341444071a901fd0c576ed28b7e163
3
+ metadata.gz: 7b989a4e5cda660b386280c064560963b9a42603
4
+ data.tar.gz: 58e679df4a7651ea2e6d936b2d1f5ddcb6bddc0e
5
5
  SHA512:
6
- metadata.gz: a921bd3cd1e73e23a32cdc08dd6ce65c19eac0bcbb5aee7c57f961a43d2ab17fb722032b672f6bc6d5a4daa8128763bd30b62eb48a7384474051c3ac46d476b3
7
- data.tar.gz: 53665d79d0797b7d68e1b1fd8fc4f1554f8f14da21e34ecb396bcdb228d7d23af1309c2bdd2ea4c62ad522ad3dd6f56b3041fd85112039a4f48f9d5d2462b8b2
6
+ metadata.gz: 10d96ee3da9d9ab082108584e894db5e3da27a6a5f5892daf80aff85e4525463ed44e46f318746fd4a8e5bc44f4287de808f8f6a9e3be6380b11b80918162c2a
7
+ data.tar.gz: fc8cb9ca9da4d1c99c7dde978aa7f53ada35ec32a2d88fad9dd681d9a95c65485759a13babe6e49e0b3aa439042710189afa28c31eddf5fe2cfe0ebf8200c1ca
@@ -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, default: ':date_created/:camera_maker/:camera_model'
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
- options = symbolize_keys!(options)
37
- system_configurations.merge(options)
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
- path = [
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 path
54
+ return {} unless config_file
49
55
 
50
- load_config_file path
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
- file.respond_to?(key) ? file.send(key) : file.exif_tags[key.to_s]
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
- @info = @file.to_hash
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
@@ -1,3 +1,3 @@
1
1
  module MediaArchiver
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  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.3
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-06 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler