ogginfo-rb 0.0.3 → 0.0.4
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/lib/ogginfo-rb.rb +24 -16
- metadata +2 -2
data/lib/ogginfo-rb.rb
CHANGED
@@ -56,22 +56,8 @@ module Ogg
|
|
56
56
|
|
57
57
|
private
|
58
58
|
def calculate_duration file
|
59
|
-
if file.stat.size > 5000
|
60
|
-
# This seek is a dirty performance hack (saves reading whole file)
|
61
|
-
file.seek(-5000, IO::SEEK_END)
|
62
|
-
else
|
63
|
-
file.rewind
|
64
|
-
end
|
65
|
-
|
66
|
-
# Find last page
|
67
|
-
pg = page = Page.find_page(file)
|
68
|
-
while pg
|
69
|
-
page = pg
|
70
|
-
pg = pg.next_page
|
71
|
-
end
|
72
|
-
|
73
59
|
# Duration is last granule position divided by sample rate
|
74
|
-
return
|
60
|
+
return Page.find_last_page(file).granule_position.to_f / @sample_rate
|
75
61
|
end
|
76
62
|
end
|
77
63
|
|
@@ -131,6 +117,28 @@ module Ogg
|
|
131
117
|
file.pos -= CAPTURE.size
|
132
118
|
return Page.new(file)
|
133
119
|
end
|
120
|
+
|
121
|
+
def self.find_last_page file
|
122
|
+
buffer_size = 1024
|
123
|
+
pos = file.stat.size - buffer_size
|
124
|
+
while pos > 0
|
125
|
+
file.seek pos, IO::SEEK_SET
|
126
|
+
sio = StringIO.new file.read(buffer_size)
|
127
|
+
|
128
|
+
# Find last page in buffer
|
129
|
+
pg = page = Page.find_page(sio)
|
130
|
+
while pg
|
131
|
+
page = pg
|
132
|
+
pg = pg.next_page
|
133
|
+
end
|
134
|
+
return page if page
|
135
|
+
|
136
|
+
pos -= buffer_size * 2 - (CAPTURE.size - 1)
|
137
|
+
end
|
138
|
+
|
139
|
+
# This means that the Ogg file is not valid
|
140
|
+
return nil
|
141
|
+
end
|
134
142
|
end
|
135
143
|
|
136
144
|
class Packet
|
@@ -205,7 +213,7 @@ module Ogg
|
|
205
213
|
length = @data.read(4).unpack('L').first
|
206
214
|
comment = @data.read(length)
|
207
215
|
key, value = comment.split('=', 2)
|
208
|
-
(@comments[key.
|
216
|
+
(@comments[key.upcase] ||= []) << value
|
209
217
|
end
|
210
218
|
end
|
211
219
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ogginfo-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aiden Nibali
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-10 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|