-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkvinfo.rb
70 lines (61 loc) · 1.53 KB
/
mkvinfo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/ruby
#
# Distributed under the MIT license
# see the file COPYING for details
# or visit http://www.opensource.org/licenses/mit-license.php
#
# $Id: mkvinfo.rb 786 2004-09-12 10:07:43Z mosu $
#
# A Matroska file parsing information tool. It'll read
# all elements as they're found and output the resulting
# tree including the element contents.
#
# Written by Moritz Bunkus <[email protected]>.
#
require "ebml"
def dump_rec(element, level = 0)
print("|") if (level > 1)
1.upto(level - 1) { print(" ") }
print("+ ") if (level > 0)
print(element.class.name.gsub(/^Ebml::/, "Ebml").gsub(/^Matroska::/, ""))
if (!element.master?)
print(" (" + element.to_s + ")")
end
puts(" at " + element.pos.to_s)
if (element.master?)
element.children.each { |c| dump_rec(c, level + 1) }
end
end
def handle_segment(element, f)
dump_rec(element)
while (true)
element = f.read_element_head
return if (element.class == NilClass)
element.read(f)
dump_rec(element, 1)
end
end
ARGV.each do |name|
io = File.new(name)
f = Ebml::File.new(io)
f.map_ids("Matroska")
element = f.read_element_head
if ((element.class == NilClass) or
(element.class.global_id != Ebml::Head.global_id))
puts("No EBML file")
exit(1)
end
element.read(f)
dump_rec(element)
while (true)
element.skip(f)
element = f.read_element_head
break if (element.class == NilClass)
if (element.class == Matroska::Segment)
handle_segment(element, f)
else
dump_rec(element)
end
end
io.close
end