ruby-mp3info 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 421738e99b09100f70bdf70796c8f700b8a2abfd
4
- data.tar.gz: c3d33ce01228e74e48ceee95696f422800f40323
3
+ metadata.gz: ce2fb0b472edc42655b9a42724e7b1cce5562251
4
+ data.tar.gz: b33e20ee08abbbf98fe6305ea2a2d034389459cf
5
5
  SHA512:
6
- metadata.gz: 8265aa027cb141ea232c63b3209f9b3e4e42d02cae25626078d2e7eed4d7c972f14b4804195e32c58e5eb42a8ede15da3ecc638a6d1329cf5ebce0a8c172ce54
7
- data.tar.gz: f8c3f0d2128173c554f584f0c8b636abe00ae8311b48d4b65003cddc87baf49db074b4fa04fd4f118ad42fa1d65501b95a1634b012055359b9a38a57b2ab401a
6
+ metadata.gz: 9dc4dd6b85ab4a3cda9f826ec5450b046d4a1e57b0bca72f7ca65aa337f532e8124a0491e3e374e74c2a027ed0bc6cb7cf44df2f0e20b0d48ec3923509ffabaf
7
+ data.tar.gz: aa3dc74cf05cc0b8359924814b75059c87853882099b89ed0932b5417791e955bdd4ecedd90c54b831176a076e13ee3855dcdec5a7a67d6d328c8d19c51d808d
data/History.txt CHANGED
@@ -1,4 +1,9 @@
1
- === 0.8.1 / 2013-10-280
1
+ === 0.8.2 / 2013-11-20
2
+
3
+ * better parsing of corrupted mp3 (more robust frame scanning)
4
+ * upgraded license to GPL 3 (previous license (ruby) is compatible)
5
+
6
+ === 0.8.1 / 2013-10-28
2
7
 
3
8
  * test fixes
4
9
  * added dot to temp filename
data/README.md CHANGED
@@ -96,7 +96,7 @@ This task will install any missing dependencies, run the tests/specs, and genera
96
96
 
97
97
  ## License
98
98
 
99
- ruby
99
+ GPL-3.0
100
100
 
101
101
  ## TODO:
102
102
 
data/lib/mp3info.rb CHANGED
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  class Mp3Info
19
19
 
20
- VERSION = "0.8.1"
20
+ VERSION = "0.8.2"
21
21
 
22
22
  LAYER = [ nil, 3, 2, 1]
23
23
  BITRATE = {
@@ -484,9 +484,18 @@ class Mp3Info
484
484
  @io.seek(@first_frame_pos, File::SEEK_SET)
485
485
  loop do
486
486
  head = @io.read(4).unpack("N").first
487
- frame = Mp3Info.get_frames_infos(head)
488
- @io.seek(frame[:size] -4, File::SEEK_CUR)
487
+ begin
488
+ frame = Mp3Info.get_frames_infos(head)
489
+ rescue Mp3InfoInternalError
490
+ begin
491
+ frame = find_next_frame
492
+ rescue Mp3InfoError
493
+ break
494
+ end
495
+ end
496
+
489
497
  yield frame
498
+ @io.seek(frame[:size] -4, File::SEEK_CUR)
490
499
  #puts "frame #{frame_count} len #{frame[:length]} br #{frame[:bitrate]} @io.pos #{@io.pos}"
491
500
  break if @io.eof?
492
501
  end
@@ -518,12 +527,22 @@ private
518
527
  size = 144 * (bitrate*1000.0 / samplerate) + (padding ? 1 : 0)
519
528
  end
520
529
  size = size.to_i
530
+ channel_num = Mp3Info.bits(head, 7,6)
521
531
  { :layer => layer,
522
532
  :bitrate => bitrate,
523
533
  :samplerate => samplerate,
524
534
  :mpeg_version => mpeg_version,
525
535
  :padding => padding,
526
- :size => size }
536
+ :size => size,
537
+ :error_protection => head[16] == 0,
538
+ :private => head[8] == 0,
539
+ :mode_extension => Mp3Info.bits(head, 5, 4),
540
+ :copyright => head[3] == 1,
541
+ :original => head[2] == 1,
542
+ :emphasis => Mp3Info.bits(head, 1, 0),
543
+ :channel_num => channel_num,
544
+ :channel_mode => CHANNEL_MODE[channel_num]
545
+ }
527
546
  end
528
547
 
529
548
  ### parses the id3 tags of the currently open @io
@@ -596,8 +615,7 @@ private
596
615
  raise(Mp3InfoError, "end of file reached") if @io.eof?
597
616
  head = 0xff000000 + (data.getbyte(0) << 16) + (data.getbyte(1) << 8) + data.getbyte(2)
598
617
  begin
599
- Mp3Info.get_frames_infos(head)
600
- return head
618
+ return Mp3Info.get_frames_infos(head)
601
619
  rescue Mp3InfoInternalError
602
620
  @io.seek(-3, IO::SEEK_CUR)
603
621
  end
@@ -629,23 +647,13 @@ private
629
647
 
630
648
  found = false
631
649
 
632
- head = nil
633
650
  5.times do
634
- head = find_next_frame()
651
+ @header = find_next_frame()
635
652
  @first_frame_pos = @io.pos - 4
636
- current_frame = Mp3Info.get_frames_infos(head)
637
- @mpeg_version = current_frame[:mpeg_version]
638
- @layer = current_frame[:layer]
639
- @header[:error_protection] = head[16] == 0 ? true : false
640
- @bitrate = current_frame[:bitrate]
641
- @samplerate = current_frame[:samplerate]
642
- @header[:padding] = current_frame[:padding]
643
- @header[:private] = head[8] == 0 ? true : false
644
- @channel_mode = CHANNEL_MODE[@channel_num = Mp3Info.bits(head, 7,6)]
645
- @header[:mode_extension] = Mp3Info.bits(head, 5,4)
646
- @header[:copyright] = (head[3] == 1 ? true : false)
647
- @header[:original] = (head[2] == 1 ? true : false)
648
- @header[:emphasis] = Mp3Info.bits(head, 1,0)
653
+ [ :mpeg_version, :layer, :channel_mode,
654
+ :channel_num, :bitrate, :samplerate ].each do |var_name|
655
+ instance_variable_set("@#{var_name}", @header[var_name])
656
+ end
649
657
  @vbr = false
650
658
  found = true
651
659
  break
@@ -683,13 +691,10 @@ private
683
691
  stream_size = @io_size - (hastag1? ? TAG1_SIZE : 0) - (@tag2.io_position || 0)
684
692
  @length = ((stream_size << 3)/1000.0)/@bitrate
685
693
  # read the first 100 frames and decide if the mp3 is vbr and needs full scan
686
- begin
687
- bitrate = frame_scan(100).first
688
- if @bitrate != bitrate
689
- @vbr = true
690
- @bitrate, @length = frame_scan
691
- end
692
- rescue Mp3InfoInternalError
694
+ average_bitrate = frame_scan(100).first
695
+ if @bitrate != average_bitrate
696
+ @vbr = true
697
+ @bitrate, @length = frame_scan
693
698
  end
694
699
  end
695
700
  end
@@ -526,13 +526,22 @@ class Mp3InfoTest < Test::Unit::TestCase
526
526
  assert_equal("JStereo", mp3.channel_mode)
527
527
  assert_equal(44100, mp3.samplerate)
528
528
  assert_equal(0.1305625, mp3.length)
529
- assert_equal({:original => true,
530
- :error_protection => false,
531
- :padding => false,
532
- :emphasis => 0,
533
- :private => true,
534
- :mode_extension => 2,
535
- :copyright => false}, mp3.header)
529
+ assert_equal({
530
+ :layer=>3,
531
+ :bitrate=>128,
532
+ :samplerate=>44100,
533
+ :mpeg_version=>1,
534
+ :padding=>false,
535
+ :size=>417,
536
+ :error_protection=>false,
537
+ :private=>true,
538
+ :mode_extension=>2,
539
+ :copyright=>false,
540
+ :original=>true,
541
+ :emphasis=>0,
542
+ :channel_num=>1,
543
+ :channel_mode=>"JStereo"
544
+ }, mp3.header)
536
545
  end
537
546
 
538
547
  def load_string_io(filename = TEMP_FILE)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mp3info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Pierronnet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-28 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '3.10'
19
+ version: '4.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '3.10'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hoe
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '3.5'
33
+ version: '3.7'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '3.5'
40
+ version: '3.7'
41
41
  description: ruby-mp3info read low-level informations and manipulate tags on mp3 files.
42
42
  email:
43
43
  - guillaume.pierronnet@gmail.com
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files:
47
47
  - History.txt
48
48
  - Manifest.txt
49
+ - README.md
49
50
  files:
50
51
  - History.txt
51
52
  - Manifest.txt
@@ -57,7 +58,8 @@ files:
57
58
  - test/test_ruby-mp3info.rb
58
59
  - .gemtest
59
60
  homepage: http://github.com/moumar/ruby-mp3info
60
- licenses: []
61
+ licenses:
62
+ - MIT
61
63
  metadata: {}
62
64
  post_install_message:
63
65
  rdoc_options: