Tidied up the recording script to use named variables, and added an optional file...
[recordtv.git] / src / rtv_saxhandler.py
blobe775343dcc96762825d9635bfd3322a6ef5461f5
1 #!/usr/bin/python
3 import rtv_programmeinfo, rtv_utils
5 XMLTV_DATETIME_FORMAT = "%Y%m%d%H%M%S"
7 class SaxHandler:
9 def __init__( self, callback ):
10 self.chars = ""
11 self.callback = callback
12 self.title = None
13 self.sub_title = None
14 self.desc = ""
15 self.channel = None
16 self.startTime = None
17 self.endTime = None
19 def parse_time( self, xmltv_time ):
20 # TODO: handle XMLTV time zones
21 return rtv_utils.parse_datetime( xmltv_time[:14],
22 XMLTV_DATETIME_FORMAT )
24 def startElement( self, name, attrs ):
25 if name == "programme":
26 if "start" in attrs:
27 self.startTime = self.parse_time( attrs['start'] )
28 if "stop" in attrs:
29 self.endTime = self.parse_time( attrs['stop'] )
30 if "channel" in attrs:
31 self.channel = attrs['channel']
33 def endElement( self, name ):
34 self.chars = self.chars.strip()
35 if name == "title":
36 self.title = self.chars
37 if name == "sub-title":
38 self.sub_title = self.chars
39 if name == "desc":
40 self.desc = self.chars
41 elif name == "programme" and self.title != None:
43 pi = rtv_programmeinfo.ProgrammeInfo()
44 pi.title = self.title
45 pi.sub_title = self.sub_title
46 pi.description = self.desc
47 pi.channel = self.channel
48 pi.startTime = self.startTime
49 pi.endTime = self.endTime
50 self.callback( pi )
52 self.title = None
53 self.sub_title = None
54 self.desc = ""
55 self.channel = None
56 self.startTime = None
57 self.endTime = None
59 self.chars = ""
61 def characters( self, data ):
62 self.chars += data