ruby-ogginfo 0.6.6 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ === 0.6.8 / 2012-02-28
2
+
3
+ * removed :encoding parameter on OggInfo#new
4
+ * utf8 strings are correctly written now in ruby > 1.9
5
+
6
+ === 0.6.7 / 2012-02-27
7
+
8
+ * fixes for ruby 1.9 (again)
9
+
1
10
  === 0.6.6 / 2011-12-23
2
11
 
3
12
  * fixes for ruby 1.9 (thanks to gwolf)
data/README.txt CHANGED
@@ -11,8 +11,7 @@ It is written in pure ruby.
11
11
 
12
12
  == FEATURES/PROBLEMS
13
13
 
14
- * writing tags is not pure ruby yet, need to have "vorbiscomment"
15
- command
14
+ * writing tags is now pure ruby
16
15
 
17
16
  == SYNOPSIS:
18
17
 
data/Rakefile CHANGED
@@ -5,9 +5,10 @@ require 'hoe'
5
5
  Hoe.plugin :yard
6
6
  Hoe.plugin :git
7
7
  Hoe.plugin :rcov
8
+ Hoe.plugin :gemspec
8
9
 
9
10
  Hoe.spec('ruby-ogginfo') do
10
- developer('Guillaume Pierronnet','moumar@rubyforge.org')
11
+ developer('Guillaume Pierronnet','guillaume.pierronnet@gmail.com')
11
12
  developer('Grant Gardner','grant@lastweekend.com.au')
12
13
  #summary = 'ruby-ogginfo is a pure-ruby library that gives low level informations on ogg files'
13
14
  remote_rdoc_dir = ''
@@ -20,6 +20,9 @@ module Ogg::Codecs
20
20
  tag_size.times do |i|
21
21
  size = pio.read(4).unpack("V")[0]
22
22
  comment = pio.read(size)
23
+ unless RUBY_VERSION[0..2] == "1.8"
24
+ comment.force_encoding("UTF-8")
25
+ end
23
26
  key, val = comment.split(/=/, 2)
24
27
  tag[key.downcase] = val
25
28
  end
@@ -39,12 +42,20 @@ module Ogg::Codecs
39
42
  packet_data << [tag.size].pack("V")
40
43
  tag.each do |k,v|
41
44
  tag_data = "#{ k }=#{ v }"
42
- packet_data << [ tag_data.length ].pack("V")
45
+ packet_data << [ binary_size(tag_data) ].pack("V")
43
46
  packet_data << tag_data
44
47
  end
45
48
 
46
49
  packet_data << "\001"
47
50
  packet_data
48
51
  end
52
+
53
+ def binary_size(s)
54
+ if RUBY_VERSION[0..2] == "1.8"
55
+ s.size
56
+ else
57
+ s.bytes.to_a.size
58
+ end
59
+ end
49
60
  end
50
61
  end
data/lib/ogginfo.rb CHANGED
@@ -4,9 +4,8 @@
4
4
  #
5
5
  # License: ruby
6
6
 
7
- require "iconv"
8
7
  require 'forwardable'
9
- require "tempfile"
8
+ require "tmpdir"
10
9
  require File.join(File.dirname(__FILE__), 'ogg.rb')
11
10
 
12
11
  class Hash
@@ -26,7 +25,7 @@ end
26
25
  class OggInfoError < StandardError ; end
27
26
 
28
27
  class OggInfo
29
- VERSION = "0.6.6"
28
+ VERSION = "0.6.8"
30
29
  extend Forwardable
31
30
  include Ogg
32
31
 
@@ -35,10 +34,13 @@ class OggInfo
35
34
  # +tag+ is a hash containing the vorbis tag like "Artist", "Title", and the like
36
35
  attr_reader :tag
37
36
 
38
- # create new instance of OggInfo, using +charset+ to convert tags
39
- def initialize(filename, charset = "utf-8")
37
+ # create new instance of OggInfo
38
+ # use of charset is deprecated! please use utf-8 encoded strings and leave +charset+ to nil")
39
+ def initialize(filename, charset = nil)
40
+ if charset
41
+ warn("use of charset is deprecated! please use utf-8 encoded tags")
42
+ end
40
43
  @filename = filename
41
- @charset = charset
42
44
  @length = nil
43
45
  @bitrate = nil
44
46
  filesize = File.size(@filename)
@@ -57,7 +59,6 @@ class OggInfo
57
59
  end
58
60
  end
59
61
 
60
- convert_tag_charset("utf-8", @charset)
61
62
  @original_tag = @tag.dup
62
63
  end
63
64
 
@@ -98,18 +99,14 @@ class OggInfo
98
99
  # commits any tags to file
99
100
  def close
100
101
  if tag != @original_tag
101
- convert_tag_charset(@charset, "utf-8")
102
-
103
- tempfile = Tempfile.new("ruby-ogginfo")
104
- begin
105
- File.open(@filename, "rb") do | input |
106
- replace_tags(input, tempfile, tag)
107
- end
108
- tempfile.close
109
- FileUtils.cp(tempfile.path, @filename)
110
- ensure
111
- tempfile.close!
102
+ path = File.join(Dir.tmpdir, "ruby-ogginfo_#{$$}.ogg")
103
+ tempfile = File.new(path, "wb")
104
+
105
+ File.open(@filename, "rb") do | input |
106
+ replace_tags(input, tempfile, tag)
112
107
  end
108
+ tempfile.close
109
+ FileUtils.mv(path, @filename)
113
110
  end
114
111
  end
115
112
 
@@ -172,13 +169,4 @@ private
172
169
  FileUtils.copy_stream(reader.input, writer.output)
173
170
  end
174
171
  end
175
-
176
- def convert_tag_charset(from_charset, to_charset)
177
- return if from_charset == to_charset
178
- Iconv.open(to_charset, from_charset) do |ic|
179
- tag.each do |k, v|
180
- tag[k] = ic.iconv(v)
181
- end
182
- end
183
- end
184
172
  end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # encoding: utf-8
2
3
 
3
4
  $:.unshift("lib/")
4
5
 
@@ -130,31 +131,34 @@ class OggInfoTest < Test::Unit::TestCase
130
131
  end
131
132
  end
132
133
 
133
- def test_tag_writing
134
- tag_test("title" => generate_random_string, "artist" => generate_random_string )
134
+ def test_writing_to_spedial_filenames
135
+ tf = generate_ogg
136
+ filename = "fichier éé.ogg"
137
+ FileUtils.cp(tf.path, filename)
138
+ begin
139
+ OggInfo.open(tf.path) do |ogg|
140
+ ogg.tag.title = "a"*200
141
+ end
142
+ #system("ls", "-l", filename)
143
+ ensure
144
+ FileUtils.rm_f(filename)
145
+ end
135
146
  end
136
147
 
137
- def test_big_tags
138
- tag_test("title" => generate_random_string(60000), "artist" => generate_random_string(60000) )
148
+ def test_good_writing_of_utf8_strings
149
+ tag = { "title" => "this is a éé utf8 string",
150
+ "artist" => "and è another one à"}
151
+ tag_test("tag_writing", tag)
139
152
  end
140
-
141
153
 
142
- def test_charset
143
- tf = generate_ogg
144
- OggInfo.open(tf.path, "utf-8") do |ogg|
145
- ogg.tag["title"] = "hello\303\251"
146
- end
154
+ def test_tag_writing
155
+ data = "a"*256
156
+ tag_test("tag_writing", "title" => data, "artist" => data )
157
+ end
147
158
 
148
- OggInfo.open(tf.path, "iso-8859-1") do |ogg|
149
- if RUBY_VERSION[0..2] == '1.8'
150
- assert_equal "hello\xe9", ogg.tag["title"]
151
- else
152
- string = ''
153
- string.force_encoding 'iso-8859-1'
154
- [104, 101, 108, 108, 111, 233].each {|chr| string << chr}
155
- assert_equal string, ogg.tag["title"]
156
- end
157
- end
159
+ def test_big_tags
160
+ data = "a"*60000
161
+ tag_test("big_tags", "title" => data, "artist" => data )
158
162
  end
159
163
 
160
164
  def test_should_not_fail_when_input_is_truncated
@@ -189,7 +193,6 @@ class OggInfoTest < Test::Unit::TestCase
189
193
 
190
194
  protected
191
195
 
192
-
193
196
  def generate_ogg
194
197
  generated_ogg_file_path = File.join(File.dirname(__FILE__), "test.ogg")
195
198
  unless test(?f, generated_ogg_file_path)
@@ -202,10 +205,6 @@ class OggInfoTest < Test::Unit::TestCase
202
205
  tf
203
206
  end
204
207
 
205
- def generate_random_string(size = 256)
206
- File.read("/dev/urandom", size)
207
- end
208
-
209
208
  def generate_truncated_ogg
210
209
  valid_ogg = generate_ogg
211
210
  tf = Tempfile.new("ruby-ogginfo")
@@ -215,7 +214,7 @@ class OggInfoTest < Test::Unit::TestCase
215
214
  tf
216
215
  end
217
216
 
218
- def tag_test(tag)
217
+ def tag_test(test_name, tag)
219
218
  tf = generate_ogg
220
219
 
221
220
  OggInfo.open(tf.path) do |ogg|
@@ -225,6 +224,14 @@ class OggInfoTest < Test::Unit::TestCase
225
224
  OggInfo.open(tf.path) do |ogg|
226
225
  assert_equal tag, ogg.tag
227
226
  end
227
+ system("cp #{tf.path} /tmp/test_#{RUBY_VERSION}_#{test_name}.ogg")
228
228
  test_length
229
+ assert_nothing_raised do
230
+ io = open(tf.path)
231
+ reader = Ogg::Reader.new(io)
232
+ reader.each_pages do |page|
233
+ page
234
+ end
235
+ end
229
236
  end
230
237
  end
@@ -87,40 +87,6 @@ class SpxInfoTest < Test::Unit::TestCase
87
87
  end
88
88
  end
89
89
 
90
-
91
- def test_charset
92
- generate_spx
93
- FileUtils.cp("test.spx",GEN_FILE)
94
- if RUBY_VERSION[0..2] == '1.8'
95
- OggInfo.open(GEN_FILE, "utf-8") do |spx|
96
- assert_equal "hello\303\251",spx.tag["test"]
97
- end
98
-
99
- OggInfo.open(GEN_FILE, "iso-8859-1") do |spx|
100
- assert_equal "hello\xe9", spx.tag["test"]
101
- end
102
-
103
- else
104
- # In Ruby >= 1.9, all strings are UTF-8, and are made up by
105
- # characters (and not anymore bytes). So, we hand-craft it in a
106
- # dumb-enough encoding.
107
- OggInfo.open(GEN_FILE, "utf-8") do |spx|
108
- string = ''
109
- string.force_encoding 'ascii-8bit'
110
- [104, 101, 108, 108, 111, 195, 169].each {|chr| string << chr}
111
- assert_equal string, spx.tag["test"]
112
- end
113
-
114
- OggInfo.open(GEN_FILE, "iso-8859-1") do |spx|
115
- string = ''
116
- string.force_encoding 'iso-8859-1'
117
- [104, 101, 108, 108, 111, 233].each {|chr| string << chr}
118
- assert_equal string, spx.tag["test"]
119
- end
120
-
121
- end
122
- end
123
-
124
90
  def test_tag_writing
125
91
  generate_spx
126
92
  FileUtils.cp("test.spx",GEN_FILE)
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.6.6
4
+ version: 0.6.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-12-23 00:00:00.000000000 +01:00
13
+ date: 2012-02-28 00:00:00.000000000 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rdoc
18
- requirement: &2156269120 !ruby/object:Gem::Requirement
18
+ requirement: &71330730 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '3.10'
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *2156269120
26
+ version_requirements: *71330730
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hoe
29
- requirement: &2156268300 !ruby/object:Gem::Requirement
29
+ requirement: &71330390 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,14 +34,14 @@ dependencies:
34
34
  version: '2.12'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *2156268300
37
+ version_requirements: *71330390
38
38
  description: ! 'ruby-ogginfo gives you access to low level information on ogg files
39
39
 
40
40
  (bitrate, length, samplerate, encoder, etc... ), as well as tag.
41
41
 
42
42
  It is written in pure ruby.'
43
43
  email:
44
- - moumar@rubyforge.org
44
+ - guillaume.pierronnet@gmail.com
45
45
  - grant@lastweekend.com.au
46
46
  executables: []
47
47
  extensions: []
@@ -95,5 +95,5 @@ specification_version: 3
95
95
  summary: ruby-ogginfo gives you access to low level information on ogg files (bitrate,
96
96
  length, samplerate, encoder, etc..
97
97
  test_files:
98
- - test/test_ruby-ogginfo.rb
99
98
  - test/test_ruby-spxinfo.rb
99
+ - test/test_ruby-ogginfo.rb