forked from gregoriorobles/ptavi-p3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smallsmilhandler.py
36 lines (28 loc) · 1.1 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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
class SmallSMILHandler(ContentHandler):
def __init__(self): # Declaramos las listas
self.lista_etiquetas = []
self.attrs = {
'root-layout': ['width', 'height', 'background-color'],
'region': ['id', 'top', 'bottom', 'left', 'right'],
'img': ['src', 'region', 'begin', 'dur'],
'audio': ['src', 'begin', 'dur'],
'textstream': ['src', 'region']}
def startElement(self, name, attrs):
dic = {}
if name in self.attrs:
for atributo in self.attrs[name]:
dic[atributo] = attrs.get(atributo, '')
self.lista_etiquetas.append([name, dic])
# Devuelve una lista con etiquetas, atributos y contenidos encontrados
def get_tags(self):
return self.lista_etiquetas
if __name__ == "__main__":
parser = make_parser()
ssHandler = SmallSMILHandler()
parser.setContentHandler(ssHandler)
parser.parse(open('karaoke.smil'))
print(ssHandler.get_tags())