3 #from time import datetime
4 from Tools import Directories
9 import NavigationInstance
11 from Tools.XMLTools import elementsWithTag
12 from ServiceReference import ServiceReference
14 class RecordTimerEntry(timer.TimerEntry):
15 def __init__(self, begin, end, serviceref, epg, description):
16 timer.TimerEntry.__init__(self, int(begin), int(end))
18 assert isinstance(serviceref, ServiceReference)
20 self.service_ref = serviceref
24 #str(epg.m_event_name)
28 self.description = description
30 self.record_service = None
32 def calculateFilename(self):
33 service_name = self.service_ref.getServiceName()
34 # begin_date = datetime.fromtimestamp(begin).strf...
36 if self.epg_data is not None:
37 description = " - " + self.epg_data
41 print "begin_date: " + str(begin_date)
42 print "service_name: " + str(service_name)
43 print "description: " + str(description)
44 self.Filename = Directories.getRecordingFilename(service_name)
45 #begin_date + " - " + service_name + description)
47 # build filename from epg
49 # pff das geht noch nicht...
51 # self.Filename = "recording.ts"
53 # self.Filename = "record_" + str(epg.m_event_name) + ".ts"
55 # print "------------ record filename: %s" % (self.Filename)
58 def activate(self, event):
59 if event == self.EventPrepare:
60 self.calculateFilename()
61 self.record_service = NavigationInstance.instance.recordService(self.service_ref)
62 if self.record_service == None:
63 print "timer record failed."
65 self.record_service.prepare(self.Filename + ".ts")
66 f = open(self.Filename + ".ts.meta", "w")
67 f.write(str(self.service_ref) + "\n")
68 f.write(self.epg_data + "\n")
71 elif self.record_service == None:
72 if event != self.EventAbort:
73 print "timer record start failed, can't finish recording."
74 elif event == self.EventStart:
75 self.record_service.start()
76 print "timer started!"
77 elif event == self.EventEnd or event == self.EventAbort:
78 self.record_service.stop()
79 self.record_service = None
80 print "Timer successfully ended"
84 begin = int(xml.getAttribute("begin"))
85 end = int(xml.getAttribute("end"))
86 serviceref = ServiceReference(str(xml.getAttribute("serviceref")))
87 description = xml.getAttribute("description")
88 epgdata = xml.getAttribute("epgdata")
89 #filename = xml.getAttribute("filename")
90 return RecordTimerEntry(begin, end, serviceref, epgdata, description)
92 class RecordTimer(timer.Timer):
94 timer.Timer.__init__(self)
96 self.Filename = Directories.resolveFilename(Directories.SCOPE_USERETC, "timers.xml")
101 print "unable to load timers from file!"
106 doc = xml.dom.minidom.parse(self.Filename)
108 root = doc.childNodes[0]
109 for timer in elementsWithTag(root.childNodes, "timer"):
110 self.record(createTimer(timer))
113 doc = xml.dom.minidom.Document()
114 root_element = doc.createElement('timers')
115 doc.appendChild(root_element)
116 root_element.appendChild(doc.createTextNode("\n"))
118 for timer in self.timer_list + self.processed_timers:
119 t = doc.createTextNode("\t")
120 root_element.appendChild(t)
121 t = doc.createElement('timer')
122 t.setAttribute("begin", str(timer.begin))
123 t.setAttribute("end", str(timer.end))
124 t.setAttribute("serviceref", str(timer.service_ref))
125 #t.setAttribute("epgdata", timer.)
126 t.setAttribute("description", timer.description)
127 root_element.appendChild(t)
128 t = doc.createTextNode("\n")
129 root_element.appendChild(t)
131 file = open(self.Filename, "w")
132 doc.writexml(codecs.getwriter('UTF-8')(file))
135 def record(self, entry):
137 self.addTimerEntry(entry)
139 def removeEntry(self, entry):
140 if entry.state == timer.TimerEntry.StateRunning:
141 entry.end = time.time()
142 self.timeChanged(entry)
143 elif entry.state != timer.TimerEntry.StateEnded:
144 entry.activate(timer.TimerEntry.EventAbort)
145 self.timer_list.remove(entry)
146 print "timer did not yet start - removing"
148 print "timer did already end - doing nothing."
150 self.calcNextActivation()