media-renamer 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/media-renamer.rb +2 -0
- data/lib/renamer.rb +14 -20
- data/lib/scrapers/image.rb +15 -0
- data/lib/scrapers/music.rb +32 -0
- metadata +37 -3
data/lib/media-renamer.rb
CHANGED
data/lib/renamer.rb
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
#renamer.rb
|
|
1
|
+
#renamer.rb: main codebase for the media-renamer gem.
|
|
2
2
|
#Currently configured to only rename JPG and TIF files (using EXIFR to extract metadata)
|
|
3
|
+
#next major release will include support
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
require 'scrapers/image.rb'
|
|
7
|
+
require 'scrapers/music.rb'
|
|
7
8
|
|
|
8
9
|
class FileNotValidError < StandardError ; end
|
|
9
10
|
class InvalidArgumentError < StandardError ; end
|
|
10
11
|
class UnsupportedFileTypeError < StandardError ; end
|
|
11
12
|
|
|
13
|
+
|
|
12
14
|
class Renamer
|
|
13
|
-
|
|
15
|
+
include Image
|
|
16
|
+
include Music
|
|
14
17
|
attr_accessor :naming_scheme # => array of strings and literals used to construct filenames
|
|
15
18
|
|
|
16
19
|
def initialize
|
|
@@ -33,7 +36,6 @@ class Renamer
|
|
|
33
36
|
raise InvalidArgumentError
|
|
34
37
|
end
|
|
35
38
|
|
|
36
|
-
|
|
37
39
|
filename_pairs = {}
|
|
38
40
|
uri_list.each do |i|
|
|
39
41
|
new_string = handleFile(i, scheme)
|
|
@@ -84,9 +86,11 @@ class Renamer
|
|
|
84
86
|
#LOAD EXIF DATA
|
|
85
87
|
case File.extname(file)
|
|
86
88
|
when '.jpg'
|
|
87
|
-
getJpegData(file)
|
|
89
|
+
Image::getJpegData(file)
|
|
88
90
|
when '.tif'
|
|
89
|
-
getTiffData(file)
|
|
91
|
+
Image::getTiffData(file)
|
|
92
|
+
when '.mp3' , '.wav' , '.m4a' , '.flac' , '.aiff'
|
|
93
|
+
Music::getMusicData(file)
|
|
90
94
|
else
|
|
91
95
|
raise UnsupportedFileTypeError, "Error processing #{file}"
|
|
92
96
|
end
|
|
@@ -96,18 +100,6 @@ class Renamer
|
|
|
96
100
|
puts e.backtrace.inspect
|
|
97
101
|
end
|
|
98
102
|
|
|
99
|
-
def getJpegData(file)
|
|
100
|
-
meta = EXIFR::JPEG.new(file)
|
|
101
|
-
return meta.to_hash
|
|
102
|
-
#!!! Rescue from common file-related and exifr-related errors here
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def getTiffData(file)
|
|
106
|
-
meta = EXIFR::TIFF.new(file)
|
|
107
|
-
return meta.to_hash
|
|
108
|
-
#!!! Rescue from common file-related and exifr-related errors here
|
|
109
|
-
end
|
|
110
|
-
|
|
111
103
|
|
|
112
104
|
private
|
|
113
105
|
def handleFile(file, scheme)
|
|
@@ -160,3 +152,5 @@ class Renamer
|
|
|
160
152
|
end
|
|
161
153
|
|
|
162
154
|
|
|
155
|
+
|
|
156
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'exifr'
|
|
2
|
+
|
|
3
|
+
module Image
|
|
4
|
+
def Image.getJpegData(file)
|
|
5
|
+
meta = EXIFR::JPEG.new(file)
|
|
6
|
+
return meta.to_hash
|
|
7
|
+
#!!! Rescue from common file-related and exifr-related errors here
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def Image.getTiffData(file)
|
|
11
|
+
meta = EXIFR::TIFF.new(file)
|
|
12
|
+
return meta.to_hash
|
|
13
|
+
#!!! Rescue from common file-related and exifr-related errors here
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'taglib'
|
|
2
|
+
|
|
3
|
+
module Music
|
|
4
|
+
def Music.getMusicData(file)
|
|
5
|
+
attributes = {}
|
|
6
|
+
TagLib::FileRef.open(file) do |fileref|
|
|
7
|
+
unless fileref.null?
|
|
8
|
+
#sign tags to local variables
|
|
9
|
+
tag = fileref.tag
|
|
10
|
+
properties = fileref.audio_properties
|
|
11
|
+
|
|
12
|
+
#load tags into attributes attribute
|
|
13
|
+
attributes[:track_name] = tag.title
|
|
14
|
+
attributes[:track_number] = tag.track
|
|
15
|
+
attributes[:track_genre] = tag.genre
|
|
16
|
+
attributes[:track_release_date] = tag.year
|
|
17
|
+
attributes[:album_name] = tag.album
|
|
18
|
+
attributes[:artist_name] = tag.artist
|
|
19
|
+
attributes[:comment] = tag.comment
|
|
20
|
+
|
|
21
|
+
attributes[:track_length] = properties.length
|
|
22
|
+
attributes[:track_bitrate] = properties.bitrate
|
|
23
|
+
attributes[:track_channels] = properties.channels
|
|
24
|
+
attributes[:track_sample_rate] = properties.sample_rate
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
return attributes
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: media-renamer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,8 +9,40 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2015-
|
|
13
|
-
dependencies:
|
|
12
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: taglib-ruby
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: exifr
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
14
46
|
description: ! 'Provides a set of functions for dynamically renaming files using their
|
|
15
47
|
metadata, according to a customizable taxonomy. For example, use bulk-renamer to
|
|
16
48
|
set filenames for a directory of photos to a standard such as: "<date-taken> - Ski
|
|
@@ -23,6 +55,8 @@ extra_rdoc_files: []
|
|
|
23
55
|
files:
|
|
24
56
|
- lib/renamer.rb
|
|
25
57
|
- lib/media-renamer.rb
|
|
58
|
+
- lib/scrapers/image.rb
|
|
59
|
+
- lib/scrapers/music.rb
|
|
26
60
|
homepage: http://rubygems.org/gems/bulk-renamer
|
|
27
61
|
licenses:
|
|
28
62
|
- MIT
|