forked from gregoriorobles/ptavi-p3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmallsmilhandler.py
executable file
·37 lines (29 loc) · 1.09 KB
/
smallsmilhandler.py
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
from collections import OrderedDict
class smallSMILHandler(ContentHandler):
def __init__(self):
self.tag = []
self.tag_dicc = {
'root-layout': ['width', 'height', 'background-color'],
'region': ['id', 'top', 'bottom', 'right', 'left'],
'img': ['src', 'region', 'begin', 'dur'],
'audio': ['src', 'begin', 'dur'],
'textstream': ['src', 'region']}
def startElement(self, name, attrs):
dicc = OrderedDict()
if name in self.tag_dicc:
dicc['tag'] = name
for attribute in self.tag_dicc[name]:
dicc[attribute] = attrs.get(attribute, "")
self.tag.append(dicc)
def get_tags(self):
return self.tag
if __name__ == "__main__":
parser = make_parser()
cHandler = smallSMILHandler()
parser.setContentHandler(cHandler)
parser.parse(open('karaoke.smil'))
print(cHandler.get_tags())