ruby-mp3info 0.6.2 → 0.6.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.
- data/History.txt +4 -0
- data/Rakefile +2 -1
- data/lib/mp3info.rb +2 -3
- data/lib/mp3info/id3v2.rb +21 -11
- metadata +3 -3
data/History.txt
CHANGED
data/Rakefile
CHANGED
data/lib/mp3info.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
# $Id: mp3info.rb
|
1
|
+
# $Id: mp3info.rb 74 2008-03-28 15:11:04Z moumar $
|
2
2
|
# License:: Ruby
|
3
3
|
# Author:: Guillaume Pierronnet (mailto:moumar_AT__rubyforge_DOT_org)
|
4
4
|
# Website:: http://ruby-mp3info.rubyforge.org/
|
5
5
|
|
6
|
-
require "delegate"
|
7
6
|
require "fileutils"
|
8
7
|
require "mp3info/extension_modules"
|
9
8
|
require "mp3info/id3v2"
|
@@ -18,7 +17,7 @@ end
|
|
18
17
|
|
19
18
|
class Mp3Info
|
20
19
|
|
21
|
-
VERSION = "0.6.
|
20
|
+
VERSION = "0.6.3"
|
22
21
|
|
23
22
|
LAYER = [ nil, 3, 2, 1]
|
24
23
|
BITRATE = [
|
data/lib/mp3info/id3v2.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require "
|
1
|
+
require "delegate"
|
2
2
|
require "iconv"
|
3
3
|
|
4
|
+
require "mp3info/extension_modules"
|
5
|
+
|
4
6
|
# This class is not intended to be used directly
|
5
7
|
class ID3v2 < DelegateClass(Hash)
|
6
8
|
|
@@ -89,6 +91,7 @@ class ID3v2 < DelegateClass(Hash)
|
|
89
91
|
|
90
92
|
include Mp3Info::HashKeys
|
91
93
|
|
94
|
+
# this is the position in the file where the tag really ends
|
92
95
|
attr_reader :io_position
|
93
96
|
|
94
97
|
# :+lang+: for writing comments
|
@@ -137,20 +140,29 @@ class ID3v2 < DelegateClass(Hash)
|
|
137
140
|
### gets id3v2 tag information from io object (must support #seek() method)
|
138
141
|
def from_io(io)
|
139
142
|
@io = io
|
143
|
+
original_pos = @io.pos
|
144
|
+
@io.extend(Mp3Info::Mp3FileMethods)
|
140
145
|
version_maj, version_min, flags = @io.read(3).unpack("CCB4")
|
141
146
|
@unsync, ext_header, experimental, footer = (0..3).collect { |i| flags[i].chr == '1' }
|
142
147
|
raise("can't find version_maj ('#{version_maj}')") unless [2, 3, 4].include?(version_maj)
|
143
148
|
@version_maj, @version_min = version_maj, version_min
|
144
149
|
@valid = true
|
145
|
-
|
150
|
+
@tag_length = @io.get_syncsafe
|
146
151
|
case @version_maj
|
147
152
|
when 2
|
148
|
-
read_id3v2_2_frames
|
149
|
-
when 3,4
|
153
|
+
read_id3v2_2_frames
|
154
|
+
when 3, 4
|
150
155
|
# seek past extended header if present
|
151
156
|
@io.seek(@io.get_syncsafe - 4, IO::SEEK_CUR) if ext_header
|
152
|
-
read_id3v2_3_frames
|
157
|
+
read_id3v2_3_frames
|
153
158
|
end
|
159
|
+
|
160
|
+
@io.seek(original_pos + @tag_length, IO::SEEK_SET)
|
161
|
+
|
162
|
+
# skip padding zeros at the end of the tag
|
163
|
+
while @io.getc == 0; end
|
164
|
+
|
165
|
+
@io.seek(-1, IO::SEEK_CUR)
|
154
166
|
@io_position = @io.pos
|
155
167
|
|
156
168
|
@hash_orig = @hash.dup
|
@@ -241,9 +253,8 @@ class ID3v2 < DelegateClass(Hash)
|
|
241
253
|
end
|
242
254
|
|
243
255
|
### reads id3 ver 2.3.x/2.4.x frames and adds the contents to @tag2 hash
|
244
|
-
### tag2_len (fixnum) = length of entire id3v2 data, as reported in header
|
245
256
|
### NOTE: the id3v2 header does not take padding zero's into consideration
|
246
|
-
def read_id3v2_3_frames
|
257
|
+
def read_id3v2_3_frames
|
247
258
|
loop do # there are 2 ways to end the loop
|
248
259
|
name = @io.read(4)
|
249
260
|
if name[0] == 0 or name == "MP3e" #bug caused by old tagging application "mp3ext" ( http://www.mutschler.de/mp3ext/ )
|
@@ -293,14 +304,13 @@ class ID3v2 < DelegateClass(Hash)
|
|
293
304
|
# else
|
294
305
|
# end
|
295
306
|
end
|
296
|
-
break if @io.pos >=
|
307
|
+
break if @io.pos >= @tag_length # 2. reach length from header
|
297
308
|
end
|
298
309
|
end
|
299
310
|
|
300
311
|
### reads id3 ver 2.2.x frames and adds the contents to @tag2 hash
|
301
|
-
### tag2_len (fixnum) = length of entire id3v2 data, as reported in header
|
302
312
|
### NOTE: the id3v2 header does not take padding zero's into consideration
|
303
|
-
def read_id3v2_2_frames
|
313
|
+
def read_id3v2_2_frames
|
304
314
|
loop do
|
305
315
|
name = @io.read(3)
|
306
316
|
if name[0] == 0
|
@@ -310,7 +320,7 @@ class ID3v2 < DelegateClass(Hash)
|
|
310
320
|
else
|
311
321
|
size = (@io.getc << 16) + (@io.getc << 8) + @io.getc
|
312
322
|
add_value_to_tag2(name, size)
|
313
|
-
break if @io.pos >=
|
323
|
+
break if @io.pos >= @tag_length
|
314
324
|
end
|
315
325
|
end
|
316
326
|
end
|
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.3
|
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-03-
|
12
|
+
date: 2008-03-28 00:00:00 +01: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.
|
22
|
+
version: 1.5.1
|
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
|