ruby-mp3info 0.6.9 → 0.6.10
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/History.txt +4 -0
- data/lib/mp3info.rb +44 -37
- data/lib/mp3info/id3v2.rb +1 -0
- data/test/test_ruby-mp3info.rb +16 -0
- metadata +2 -2
data/History.txt
CHANGED
data/lib/mp3info.rb
CHANGED
@@ -18,7 +18,7 @@ end
|
|
18
18
|
|
19
19
|
class Mp3Info
|
20
20
|
|
21
|
-
VERSION = "0.6.
|
21
|
+
VERSION = "0.6.10"
|
22
22
|
|
23
23
|
LAYER = [ nil, 3, 2, 1]
|
24
24
|
BITRATE = {
|
@@ -189,12 +189,18 @@ class Mp3Info
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
-
# Instantiate Mp3Info object with name +filename
|
193
|
-
# options hash for ID3v2#new
|
194
|
-
|
192
|
+
# Instantiate Mp3Info object with name +filename+.
|
193
|
+
# options hash is used for ID3v2#new.
|
194
|
+
# You can specify :parse_tags => false to disable the processing
|
195
|
+
# of the tags (read and write).
|
196
|
+
def initialize(filename, options = {})
|
195
197
|
warn("#{self.class}::new() does not take block; use #{self.class}::open() instead") if block_given?
|
196
198
|
@filename = filename
|
197
|
-
@
|
199
|
+
@tag_parsing_enabled = options.delete(:parse_tags)
|
200
|
+
if @tag_parsing_enabled == nil
|
201
|
+
@tag_parsing_enabled = true
|
202
|
+
end
|
203
|
+
@id3v2_options = options
|
198
204
|
reload
|
199
205
|
end
|
200
206
|
|
@@ -204,46 +210,44 @@ class Mp3Info
|
|
204
210
|
|
205
211
|
@header = {}
|
206
212
|
|
207
|
-
@tag1 = {}
|
208
|
-
@tag1.extend(HashKeys)
|
209
|
-
|
210
|
-
@tag2 = ID3v2.new(@id3v2_options)
|
211
|
-
|
212
213
|
@file = File.new(filename, "rb")
|
213
214
|
@file.extend(Mp3FileMethods)
|
215
|
+
@tag1 = @tag = @tag1_orig = @tag_orig = {}
|
216
|
+
@tag1.extend(HashKeys)
|
217
|
+
@tag2 = ID3v2.new(@id3v2_options)
|
214
218
|
|
215
219
|
begin
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
@tag = {}
|
220
|
+
if @tag_parsing_enabled
|
221
|
+
parse_tags
|
222
|
+
@tag1_orig = @tag1.dup
|
220
223
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
+
if hastag1?
|
225
|
+
@tag = @tag1.dup
|
226
|
+
end
|
224
227
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
228
|
+
if hastag2?
|
229
|
+
@tag = {}
|
230
|
+
# creation of a sort of "universal" tag, regardless of the tag version
|
231
|
+
tag2_mapping = @tag2.version =~ /^2\.2/ ? TAG_MAPPING_2_2 : TAG_MAPPING_2_3
|
232
|
+
tag2_mapping.each do |key, tag2_name|
|
233
|
+
tag_value = (@tag2[tag2_name].is_a?(Array) ? @tag2[tag2_name].first : @tag2[tag2_name])
|
234
|
+
next unless tag_value
|
235
|
+
@tag[key] = tag_value.is_a?(Array) ? tag_value.first : tag_value
|
236
|
+
|
237
|
+
if %w{year tracknum}.include?(key)
|
238
|
+
@tag[key] = tag_value.to_i
|
239
|
+
end
|
240
|
+
# this is a special case with id3v2.2, which uses
|
241
|
+
# old fashionned id3v1 genres
|
242
|
+
if tag2_name == "TCO" && tag_value =~ /^\((\d+)\)$/
|
243
|
+
@tag["genre_s"] = GENRES[$1.to_i]
|
244
|
+
end
|
241
245
|
end
|
242
|
-
|
243
|
-
end
|
246
|
+
end
|
244
247
|
|
245
|
-
|
246
|
-
|
248
|
+
@tag.extend(HashKeys)
|
249
|
+
@tag_orig = @tag.dup
|
250
|
+
end
|
247
251
|
|
248
252
|
|
249
253
|
### extracts MPEG info from MPEG header and stores it in the hash @mpeg
|
@@ -420,6 +424,9 @@ class Mp3Info
|
|
420
424
|
# Flush pending modifications to tags and close the file
|
421
425
|
def close
|
422
426
|
puts "close" if $DEBUG
|
427
|
+
if !@tag_parsing_enabled
|
428
|
+
return
|
429
|
+
end
|
423
430
|
if @tag != @tag_orig
|
424
431
|
puts "@tag has changed" if $DEBUG
|
425
432
|
|
data/lib/mp3info/id3v2.rb
CHANGED
@@ -103,6 +103,7 @@ class ID3v2 < DelegateClass(Hash)
|
|
103
103
|
# for read and write tag2 values.
|
104
104
|
attr_reader :options
|
105
105
|
|
106
|
+
# possible options are described above ('options' attribute)
|
106
107
|
# you can access this object like an hash, with [] and []= methods
|
107
108
|
# special cases are ["disc_number"] and ["disc_total"] mirroring TPOS attribute
|
108
109
|
def initialize(options = {})
|
data/test/test_ruby-mp3info.rb
CHANGED
@@ -452,6 +452,22 @@ class Mp3InfoTest < Test::Unit::TestCase
|
|
452
452
|
end
|
453
453
|
end
|
454
454
|
|
455
|
+
def test_parse_tags_disabled
|
456
|
+
write_temp_file(DUMMY_TAG2)
|
457
|
+
Mp3Info.open(TEMP_FILE, :parse_tags => false) do |mp3|
|
458
|
+
assert mp3.tag.empty?
|
459
|
+
assert mp3.tag1.empty?
|
460
|
+
assert mp3.tag2.empty?
|
461
|
+
mp3.tag["artist"] = "some dummy tag"
|
462
|
+
mp3.tag2["TIT2"] = "title 2"
|
463
|
+
mp3.flush
|
464
|
+
# tag should not be written
|
465
|
+
assert mp3.tag.empty?
|
466
|
+
assert mp3.tag1.empty?
|
467
|
+
assert mp3.tag2.empty?
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
455
471
|
def compute_audio_content_mp3_digest(mp3)
|
456
472
|
pos, size = mp3.audio_content
|
457
473
|
data = File.open(mp3.filename) do |f|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mp3info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Pierronnet
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-27 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|