forked from gregoriorobles/ptavi-p3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmallsmilhandler.py
More file actions
executable file
·81 lines (55 loc) · 1.86 KB
/
smallsmilhandler.py
File metadata and controls
executable file
·81 lines (55 loc) · 1.86 KB
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
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
tags = []
# this are the lists of possible attributes for each tag
regList = ["id", "top", "left", "bottom", "right"]
rootList = ["width", "height", "background-color"]
imgList = ["src", "region", "begin", "dur"]
audList = ["src", "begin", "dur"]
textList = ["src", "region", "fill"]
def findAttValue(string, attrs):
value = attrs.get(string, "")
return value
def findAttrs(dictionary, listing, attrs):
for attribute in listing:
dictionary[attribute] = findAttValue(attribute, attrs)
class SmallSMILHandler(ContentHandler):
def __init__(self):
pass
def startElement(self, name, attrs):
if name == 'root-layout':
rootDict = {'tag': name}
findAttrs(rootDict, rootList, attrs)
tags.append(rootDict)
elif name == 'region':
regDict = {'tag': name}
findAttrs(regDict, regList, attrs)
tags.append(regDict)
elif name == 'img':
imgDict = {'tag': name}
findAttrs(imgDict, imgList, attrs)
tags.append(imgDict)
elif name == 'audio':
audDict = {'tag': name}
findAttrs(audDict, audList, attrs)
tags.append(audDict)
elif name == 'textstream':
textDict = {'tag': name}
findAttrs(textDict, textList, attrs)
tags.append(textDict)
def get_tags(self, file):
parser = make_parser()
cHandler = SmallSMILHandler()
parser.setContentHandler(cHandler)
parser.parse(open(file))
return tags
if __name__ == "__main__":
"""
Test block
"""
parser = make_parser()
cHandler = SmallSMILHandler()
parser.setContentHandler(cHandler)
parser.parse(open('karaoke.smil'))