ruby-mp3info 0.6.10 → 0.6.11

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.6.11 / 2009-01-27
2
+
3
+ * the library doesn't raise an ID3v2Error anymore when a id3v2 tag size is incorrect, but just output
4
+ a warning. (Fixes bug #23619)
5
+
1
6
  === 0.6.10 / 2008-11-27
2
7
 
3
8
  * processing of tags (read and write) can be disabled with :parse_tags => false
data/README.txt CHANGED
@@ -3,6 +3,7 @@ ruby-mp3info
3
3
  by Guillaume Pierronnet
4
4
  * http://ruby-mp3info.rubyforge.org/
5
5
  * http://rubyforge.org/projects/ruby-mp3info/
6
+ * mercurial repository since v0.6.10: http://www.bitbucket.org/moumar/ruby-mp3info/overview/
6
7
 
7
8
  == DESCRIPTION:
8
9
 
data/lib/mp3info.rb CHANGED
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  class Mp3Info
20
20
 
21
- VERSION = "0.6.10"
21
+ VERSION = "0.6.11"
22
22
 
23
23
  LAYER = [ nil, 3, 2, 1]
24
24
  BITRATE = {
@@ -305,7 +305,7 @@ class Mp3Info
305
305
  @vbr = true
306
306
  else
307
307
  # for cbr, calculate duration with the given bitrate
308
- stream_size = @file.stat.size - (hastag1? ? TAG1_SIZE : 0) - (@tag2.valid? ? @tag2.io_position : 0)
308
+ stream_size = @file.stat.size - (hastag1? ? TAG1_SIZE : 0) - (@tag2.io_position || 0)
309
309
  @length = ((stream_size << 3)/1000.0)/@bitrate
310
310
  # read the first 100 frames and decide if the mp3 is vbr and needs full scan
311
311
  begin
@@ -386,7 +386,7 @@ class Mp3Info
386
386
 
387
387
  # Does the file has an id3v1 or v2 tag?
388
388
  def hastag?
389
- hastag1? or hastag2?
389
+ hastag1? || hastag2?
390
390
  end
391
391
 
392
392
  # Does the file has an id3v1 tag?
@@ -396,7 +396,7 @@ class Mp3Info
396
396
 
397
397
  # Does the file has an id3v2 tag?
398
398
  def hastag2?
399
- @tag2.valid?
399
+ @tag2.parsed?
400
400
  end
401
401
 
402
402
  # write to another filename at close()
@@ -482,7 +482,7 @@ class Mp3Info
482
482
  tempfile_name = nil
483
483
  File.open(@filename, 'rb+') do |file|
484
484
  #if tag2 already exists, seek to end of it
485
- if @tag2.valid?
485
+ if @tag2.parsed?
486
486
  file.seek(@tag2.io_position)
487
487
  end
488
488
  # if @file.read(3) == "ID3"
@@ -543,7 +543,7 @@ private
543
543
  unless @tag1_parsed # v1 tag at end
544
544
  # this preserves the file pos if tag2 found, since gettag2 leaves
545
545
  # the file at the best guess as to the first MPEG frame
546
- pos = (@tag2.valid? ? @file.pos : 0)
546
+ pos = (@tag2.io_position || 0)
547
547
  # seek to where id3v1 tag should be
548
548
  @file.seek(-TAG1_SIZE, IO::SEEK_END)
549
549
  if @file.read(3) == "TAG"
data/lib/mp3info/id3v2.rb CHANGED
@@ -123,13 +123,13 @@ class ID3v2 < DelegateClass(Hash)
123
123
  #TAGS.keys.each { |k| @hash[k] = nil }
124
124
  @hash_orig = {}
125
125
  super(@hash)
126
- @valid = false
126
+ @parsed = false
127
127
  @version_maj = @version_min = nil
128
128
  end
129
129
 
130
130
  # does this tag has been correctly read ?
131
- def valid?
132
- @valid
131
+ def parsed?
132
+ @parsed
133
133
  end
134
134
 
135
135
  # does this tag has been changed ?
@@ -140,7 +140,7 @@ class ID3v2 < DelegateClass(Hash)
140
140
  # full version of this tag (like "2.3.0") or nil
141
141
  # if tag was not correctly read
142
142
  def version
143
- if valid?
143
+ if @version_maj && @version_min
144
144
  "2.#{@version_maj}.#{@version_min}"
145
145
  else
146
146
  nil
@@ -156,29 +156,26 @@ class ID3v2 < DelegateClass(Hash)
156
156
  @unsync, ext_header, experimental, footer = (0..3).collect { |i| flags[i].chr == '1' }
157
157
  raise(ID3v2Error, "can't find version_maj ('#{version_maj}')") unless [2, 3, 4].include?(version_maj)
158
158
  @version_maj, @version_min = version_maj, version_min
159
- @valid = true
160
159
  @tag_length = @io.get_syncsafe
161
- case @version_maj
162
- when 2
163
- read_id3v2_2_frames
164
- when 3, 4
165
- # seek past extended header if present
166
- @io.seek(@io.get_syncsafe - 4, IO::SEEK_CUR) if ext_header
167
- read_id3v2_3_frames
160
+ @io_position = original_pos + @tag_length
161
+
162
+ @parsed = true
163
+ begin
164
+ case @version_maj
165
+ when 2
166
+ read_id3v2_2_frames
167
+ when 3, 4
168
+ # seek past extended header if present
169
+ @io.seek(@io.get_syncsafe - 4, IO::SEEK_CUR) if ext_header
170
+ read_id3v2_3_frames
171
+ end
172
+ rescue ID3v2Error => e
173
+ warn("warning: id3v2 tag not fully parsed: #{e.message}")
168
174
  end
169
175
 
170
- @io.seek(original_pos + @tag_length, IO::SEEK_SET)
171
-
172
- # skip padding zeros at the end of the tag
173
- while @io.getbyte == 0; end
174
-
175
- @io.seek(-1, IO::SEEK_CUR)
176
- @io_position = @io.pos
177
-
178
176
  @hash_orig = @hash.dup
179
177
  #no more reading
180
178
  @io = nil
181
- # we should now have io sitting at the first MPEG frame
182
179
  end
183
180
 
184
181
  # dump tag for writing. Version is always 2.#{WRITE_VERSION}.0.
@@ -264,13 +261,13 @@ class ID3v2 < DelegateClass(Hash)
264
261
  begin
265
262
  Iconv.iconv(@options[:encoding], TEXT_ENCODINGS[encoding], out).first
266
263
  rescue Iconv::Failure
267
- out
264
+ return out
268
265
  end
269
266
  else
270
- out
267
+ return out
271
268
  end
272
269
  else
273
- raw_value
270
+ return raw_value
274
271
  end
275
272
  end
276
273
 
@@ -321,13 +318,13 @@ class ID3v2 < DelegateClass(Hash)
321
318
  puts "add_value_to_tag2" if $DEBUG
322
319
 
323
320
  if size > 50_000_000
324
- raise ID3v2Error, "tag size too big for tag '#{name}'"
321
+ raise ID3v2Error, "tag size is > 50_000_000"
325
322
  end
326
323
 
327
324
  data_io = @io.read(size)
328
325
  data = decode_tag(name, data_io)
329
326
  # remove padding zeros for textual tags
330
- if name =~ /^T/
327
+ if data && name =~ /^T/
331
328
  data.sub!(/\0*$/, '')
332
329
  end
333
330
 
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.10
4
+ version: 0.6.11
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-11-27 00:00:00 +01:00
12
+ date: 2009-01-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements: []
66
66
 
67
67
  rubyforge_project: ruby-mp3info
68
- rubygems_version: 1.2.0
68
+ rubygems_version: 1.3.1
69
69
  signing_key:
70
70
  specification_version: 2
71
71
  summary: ruby-mp3info is a pure-ruby library to retrieve low level informations on mp3 files and manipulate id3v1 and id3v2 tags