media-renamer 0.0.2 → 0.1.3

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.
@@ -0,0 +1,114 @@
1
+ #
2
+ #filescanner.rb: defines the class Filescanner, which scans directory trees for media files
3
+ #
4
+
5
+ require 'scrapers/image.rb'
6
+ require 'scrapers/music.rb'
7
+
8
+
9
+ module MediaOrganizer
10
+
11
+
12
+ #FileScanner: scans a file system for images and/or music files, providing a list of file URIs.
13
+ #Output of FileScanner.open() returns a list of paths that can then be consumed by MediaOrganizer::Renamer.
14
+ #
15
+ #===Example
16
+ #
17
+ #Filescanner.open("/path/to/files/", {:image => true, :music => true})
18
+ #
19
+ #This will return a list of all music and image files contained in /path/to/files/ and it's
20
+ class Filescanner
21
+ class FileNotValidError < StandardError ; end
22
+
23
+
24
+ attr_reader :root_nodes
25
+ attr_accessor :source_list
26
+
27
+
28
+ def initialize()
29
+ @root_nodes = []
30
+ @source_list = []
31
+ end
32
+
33
+ #
34
+ #Filescanner.open(String, {}): scans directory tree for media files, starting at String specified in first argument.
35
+ #
36
+ #===Inputs
37
+ # *(1) String: String containing the URI of the top of the directory tree to scan
38
+ #
39
+ # *2: Optional Arguments Hash:
40
+ # *:mode => (:single) -- if set to :single, only the given URI will be scanned. Subdirectories will be ignored.
41
+ # *:music => (true, false) -- if true, music files will be included in the scan. Set to false to exclude music files. Defaults to true
42
+ # *:image => (true, false) -- if true, image files will be included in the scan. Set to false to exclude image files. Defaults to true
43
+ #
44
+ #===Outputs
45
+ #Returns array of strings, where each string is a file URI for a music or image file.
46
+ #
47
+ #
48
+ #===Example
49
+ #Filescanner.open("/absolute/path/for/top/of/directory/tree")
50
+ #
51
+ def open(uri = "", args = {})
52
+ unless !uri.nil? && uri.is_a?(String) && (File.directory?(uri) || File.exists?(uri))
53
+ raise FileNotFoundError, "Directory given (#{uri}) could not be accessed."
54
+ end
55
+
56
+ include_images = true unless args[:image] == false
57
+ include_music = true unless args[:music] == false
58
+ files = []
59
+ if args[:mode] == :single
60
+ files = Dir.glob("#{uri}/*")
61
+ else
62
+ files = Dir.glob("#{uri}/**/*")
63
+ end
64
+
65
+ #add all files found to @source_list, if they are music files
66
+ files.each do |f|
67
+ if (Music.is_music?(f) && include_music) || (Image.is_image?(f) && include_images)
68
+ @source_list << f
69
+ end
70
+ end
71
+
72
+ return @source_list
73
+
74
+ rescue FileNotFoundError => e
75
+ puts e.message
76
+ puts e.backtrace.inspect
77
+ return false
78
+ end
79
+
80
+ #Alternative run mode. Add multiple "root" directories to scan at once
81
+ def addRoot(dir_uri)
82
+ unless !dir_uri.nil? && dir_uri.is_a?(String) && File.directory?(dir_uri)
83
+ raise FileNotFoundError, "Directory given (#{dir_uri}) could not be accessed."
84
+ end
85
+ @root_nodes << dir_uri
86
+ rescue FileNotFoundError => e
87
+ puts e.message
88
+ puts e.backtrace.inspect
89
+ return false
90
+ end
91
+
92
+ #Filescanner:multiscan(): scans multiple directories added to @root_nodes using the addRoot() method.
93
+ #
94
+ #===Inputs
95
+ #
96
+ # *Optional Arguments Hash:
97
+ # *:mode => (:single, :multiple)
98
+ # *:music => (true, false) -- if true, music files will be included in the scan. Set to false to exclude music files. Defaults to true
99
+ # *:image => (true, false) -- if true, image files will be included in the scan. Set to false to exclude image files. Defaults to true
100
+ #
101
+ #===Outputs
102
+ #Array of strings, where each string is a file URI for a music or image file.
103
+ #
104
+ def multiscan(args = {})
105
+ @root_nodes.each do |uri|
106
+ open(uri, args)
107
+ end
108
+ return @source_list
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+
@@ -0,0 +1,21 @@
1
+ #media-renamer.rb
2
+
3
+ require 'renamer.rb'
4
+ require 'filescanner.rb'
5
+
6
+ #MediaOrganizer: namespace container for MediaOrganizer sub-classes:
7
+ # *Renamer
8
+ # *Filescanner
9
+ # *Image
10
+ # *Music
11
+ module MediaOrganizer
12
+ VERSION = "0.1.2"
13
+
14
+ class FileNotValidError < StandardError ; end
15
+ class InvalidArgumentError < StandardError ; end
16
+ class UnsupportedFileTypeError < StandardError ; end
17
+ class RenameFailedError < StandardError ; end
18
+ class FileNotFoundError < StandardError ; end
19
+
20
+ end
21
+
@@ -1,156 +1,213 @@
1
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
3
  #next major release will include support
4
-
5
-
6
4
  require 'scrapers/image.rb'
7
5
  require 'scrapers/music.rb'
8
6
 
9
- class FileNotValidError < StandardError ; end
10
- class InvalidArgumentError < StandardError ; end
11
- class UnsupportedFileTypeError < StandardError ; end
12
-
13
-
14
- class Renamer
15
- include Image
16
- include Music
17
- attr_accessor :naming_scheme # => array of strings and literals used to construct filenames
18
-
19
- def initialize
20
- @naming_scheme = ["Renamed-default-"]
21
- end
22
-
23
- def setNamingScheme(arr = [])
24
- @naming_scheme = setScheme(arr)
25
- end
26
- #Input: list of URIs in the form of an array
27
- #Output: hash of "file name pairs." old_file => new_file
28
- #Accepts optional arguments: :scheme (array of strings and symbols specifying file naming convention)
29
- def generateRenameList(uri_list = [], args = {})
30
- if args[:scheme] != nil && args[:scheme].is_a?(Array) && !args[:scheme].empty?
31
- scheme = setScheme(args[:scheme])
32
- else
33
- scheme = @naming_scheme
34
- end
35
- unless !uri_list.nil? && uri_list.is_a?(Array)
36
- raise InvalidArgumentError
7
+ module MediaOrganizer
8
+
9
+ #Renamer: primary class to use for renaming files. Allows renaming of a given list of files to a user-defined scheme based on each file's metadata.
10
+ #
11
+ #===Key Methods
12
+ # *setNamingScheme()
13
+ # *generateRenameList()
14
+ # *overwrite()
15
+ #
16
+ #===Example Usage
17
+ #
18
+ # old_uris = ['./test/data/hs-2003-24-a-full_tif.tif']
19
+ #
20
+ # scheme = ["Test-", :date_time]
21
+ #
22
+ # r = Renamer.new()
23
+ #
24
+ # r.setNamingScheme(scheme)
25
+ #
26
+ # new_uris = r.generateRenameList(old_uris)
27
+ #
28
+ # r.overwrite(new_uris) #new filename: "./test/data/Test-2003-09-03 12_52_43 -0400.tif")
29
+ #
30
+ class Renamer
31
+ DISALLOWED_CHARACTERS = /[\\:\?\*<>\|"\/]/ #Characters that are not allowed in file names by many file systems. Replaced with @subchar character.
32
+ class RenameFailedError < StandardError ; end
33
+ class FileNotValidError < StandardError ; end
34
+ class InvalidArgumentError < StandardError ; end
35
+ class UnsupportedFileTypeError < StandardError ; end
36
+ class FileNotFoundError < StandardError ; end
37
+
38
+
39
+ attr_accessor :naming_scheme #Array of strings and literals used to construct filenames. Set thruough setNamingScheme as opposed to typical/default accessor.
40
+ attr_accessor :subchar #Character with which to substitute disallowed characters
41
+
42
+ def initialize(args = {})
43
+ @naming_scheme = ["Renamed-default-"]
44
+ @subchar = "_"
37
45
  end
38
46
 
39
- filename_pairs = {}
40
- uri_list.each do |i|
41
- new_string = handleFile(i, scheme)
42
- #If this is a valid file path, add it to the filename_pairs
43
- #puts "New file rename added: #{new_string}"
44
- if new_string != nil && new_string != ""
45
- filename_pairs[i] = new_string
46
- end
47
+ #Renamer.setNamingScheme(): sets the naming scheme for the generateRenameList method.
48
+ #
49
+ #===Inputs
50
+ # 1. Array containing strings and symbols.
51
+ #
52
+ #===Outputs
53
+ #None (sets instance variable @naming_scheme)
54
+ #
55
+ #===Example
56
+ #setNamingScheme(["Vacation_Photos_", :date_taken]).
57
+ #This will rename files into a format like "Vacation_Photos_2014_05_22.png" based on the file's date_taken metadata field.
58
+ def setNamingScheme(arr = [])
59
+ @naming_scheme = setScheme(arr)
47
60
  end
48
61
 
49
- return filename_pairs
50
-
51
- rescue InvalidArgumentError => arg_e
52
- puts arg_e
53
- puts "Invalid arguments provided. Expected: uri_list = [], args = {}"
54
- puts arg_e.backtrace.inspect
55
- rescue => e
56
- puts e
57
- puts e.message
58
- puts e.backtrace.inspect
59
- end
62
+ #Renamer.generateRenameList(): Creates a hash mapping the original filenames to the new (renamed) filenames
63
+ #
64
+ #===Inputs
65
+ # 1. List of URIs in the form of an array
66
+ # 2. Optional hash of arguments.
67
+ # *:scheme - array of strings and symbols specifying file naming convention
68
+ #
69
+ #===Outputs
70
+ #Hash of "file name pairs." old_file => new_file
71
+ def generateRenameList(uri_list = [], args = {})
72
+ if args[:scheme] != nil && args[:scheme].is_a?(Array) && !args[:scheme].empty?
73
+ scheme = setScheme(args[:scheme])
74
+ else
75
+ scheme = @naming_scheme
76
+ end
77
+ unless !uri_list.nil? && uri_list.is_a?(Array)
78
+ raise InvalidArgumentError
79
+ end
60
80
 
61
- def overwrite(renames_hash = {})
62
- renames_hash.each do |old_name, new_name|
63
- begin
64
- #error/integrity checking on old_name and new_name
65
- raise FileNotValidError, "Could not access specified source file: #{i}." unless old_name.is_a?(String) && File.exists?(old_name)
66
- raise FileNotValidError, "New file name provided is not a string" unless new_name.is_a?(String)
67
-
68
- File.rename(File.absolute_path(old_name),File.dirname(File.absolute_path(old_name)) + "/" + new_name)
69
-
70
- #check that renamed file exists
71
- unless new_name.is_a?(String) && File.exists?(new_name)
72
- raise RenameFailedError, "Could not successfuly rename file: #{old_name} => #{new_name}."
73
- end
74
- rescue => e
75
- puts "Ignoring rename for #{old_name} => #{new_name}"
76
- puts e
77
- puts e.backtrace.inspect
81
+ filename_pairs = {}
82
+ uri_list.each do |i|
83
+ new_string = handleFile(i, scheme)
84
+ #If this is a valid file path, add it to the filename_pairs
85
+ #puts "New file rename added: #{new_string}"
86
+ if new_string != nil && new_string != ""
87
+ filename_pairs[i] = new_string
88
+ end
78
89
  end
79
- end
80
- end
81
90
 
82
- #Routes metadata scrape based on file type (currently relies on extension - future version should use MIME)
83
- #currently assumes file was checked for validity in calling code
84
- def getFileMetadata(file)
91
+ return filename_pairs
85
92
 
86
- #LOAD EXIF DATA
87
- case File.extname(file)
88
- when '.jpg'
89
- Image::getJpegData(file)
90
- when '.tif'
91
- Image::getTiffData(file)
92
- when '.mp3' , '.wav' , '.m4a' , '.flac' , '.aiff'
93
- Music::getMusicData(file)
94
- else
95
- raise UnsupportedFileTypeError, "Error processing #{file}"
93
+ rescue InvalidArgumentError => arg_e
94
+ puts arg_e
95
+ puts "Invalid arguments provided. Expected: uri_list = [], args = {}"
96
+ puts arg_e.backtrace.inspect
97
+ rescue => e
98
+ puts e
99
+ puts e.message
100
+ puts e.backtrace.inspect
96
101
  end
97
- #otherwise, outsource
98
- rescue UnsupportedFileTypeError => e
99
- puts "Could not process file: Extension #{File.extname(file)} is not supported."
100
- puts e.backtrace.inspect
101
- end
102
-
103
102
 
104
- private
105
- def handleFile(file, scheme)
106
- #Check file is real
107
- unless file.is_a?(String) && File.exists?(file)
108
- raise FileNotValidError, "Could not access specified file file: #{file}."
109
- end
110
- #convert URI (i) to absolute path
111
-
112
- #get metadata hash for this file (i)
113
- metadata = getFileMetadata(File.absolute_path(file))
114
- #build URI string
115
- new_string = ""
116
- scheme.each do |j|
117
- if j.is_a?(String) then new_string += j
118
- elsif j.is_a?(Symbol)
103
+ #Renamer.overwrite(): Writes new file names based upon mapping provided in hash argument. NOTE: this will create changes to file names!
104
+ #
105
+ #===Inputs
106
+ # 1. Hash containing mappings between old filenames (full URI) and new filenames (full URI). Example: {"/path/to/oldfile.jpg" => "/path/to/newfile.jpg"}
107
+ #
108
+ #===Outputs
109
+ #none (file names are overwritten)
110
+ def overwrite(renames_hash = {})
111
+ renames_hash.each do |old_name, new_name|
119
112
  begin
120
- raise EmptyMetadataError unless metadata[j] != nil
121
- new_string += metadata[j].to_s
122
- rescue => e
123
- puts "Could not get string for metadata tag provided in scheme: #{j} for file #{file}."
124
- puts "Ignoring file #{file}"
125
- puts e.backtrace.inspect
126
- return nil
113
+ #error/integrity checking on old_name and new_name
114
+ raise FileNotValidError, "Could not access specified source file: #{i}." unless old_name.is_a?(String) && File.exists?(old_name)
115
+ raise FileNotValidError, "New file name provided is not a string" unless new_name.is_a?(String)
116
+
117
+ #puts (File.dirname(File.absolute_path(old_name)) + "/" + new_name) #Comment this line out unless testing
118
+ File.rename(File.absolute_path(old_name),File.dirname(File.absolute_path(old_name)) + "/" + new_name)
119
+
120
+ #check that renamed file exists - Commented out because this currently does not work.
121
+ #unless new_name.is_a?(String) && File.exists?(new_name)
122
+ # raise RenameFailedError, "Could not successfuly rename file: #{old_name} => #{new_name}. Invalid URI or file does not exist."
123
+ #end
124
+ rescue => e
125
+ puts "Ignoring rename for #{old_name} => #{new_name}"
126
+ puts e
127
+ puts e.backtrace.inspect
127
128
  end
128
129
  end
129
130
  end
130
- #puts "Found file metadata: #{metadata[:date_time]}"
131
- return new_string + File.extname(file)
132
- rescue FileNotValidError => e
133
- puts ("Ignoring file #{file}")
134
- puts e
135
- puts e.backtrace
136
- return nil
137
- rescue => e
138
- puts e.message
139
- puts e.backtrace.inspect
140
- return nil
141
- end
142
131
 
143
- def setScheme(input_arr = [])
144
- clean_scheme = []
145
- input_arr.each do |i|
146
- if i.is_a?(String) || i.is_a?(Symbol)
147
- clean_scheme << i
132
+ #Routes metadata scrape based on file type (currently relies on extension - future version should use MIME)
133
+ #currently assumes file was checked for validity in calling code.
134
+ #
135
+ #===Inputs
136
+ #String containing full file URI (path and filename)
137
+ #
138
+ #===Outputs
139
+ #Returns hash of metadata for file, or nil if none/error.
140
+ def getFileMetadata(file)
141
+
142
+ #LOAD EXIF DATA
143
+ case File.extname(file).downcase
144
+ when '.jpg'
145
+ Image::getJpegData(file)
146
+ when '.tif'
147
+ Image::getTiffData(file)
148
+ when '.mp3' , '.wav' , '.flac' , '.aiff', '.ogg', '.m4a', '.asf'
149
+ Music::getMusicData(file)
150
+ else
151
+ raise UnsupportedFileTypeError, "Error processing #{file}"
148
152
  end
153
+ rescue UnsupportedFileTypeError => e
154
+ puts "Could not process file: Extension #{File.extname(file)} is not supported."
155
+ puts e.backtrace.inspect
149
156
  end
150
- return clean_scheme
151
- end
152
- end
153
157
 
154
158
 
159
+ private
160
+ def handleFile(file, scheme)
161
+ #Check file is real
162
+ unless file.is_a?(String) && File.exists?(file)
163
+ raise FileNotValidError, "Could not access specified file file: #{file}."
164
+ end
165
+ #convert URI (i) to absolute path
166
+
167
+ #get metadata hash for this file (i)
168
+ metadata = getFileMetadata(File.absolute_path(file))
169
+ #build URI string
170
+ new_string = ""
171
+ scheme.each do |j|
172
+ if j.is_a?(String) then new_string += j
173
+ elsif j.is_a?(Symbol)
174
+ begin
175
+ raise EmptyMetadataError unless metadata[j] != nil
176
+ new_string += metadata[j].to_s
177
+ rescue => e
178
+ puts "Could not get string for metadata tag provided in scheme: #{j} for file #{file}."
179
+ puts "Ignoring file #{file}"
180
+ puts e.backtrace.inspect
181
+ return nil
182
+ end
183
+ end
184
+ end
185
+ #puts "Found file metadata: #{metadata[:date_time]}"
186
+ return subHazardousChars(new_string + File.extname(file))
187
+ rescue FileNotValidError => e
188
+ puts ("Ignoring file #{file}")
189
+ puts e
190
+ puts e.backtrace
191
+ return nil
192
+ rescue => e
193
+ puts e.message
194
+ puts e.backtrace.inspect
195
+ return nil
196
+ end
197
+
198
+ def setScheme(input_arr = [])
199
+ clean_scheme = []
200
+ input_arr.each do |i|
201
+ if i.is_a?(String) || i.is_a?(Symbol)
202
+ clean_scheme << i
203
+ end
204
+ end
205
+ return clean_scheme
206
+ end
155
207
 
208
+ def subHazardousChars(str = "")
209
+ return str.gsub(DISALLOWED_CHARACTERS, @subchar)
210
+ end
211
+ end
156
212
 
213
+ end
@@ -1,15 +1,43 @@
1
1
  require 'exifr'
2
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
3
+ module MediaOrganizer
4
+
5
+ module Image
6
+ SUPPORTED_FILETYPES = %w{.jpg .tif}
7
+ class FileNotFoundError < StandardError ; end
8
+
9
+ def Image.getJpegData(file)
10
+ meta = EXIFR::JPEG.new(file)
11
+ return meta.to_hash
12
+ #!!! Rescue from common file-related and exifr-related errors here
13
+ end
14
+
15
+ def Image.getTiffData(file)
16
+ meta = EXIFR::TIFF.new(file)
17
+ return meta.to_hash
18
+ #!!! Rescue from common file-related and exifr-related errors here
19
+ end
20
+
21
+ def Image.supported_filetypes
22
+ return SUPPORTED_FILETYPES
23
+ end
24
+
25
+ def Image.is_image?(uri)
26
+ unless !uri.nil? && uri.is_a?(String) && File.exists?(uri)
27
+ raise FileNotFoundError, "Directory given (#{uri}) could not be accessed."
28
+ end
29
+
30
+ if SUPPORTED_FILETYPES.include?(File.extname(uri).downcase)
31
+ return true
32
+ else
33
+ return false
34
+ end
35
+
36
+ rescue FileNotFoundError => e
37
+ puts e.message
38
+ puts e.backtrace.inspect
39
+ return false
40
+ end
9
41
 
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
42
  end
15
43
  end
@@ -1,32 +1,115 @@
1
1
  require 'taglib'
2
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
3
+ module MediaOrganizer
30
4
 
31
- end
5
+ module Music
6
+ class FileNotFoundError < StandardError ; end
7
+
8
+ SUPPORTED_FILETYPES = %w{.mp3 .m4a .mp4 .flac .m4a .ogg .aiff .asf .wav}
9
+
10
+ def Music.getMusicData(file)
11
+ attributes = {}
12
+ TagLib::FileRef.open(file) do |fileref|
13
+ unless fileref.null?
14
+ #sign tags to local variables
15
+ tag = fileref.tag
16
+ properties = fileref.audio_properties
17
+
18
+ #load tags into attributes attribute
19
+ attributes[:title] = tag.title
20
+ attributes[:track] = tag.track
21
+ attributes[:genre] = tag.genre
22
+ attributes[:year] = tag.year
23
+ attributes[:album] = tag.album
24
+ attributes[:artist] = tag.artist
25
+ attributes[:comment] = tag.comment
26
+
27
+ attributes[:length] = properties.length
28
+ attributes[:bitrate] = properties.bitrate
29
+ attributes[:channels] = properties.channels
30
+ attributes[:sample_rate] = properties.sample_rate
31
+
32
+ end
33
+ end
34
+ return attributes
35
+ end
36
+
37
+ def Music.supported_filetypes
38
+ reutrn SUPPORTED_FILETYPES
39
+ end
40
+
41
+ def Music.is_music?(uri)
42
+ unless !uri.nil? && uri.is_a?(String) && File.exists?(uri)
43
+ raise FileNotFoundError, "Directory given (#{uri}) could not be accessed."
44
+ end
45
+
46
+ if SUPPORTED_FILETYPES.include?(File.extname(uri).downcase)
47
+ return true
48
+ else
49
+ return false
50
+ end
51
+
52
+ rescue FileNotFoundError => e
53
+ puts e.message
54
+ puts e.backtrace.inspect
55
+ return false
56
+ end
32
57
 
58
+ #
59
+ #availableMetadata(file, args): returns list of fields available as metadata for the given file.
60
+ #
61
+ #===Inputs
62
+ # *(1) filepath: full/absolute URI of the file to be analyzed. Required input.
63
+ # *(2) args: optional arguments passed as hash. Set ":include_null" to false to only return populated metadata fields.
64
+ #
65
+ def Music.availableMetadata(filepath = "", args = {})
66
+ attrs = getMusicData(filepath)
67
+
68
+ unless args[:include_null] == false
69
+ attrs.each do |field, value|
70
+ if value == nil || value == ""
71
+ attrs.delete(field)
72
+ end
73
+ end
74
+ end
75
+ return attrs
76
+ end
77
+
78
+ #
79
+ #writeMetadata(file = "", meta = {}): returns list of fields available as metadata for the given file.
80
+ #
81
+ #===Inputs
82
+ # *(1) filepath: full/absolute URI of the file to be analyzed. Required input.
83
+ # *(2) meta: metadata to be written, passed as a hash in the format :metadata_field => metadata_value
84
+ #
85
+ #===Outputs
86
+ #Returns true if the file was successfully saved. Note: true status does not necessarily indicate each field was successfully written.
87
+ #
88
+ #===Examples
89
+ #Music.writeMetadata("/absolute/path/to/file.mp3", {:artist => "NewArtistName", :year => "2019"})
90
+ #
91
+ def Music.writeMetadata(filepath, meta = {})
92
+ attributes = {}
93
+ successflag = false
94
+ TagLib::FileRef.open(filepath) do |fileref|
95
+ unless fileref.null?
96
+ #sign tags to local variables
97
+ tag = fileref.tag
98
+ properties = fileref.audio_properties
99
+
100
+ meta.each do |field, value|
101
+ if tag.respond_to?(field)
102
+ tag.send("#{field.to_s}=", value)
103
+ elsif properties.respond_to?(field)
104
+ properties.send("#{field.to_s}=", value)
105
+ end
106
+ end
107
+ successflag = fileref.save
108
+ end
109
+ end
110
+ return successflag
111
+
112
+ end
113
+
114
+ end
115
+ end
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.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,55 +9,25 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
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'
46
- description: ! 'Provides a set of functions for dynamically renaming files using their
47
- metadata, according to a customizable taxonomy. For example, use bulk-renamer to
48
- set filenames for a directory of photos to a standard such as: "<date-taken> - Ski
49
- Vacation.jpg". Currently supports only JPEG and TIFF files. Future releases will
50
- include support for music and additional image files.'
12
+ date: 2015-03-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Provides a set of functions to scan file systems for media files,
15
+ and dynamically rename them using their metadata. Files are renamed according to
16
+ a customizable taxonomy. For example, use MediaOrganizer::Renamer to set filenames
17
+ for a directory of photos to a standard such as: "<date-taken> - Ski Vacation.jpg".
18
+ Currently supports only JPEG and TIFF files. Future releases will include support
19
+ for music and additional image files.'
51
20
  email: djeserkare@gmail.com
52
21
  executables: []
53
22
  extensions: []
54
23
  extra_rdoc_files: []
55
24
  files:
56
25
  - lib/renamer.rb
57
- - lib/media-renamer.rb
58
- - lib/scrapers/image.rb
26
+ - lib/media-organizer.rb
27
+ - lib/filescanner.rb
59
28
  - lib/scrapers/music.rb
60
- homepage: http://rubygems.org/gems/bulk-renamer
29
+ - lib/scrapers/image.rb
30
+ homepage: http://rubygems.org/gems/media-organizer
61
31
  licenses:
62
32
  - MIT
63
33
  post_install_message:
@@ -81,5 +51,5 @@ rubyforge_project:
81
51
  rubygems_version: 1.8.23
82
52
  signing_key:
83
53
  specification_version: 3
84
- summary: Rename files in bulk based on file metadata.
54
+ summary: Rename media files in bulk based on file metadata.
85
55
  test_files: []
@@ -1,6 +0,0 @@
1
- #media-renamer.rb
2
-
3
- require 'renamer.rb'
4
- class MediaRenamer < Renamer
5
- end
6
-