media_archiver 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +48 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/bin/media_archiver +3 -0
- data/lib/media_archiver/cli.rb +98 -0
- data/lib/media_archiver/media_file.rb +37 -0
- data/lib/media_archiver/media_file_utils.rb +26 -0
- data/lib/media_archiver/version.rb +3 -0
- data/lib/media_archiver.rb +7 -0
- data/media_archiver.gemspec +29 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6e2678c58e445dc29cc0efacce29ab8933db62a4
|
4
|
+
data.tar.gz: 3f14976c863bbb273f36f8dac3c404f582eabd48
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c62247e57518b50435f5b7c6a521d36077674f461479c7ad99cf9d9e6e62d2d28e483bd9f04d7943912b5ddb2d6d00f59284c4e8d0ca2ae2673f78e6141a60eb
|
7
|
+
data.tar.gz: 3320facf61372ed416dcea03522101f02469a9bc7ddeda0f96113cb48c74afd36571f869a38299a34c9998c701fe5b4b8b1d673629c46b05418d1c01f0dde5ff
|
data/.gitignore
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
/.bundle/
|
3
|
+
/.yardoc
|
4
|
+
/Gemfile.lock
|
5
|
+
/_yardoc/
|
6
|
+
/coverage/
|
7
|
+
/doc/
|
8
|
+
/pkg/
|
9
|
+
/spec/reports/
|
10
|
+
/tmp/
|
11
|
+
*.bundle
|
12
|
+
*.so
|
13
|
+
*.o
|
14
|
+
*.a
|
15
|
+
mkmf.log
|
16
|
+
|
17
|
+
*.gem
|
18
|
+
*.rbc
|
19
|
+
/.config
|
20
|
+
/coverage/
|
21
|
+
/InstalledFiles
|
22
|
+
/pkg/
|
23
|
+
/test/tmp/
|
24
|
+
/test/version_tmp/
|
25
|
+
|
26
|
+
## Specific to RubyMotion:
|
27
|
+
.dat*
|
28
|
+
.repl_history
|
29
|
+
build/
|
30
|
+
|
31
|
+
## Documentation cache and generated files:
|
32
|
+
/.yardoc/
|
33
|
+
/_yardoc/
|
34
|
+
/doc/
|
35
|
+
/rdoc/
|
36
|
+
|
37
|
+
## Environment normalisation:
|
38
|
+
/.bundle/
|
39
|
+
/lib/bundler/man/
|
40
|
+
|
41
|
+
# for a library or gem, you might want to ignore these files since the code is
|
42
|
+
# intended to run in multiple environments; otherwise, check them in:
|
43
|
+
# Gemfile.lock
|
44
|
+
# .ruby-version
|
45
|
+
# .ruby-gemset
|
46
|
+
|
47
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
48
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 David Ramalho
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# MediaArchiver
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'media_archiver'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install media_archiver
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/media_archiver/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/media_archiver
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'mini_exiftool'
|
3
|
+
require 'byebug'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module MediaArchiver
|
7
|
+
class CLI < Thor
|
8
|
+
option :output_dir, aliases: :o, default: Dir.pwd
|
9
|
+
option :recursive, aliases: :r, type: :boolean, default: true
|
10
|
+
option :output_template, default: ':date_created/:camera_maker/:camera_model'
|
11
|
+
option :configuration_file, aliases: :c
|
12
|
+
desc 'scan [PATH]', 'Scans a folder for media files and returns info'
|
13
|
+
def scan(path = Dir.pwd)
|
14
|
+
config = configurations(options)
|
15
|
+
|
16
|
+
path = File.expand_path(path)
|
17
|
+
|
18
|
+
MediaFileUtils.new(path).each(config[:recursive]) do |file|
|
19
|
+
puts output_path(file, config[:output_dir], config[:output_template])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'copy [DIR] [OUTPUT_DIR]', 'Scans a folder and archives media files'
|
24
|
+
option :output_dir, aliases: :o
|
25
|
+
option :recursive, aliases: :r, type: :boolean, default: true
|
26
|
+
option :output_template, default: ':date_created/:camera_maker/:camera_model'
|
27
|
+
option :configuration_file, aliases: :c
|
28
|
+
def copy(path = Dir.pwd)
|
29
|
+
config = configurations(options)
|
30
|
+
|
31
|
+
path = File.expand_path(path)
|
32
|
+
|
33
|
+
MediaFileUtils.new(path).each(config[:recursive]) do |file|
|
34
|
+
dest = output_path(file, config[:output_dir], config[:output_template])
|
35
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
36
|
+
|
37
|
+
output = ["File: #{dest}"]
|
38
|
+
output << if File.exist?(dest)
|
39
|
+
'[SKIP]'
|
40
|
+
else
|
41
|
+
FileUtils.cp(file.path, dest)
|
42
|
+
'[OK]'
|
43
|
+
end
|
44
|
+
|
45
|
+
puts output.join(' ')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def configurations(options)
|
52
|
+
options = symbolize_keys!(options)
|
53
|
+
system_configurations.merge(options)
|
54
|
+
end
|
55
|
+
|
56
|
+
def system_configurations
|
57
|
+
path = [
|
58
|
+
File.expand_path(Dir.pwd),
|
59
|
+
Dir.home
|
60
|
+
].map { |path| File.join(path, '.media_archiver_conf.yml') }
|
61
|
+
.keep_if { |f| File.file? f }
|
62
|
+
.first
|
63
|
+
|
64
|
+
return {} unless path
|
65
|
+
|
66
|
+
load_config_file path
|
67
|
+
end
|
68
|
+
|
69
|
+
def load_config_file(path)
|
70
|
+
symbolize_keys! YAML.load_file(path)
|
71
|
+
end
|
72
|
+
|
73
|
+
def output_path(file, output_path, template)
|
74
|
+
output = [output_path]
|
75
|
+
|
76
|
+
output += output_template_parts(template).map do |key|
|
77
|
+
file.respond_to?(key) ? file.send(key) : file.exif_tags[key.to_s]
|
78
|
+
end
|
79
|
+
output << file.file_name
|
80
|
+
|
81
|
+
File.join(*output)
|
82
|
+
end
|
83
|
+
|
84
|
+
def output_template_parts(template)
|
85
|
+
template.split('/').map do |part|
|
86
|
+
if part[0] == ':'
|
87
|
+
part[1..-1].to_sym
|
88
|
+
else
|
89
|
+
part
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def symbolize_keys!(hash)
|
95
|
+
hash.each_with_object({}) { |(k,v),acc| acc[k.to_sym] = v }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module MediaArchiver
|
2
|
+
class MediaFile
|
3
|
+
attr_reader :path, :file_name
|
4
|
+
|
5
|
+
def initialize(file_path)
|
6
|
+
@path = file_path
|
7
|
+
@file_name = File.basename(@path)
|
8
|
+
|
9
|
+
begin
|
10
|
+
@file = MiniExiftool.new(file_path)
|
11
|
+
@info = @file.to_hash
|
12
|
+
rescue MiniExiftool::Error
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
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']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module MediaArchiver
|
2
|
+
class MediaFileUtils
|
3
|
+
def initialize(path)
|
4
|
+
@path = path
|
5
|
+
end
|
6
|
+
|
7
|
+
def each(recursive)
|
8
|
+
files = if recursive
|
9
|
+
Dir.glob(File.join(@path, '**', '*'))
|
10
|
+
else
|
11
|
+
Dir.glob(File.join(@path, '*'))
|
12
|
+
end
|
13
|
+
|
14
|
+
files
|
15
|
+
.reject { |path| File.directory? path }
|
16
|
+
.each_with_object([]) do |file_path, acc|
|
17
|
+
file = MediaFile.new(file_path)
|
18
|
+
|
19
|
+
if file.valid?
|
20
|
+
yield(file)
|
21
|
+
acc << file
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'media_archiver/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'media_archiver'
|
8
|
+
spec.version = MediaArchiver::VERSION
|
9
|
+
spec.authors = ['David Ramalho']
|
10
|
+
spec.email = ['david@ragingnexus.com']
|
11
|
+
spec.summary = 'Utility to organize media files based on metadata'
|
12
|
+
spec.description = 'Utility that scans a given location for media files and,
|
13
|
+
based on Exif information and a set of rules copies the files over to
|
14
|
+
another location.'
|
15
|
+
spec.homepage = ''
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'byebug'
|
26
|
+
|
27
|
+
spec.add_dependency 'mini_exiftool', '~> 2.5'
|
28
|
+
spec.add_dependency 'thor'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: media_archiver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Ramalho
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mini_exiftool
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.5'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: |-
|
84
|
+
Utility that scans a given location for media files and,
|
85
|
+
based on Exif information and a set of rules copies the files over to
|
86
|
+
another location.
|
87
|
+
email:
|
88
|
+
- david@ragingnexus.com
|
89
|
+
executables:
|
90
|
+
- media_archiver
|
91
|
+
extensions: []
|
92
|
+
extra_rdoc_files: []
|
93
|
+
files:
|
94
|
+
- ".gitignore"
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/media_archiver
|
100
|
+
- lib/media_archiver.rb
|
101
|
+
- lib/media_archiver/cli.rb
|
102
|
+
- lib/media_archiver/media_file.rb
|
103
|
+
- lib/media_archiver/media_file_utils.rb
|
104
|
+
- lib/media_archiver/version.rb
|
105
|
+
- media_archiver.gemspec
|
106
|
+
homepage: ''
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.2.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Utility to organize media files based on metadata
|
130
|
+
test_files: []
|