ruby-ogginfo 0.3 → 0.3.1

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.3.1 / 2008-03-16
2
+
3
+ * bug fixed #18852 "OggInfo#close(): close @ic only if not nil"
4
+ * bug fixed on encoding handling
5
+
1
6
  === 0.3 / 2008-03-15
2
7
 
3
8
  * write support through "vorbiscomment" binary
data/lib/ogginfo.rb CHANGED
@@ -1,4 +1,4 @@
1
- # $Id: ogginfo.rb 36 2008-03-15 01:01:51Z moumar $
1
+ # $Id: ogginfo.rb 39 2008-03-15 17:21:31Z moumar $
2
2
  #
3
3
  # see http://www.xiph.org/ogg/vorbis/docs.html for documentation on vorbis format
4
4
  # http://www.xiph.org/ogg/vorbis/doc/v-comment.html
@@ -22,7 +22,7 @@ end
22
22
  class OggInfoError < StandardError ; end
23
23
 
24
24
  class OggInfo
25
- VERSION = "0.3"
25
+ VERSION = "0.3.1"
26
26
  attr_reader :channels, :samplerate, :bitrate, :nominal_bitrate, :length
27
27
 
28
28
  # +tag+ is a hash containing the vorbis tag like "Artist", "Title", and the like
@@ -30,18 +30,19 @@ class OggInfo
30
30
 
31
31
  # create new instance of OggInfo, using +charset+ to convert tags to
32
32
  def initialize(filename, charset = "iso-8859-1")
33
- @file = File.new(filename, "rb")
34
- if charset !~ /^utf-?8$/i
35
- @ic = Iconv.new(charset, "utf8")
36
- end
33
+ @filename = filename
34
+ @charset = charset
35
+ @file = File.new(@filename, "rb")
37
36
 
38
37
  find_next_page
39
38
  extract_infos
40
39
  find_next_page
41
- extract_tag(charset)
40
+ extract_tag
41
+ convert_tag_charset("utf-8", @charset)
42
42
  @saved_tag = @tag.dup
43
43
  extract_end
44
44
  @bitrate = @file.stat.size.to_f*8/@length
45
+ @file.close
45
46
  end
46
47
 
47
48
  # "block version" of ::new()
@@ -62,15 +63,14 @@ class OggInfo
62
63
 
63
64
  # write any tags to file
64
65
  def close
65
- @ic.close
66
- @file.close if @file and not @file.closed?
67
66
  if @tag != @saved_tag
68
67
  cmd = %w{vorbiscomment -w}
68
+ convert_tag_charset(@charset, "utf-8")
69
69
 
70
70
  @tag.each do |k,v|
71
71
  cmd.concat(["-t", k.upcase+"="+v])
72
72
  end
73
- cmd << @file.path
73
+ cmd << @filename
74
74
  system(*cmd)
75
75
  end
76
76
  end
@@ -112,7 +112,7 @@ private
112
112
  end
113
113
  end
114
114
 
115
- def extract_tag(charset)
115
+ def extract_tag
116
116
  @tag = {}
117
117
  @file.seek(22, IO::SEEK_CUR)
118
118
  segs = @file.read(1).unpack("C")[0]
@@ -124,9 +124,6 @@ private
124
124
  tag_size.times do |i|
125
125
  size = @file.read(4).unpack("V")[0]
126
126
  comment = @file.read(size)
127
- if @ic
128
- comment = @ic.iconv( com ) rescue comment
129
- end
130
127
  key, val = comment.split(/=/)
131
128
  @tag[key.downcase] = val
132
129
  end
@@ -142,4 +139,12 @@ private
142
139
  @length = 0
143
140
  end
144
141
  end
142
+
143
+ def convert_tag_charset(from_charset, to_charset)
144
+ Iconv.open(to_charset, from_charset) do |ic|
145
+ @tag.each do |k, v|
146
+ @tag[k] = ic.iconv(v)
147
+ end
148
+ end
149
+ end
145
150
  end
@@ -142,6 +142,17 @@ class OggInfoTest < Test::Unit::TestCase
142
142
  end
143
143
  end
144
144
 
145
+ def test_charset
146
+ generate_ogg
147
+ OggInfo.open("test.ogg", "utf-8") do |ogg|
148
+ ogg.tag["title"] = "hello\303\251"
149
+ end
150
+
151
+ OggInfo.open("test.ogg", "iso-8859-1") do |ogg|
152
+ assert_equal "hello\xe9", ogg.tag["title"]
153
+ end
154
+ end
155
+
145
156
  def generate_ogg
146
157
  unless test(?f, "test.ogg")
147
158
  system("dd if=/dev/urandom bs=1024 count=3000 | oggenc -q0 --raw -o test.ogg -") or
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-ogginfo
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.3"
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Pierronnet