ruby-mp3info 0.6.6 → 0.6.7

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.
@@ -1,3 +1,7 @@
1
+ === 0.6.7 / 2008-06-26
2
+
3
+ * Mp3Info#header hash now gives access to additional mpeg attributes (thanks to Andrew Kuklewicz)
4
+
1
5
  === 0.6.6 / 2008-05-27
2
6
 
3
7
  * avoid reading tag that are too big (> 50Mb)
@@ -1,5 +1,5 @@
1
1
  # coding:utf-8
2
- # $Id: mp3info.rb 88 2008-05-26 22:22:31Z moumar $
2
+ # $Id: mp3info.rb 90 2008-06-26 09:49:38Z moumar $
3
3
  # License:: Ruby
4
4
  # Author:: Guillaume Pierronnet (mailto:moumar_AT__rubyforge_DOT_org)
5
5
  # Website:: http://ruby-mp3info.rubyforge.org/
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  class Mp3Info
20
20
 
21
- VERSION = "0.6.6"
21
+ VERSION = "0.6.7"
22
22
 
23
23
  LAYER = [ nil, 3, 2, 1]
24
24
  BITRATE = [
@@ -120,6 +120,17 @@ class Mp3Info
120
120
  # only used in vbr mode
121
121
  attr_reader(:samples_per_frame)
122
122
 
123
+ # Hash representing values in the MP3 frame header. Keys are one of the following:
124
+ # - :private (boolean)
125
+ # - :copyright (boolean)
126
+ # - :original (boolean)
127
+ # - :padding (boolean)
128
+ # - :error_protection (boolean)
129
+ # - :mode_extension (integer in the 0..3 range)
130
+ # - :emphasis (integer in the 0..3 range)
131
+ # detailled explanation can be found here: http://www.mp3-tech.org/programmer/frame_header.html
132
+ attr_reader(:header)
133
+
123
134
  # length in seconds as a Float
124
135
  attr_reader(:length)
125
136
 
@@ -141,9 +152,6 @@ class Mp3Info
141
152
  # the original filename
142
153
  attr_reader(:filename)
143
154
 
144
- # Moved hastag1? and hastag2? to be booleans
145
- attr_reader(:hastag1, :hastag2)
146
-
147
155
  # Test the presence of an id3v1 tag in file +filename+
148
156
  def self.hastag1?(filename)
149
157
  File.open(filename) { |f|
@@ -186,6 +194,8 @@ class Mp3Info
186
194
  # reload (or load for the first time) the file from disk
187
195
  def reload
188
196
  raise(Mp3InfoError, "empty file") unless File.size?(@filename)
197
+
198
+ @header = {}
189
199
 
190
200
  @tag1 = {}
191
201
  @tag1.extend(HashKeys)
@@ -239,13 +249,16 @@ class Mp3Info
239
249
  @mpeg_version = [2, 1][head[19]]
240
250
  @layer = LAYER[bits(head, 18,17)]
241
251
  next if @layer.nil?
252
+ @header[:error_protection] = head[16] == 0 ? true : false
242
253
  @bitrate = BITRATE[@mpeg_version-1][@layer-1][bits(head, 15,12)-1]
243
- @error_protection = head[16] == 0 ? true : false
244
254
  @samplerate = SAMPLERATE[@mpeg_version-1][bits(head, 11,10)]
245
- @padding = (head[9] == 1 ? true : false)
255
+ @header[:padding] = (head[9] == 1 ? true : false)
256
+ @header[:private] = head[8] == 0 ? true : false
246
257
  @channel_mode = CHANNEL_MODE[@channel_num = bits(head, 7,6)]
247
- @copyright = (head[3] == 1 ? true : false)
248
- @original = (head[2] == 1 ? true : false)
258
+ @header[:mode_extension] = bits(head, 5,4)
259
+ @header[:copyright] = (head[3] == 1 ? true : false)
260
+ @header[:original] = (head[2] == 1 ? true : false)
261
+ @header[:emphasis] = bits(head, 1,0)
249
262
  @vbr = false
250
263
  found = true
251
264
  break
@@ -459,7 +472,7 @@ class Mp3Info
459
472
 
460
473
  # inspect inside Mp3Info
461
474
  def to_s
462
- s = "MPEG #{@mpeg_version} Layer #{@layer} #{@vbr ? "VBR" : "CBR"} #{@bitrate} Kbps #{@channel_mode} #{@samplerate} Hz length #{@length} sec. error protection #{@error_protection} "
475
+ s = "MPEG #{@mpeg_version} Layer #{@layer} #{@vbr ? "VBR" : "CBR"} #{@bitrate} Kbps #{@channel_mode} #{@samplerate} Hz length #{@length} sec. header #{@header.inspect} "
463
476
  s << "tag1: "+@tag1.inspect+"\n" if hastag1?
464
477
  s << "tag2: "+@tag2.inspect+"\n" if hastag2?
465
478
  s
@@ -87,14 +87,20 @@ class Mp3InfoTest < Test::Unit::TestCase
87
87
 
88
88
  def test_detected_info
89
89
  Mp3Info.open(TEMP_FILE) do |info|
90
- assert_equal(info.mpeg_version, 1)
91
- assert_equal(info.layer, 3)
92
- assert_equal(info.vbr, false)
93
- assert_equal(info.bitrate, 128)
94
- assert_equal(info.channel_mode, "JStereo")
95
- assert_equal(info.samplerate, 44100)
96
- assert_equal(info.error_protection, false)
97
- assert_equal(info.length, 0.1305625)
90
+ assert_equal(1, info.mpeg_version)
91
+ assert_equal(3, info.layer)
92
+ assert_equal(false, info.vbr)
93
+ assert_equal(128, info.bitrate)
94
+ assert_equal("JStereo", info.channel_mode)
95
+ assert_equal(44100, info.samplerate)
96
+ assert_equal(0.1305625, info.length)
97
+ assert_equal({:original => true,
98
+ :error_protection => false,
99
+ :padding => false,
100
+ :emphasis => 0,
101
+ :private => true,
102
+ :mode_extension => 2,
103
+ :copyright => false}, info.header)
98
104
  end
99
105
  end
100
106
 
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.6
4
+ version: 0.6.7
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-05-27 00:00:00 +02:00
12
+ date: 2008-06-26 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.5.3
22
+ version: 1.6.0
23
23
  version:
24
24
  description: "* written in pure ruby * read low-level informations like bitrate, length, samplerate, etc... * read, write, remove id3v1 and id3v2 tags * only 2.3 version is supported for writings id3v2 tags == SYNOPSIS: a good exercise is to read the test.rb to understand how the library works deeper require \"mp3info\" # read and display infos & tags Mp3Info.open(\"myfile.mp3\") do |mp3info| puts mp3info end # read/write tag1 and tag2 with Mp3Info#tag attribute # when reading tag2 have priority over tag1 # when writing, each tag is written. Mp3Info.open(\"myfile.mp3\") do |mp3| puts mp3.tag.title puts mp3.tag.artist puts mp3.tag.album puts mp3.tag.tracknum mp3.tag.title = \"track title\" mp3.tag.artist = \"artist name\" end Mp3Info.open(\"myfile.mp3\") do |mp3| # you can access four letter v2 tags like this puts mp3.tag2.TIT2 mp3.tag2.TIT2 = \"new TIT2\" # or like that mp3.tag2[\"TIT2\"] # at this time, only COMM tag is processed after reading and before writing # according to ID3v2#options hash mp3.tag2.options[:lang] = \"FRE\" mp3.tag2.COMM = \"my comment in french, correctly handled when reading and writing\" end"
25
25
  email: moumar@rubyforge.org