vps 0.5
[enigma2-plugins.git] / vps / src_py / Vps.py
1 # -*- coding: utf-8 -*-
2
3 from enigma import eTimer, eConsoleAppContainer, getBestPlayableServiceReference, eServiceReference, eEPGCache
4 from time import time, strftime, localtime
5 from Components.config import config
6 from timer import TimerEntry
7 from Tools import Notifications
8 from Screens.MessageBox import MessageBox
9 from os import access, chmod, X_OK
10 from RecordTimer import RecordTimerEntry, parseEvent
11 from ServiceReference import ServiceReference
12 from Components.TimerSanityCheck import TimerSanityCheck
13 import NavigationInstance
14
15 vps_exe = "/usr/lib/enigma2/python/Plugins/SystemPlugins/vps/vps"
16 if not access(vps_exe, X_OK):
17         chmod(vps_exe, 493)
18
19 class vps_timer:
20         def __init__(self, timer, session):
21                 self.timer = timer
22                 self.session = session
23                 self.program = eConsoleAppContainer()
24                 self.program.dataAvail.append(self.program_dataAvail)
25                 self.program.appClosed.append(self.program_closed)
26                 self.program_running = False
27                 self.program_try_search_running = False
28                 self.last_overwrite_enabled = False
29                 self.activated_auto_increase = False
30                 self.simulate_recordService = None
31                 self.demux = -1
32                 self.rec_ref = None
33                 self.found_pdc = False
34                 self.dont_restart_program = False
35                 self.org_timer_end = 0
36                 self.org_timer_begin = 0
37                 self.next_events = [ ]
38                 
39                 self.program_seek_vps_multiple = eConsoleAppContainer()
40                 self.program_seek_vps_multiple.dataAvail.append(self.program_seek_vps_multiple_dataAvail)
41                 self.program_seek_vps_multiple.appClosed.append(self.program_seek_vps_multiple_closed)
42                 self.program_seek_vps_multiple_started = 0
43                 self.found_vps_multiple = [ ]
44         
45         def program_closed(self, retval):
46                 #print "[VPS-Plugin] Programm hat sich beendet"
47                 self.timer.log(0, "[VPS] stop monitoring (process terminated)")
48                 if self.program_running or self.program_try_search_running:
49                         self.program_running = False
50                         self.program_try_search_running = False
51                         self.stop_simulation()
52         
53         def program_dataAvail(self, str):
54                 #print "[VPS-Plugin] received: "+ str
55                 #try:
56                 if self.timer is None or self.timer.state == TimerEntry.StateEnded or self.timer.cancelled:
57                         self.program_abort()
58                         self.stop_simulation()
59                         return
60                 if self.timer.vpsplugin_enabled == False or config.plugins.vps.enabled.value == False:
61                         if self.activated_auto_increase:
62                                 self.timer.autoincrease = False
63                         self.program_abort()
64                         self.stop_simulation()
65                         return
66                 
67                 lines = str.split("\n")
68                 for line in lines:
69                         data = line.split()
70                         if len(data) < 2:
71                                 continue
72                         
73                         self.timer.log(0, "[VPS] "+ " ".join(data))
74                         
75                         if data[1] == "RUNNING_STATUS":
76                                 if data[2] == "1": # not running
77                                         # Wenn der Eintrag im Following (Section_Number = 1) ist, dann nicht beenden (Sendung begann noch gar nicht)
78                                         if data[3] == "FOLLOWING":
79                                                 if not self.activated_auto_increase and self.timer.state == TimerEntry.StateRunning:
80                                                         self.activate_autoincrease()
81                                         else:
82                                                 if self.timer.state == TimerEntry.StateRunning and not self.set_next_event():
83                                                         self.activated_auto_increase = False
84                                                         self.timer.autoincrease = False
85                                                         
86                                                         if self.timer.vpsplugin_overwrite:
87                                                                 # sofortiger Stopp
88                                                                 self.timer.abort()
89                                                                 self.session.nav.RecordTimer.doActivate(self.timer)
90                                                                 self.stop_simulation()
91                                                         
92                                                         self.dont_restart_program = True
93                                                         self.program_abort()
94                                 
95                                 elif data[2] == "2": # starts in a few seconds
96                                         if self.timer.state == TimerEntry.StateWaiting:
97                                                 self.session.nav.RecordTimer.doActivate(self.timer)
98                                 
99                                 elif data[2] == "3": # pausing
100                                         if self.timer.state == TimerEntry.StateRunning:
101                                                 if not self.activated_auto_increase:
102                                                         self.activate_autoincrease()
103                                 
104                                 elif data[2] == "4": # running
105                                         if self.timer.state == TimerEntry.StateRunning:
106                                                 if not self.timer.vpsplugin_overwrite and (time() - self.timer.begin) < 60:
107                                                         self.program_abort()
108                                                         self.stop_simulation()
109                                                 elif not self.activated_auto_increase:
110                                                         self.activate_autoincrease()
111                                         
112                                         elif self.timer.state == TimerEntry.StateWaiting or self.timer.state == TimerEntry.StatePrepared:
113                                                 # setze Startzeit auf jetzt
114                                                 self.timer.begin = int(time())
115                                                 self.session.nav.RecordTimer.timeChanged(self.timer)
116                                                 
117                                                 if self.timer.vpsplugin_overwrite:
118                                                         self.activate_autoincrease()
119                                                         self.program_abort()
120                                                         self.stop_simulation()
121                                                         vps_timers.checksoon(2000) # Programm neu starten
122                                                 else:
123                                                         self.program_abort()
124                                                         self.stop_simulation()
125                         
126                         elif data[1] == "EVENT_ENDED":
127                                 if not self.set_next_event():
128                                         if self.timer.state == TimerEntry.StateRunning:
129                                                 self.activated_auto_increase = False
130                                                 self.timer.autoincrease = False
131                                                 
132                                                 if self.timer.vpsplugin_overwrite:
133                                                         # sofortiger Stopp
134                                                         self.timer.abort()
135                                                         self.session.nav.RecordTimer.doActivate(self.timer)
136                                                         self.stop_simulation()
137         
138                                                         
139                                         self.program_abort()
140                                         self.stop_simulation()
141                         
142                         elif data[1] == "OTHER_TS_RUNNING_STATUS":
143                                 if self.timer.state == TimerEntry.StateWaiting:
144                                         self.timer.start_prepare = int(time())
145                                         #self.session.nav.RecordTimer.calcNextActivation()
146                                         self.session.nav.RecordTimer.doActivate(self.timer)
147                                 
148                                 self.program_abort()
149                                 self.stop_simulation()
150                                 #self.check()
151                                 vps_timers.checksoon(2000)
152                         
153                         # PDC
154                         elif data[1] == "PDC_FOUND_EVENT_ID":
155                                 self.found_pdc = True
156                                 self.timer.eit = int(data[2])
157                                 epgcache = eEPGCache.getInstance()
158                                 evt = epgcache.lookupEventId(self.rec_ref, self.timer.eit)
159                                 if evt:
160                                         self.timer.name = evt.getEventName()
161                                         self.timer.description = evt.getShortDescription()
162                                 self.program_abort()
163                                 vps_timers.checksoon(500)
164                         
165                         # Fehler
166                         elif data[1] == "DMX_ERROR_TIMEOUT" or data[1] == "DMX_SET_FILTER_ERROR":
167                                 self.program_abort()
168                         
169                         elif data[1] == "EVENT_CURRENTLY_NOT_FOUND" and self.timer.state == TimerEntry.StateRunning:
170                                 self.set_next_event()
171
172                 #except:
173                 #       pass
174         
175         def activate_autoincrease(self):
176                 self.activated_auto_increase = True
177                 self.timer.autoincrease = True
178                 self.timer.autoincreasetime = 60
179                 if self.org_timer_end == 0:
180                         self.org_timer_end = self.timer.end
181                 self.timer.log(0, "[VPS] enable autoincrease")
182         
183         # Noch ein Event aufnehmen?
184         def set_next_event(self):
185                 if not self.timer.vpsplugin_overwrite and len(self.next_events) > 0:
186                         if not self.activated_auto_increase:
187                                 self.activate_autoincrease()
188                         
189                         neweventid = self.next_events[0]
190                         self.timer.eit = neweventid
191                         self.dont_restart_program = False
192                         self.next_events.remove(neweventid)
193                         self.timer.log(0, "[VPS] record now event_id "+ str(neweventid))
194                         self.program_start()
195                         return True
196                 else:
197                         return False
198         
199         def program_abort(self):
200                 if self.program_running or self.program_try_search_running:
201                         #self.program.sendCtrlC()
202                         self.program.kill()
203                         self.program_running = False
204                         self.program_try_search_running = False
205                         self.timer.log(0, "[VPS] stop monitoring")
206         
207         def stop_simulation(self):
208                 if self.simulate_recordService:
209                         NavigationInstance.instance.stopRecordService(self.simulate_recordService)
210                         self.simulate_recordService = None
211                         self.timer.log(0, "[VPS] stop RecordService (simulation)")
212         
213         
214         def program_seek_vps_multiple_closed(self, retval):
215                 self.program_seek_vps_multiple_started = -1
216                 
217                 self.found_vps_multiple = sorted(self.found_vps_multiple)
218                 
219                 for evt_begin, evt_id, evt in self.found_vps_multiple:
220                         # eigenen Timer überprüfen, wenn Zeiten nicht überschrieben werden dürfen
221                         if not self.timer.vpsplugin_overwrite and evt_begin <= self.timer.end:
222                                 self.next_events.append(evt_id)
223                                 self.timer.log(0, "[VPS] add event_id "+ str(evt_id))
224                         
225                         else:
226                                 canbeadded = True
227                                 evt_begin += 60
228                                 evt_end = evt.getBeginTime() + evt.getDuration() - 60
229                                 now = time()
230                                 
231                                 for checktimer in self.session.nav.RecordTimer.timer_list:
232                                         if checktimer == self.timer:
233                                                 continue
234                                         if (checktimer.begin - now) > 3600*24:
235                                                 break
236                                         if checktimer.service_ref.ref.toCompareString() == self.timer.service_ref.ref.toCompareString() or checktimer.service_ref.ref.toCompareString() == self.rec_ref.toCompareString():      
237                                                 if checktimer.begin <= evt_begin and checktimer.end >= evt_end:
238                                                         if not checktimer.vpsplugin_enabled or not checktimer.vpsplugin_overwrite:
239                                                                 canbeadded = False
240                                                         
241                                                         # manuell angelegter Timer mit VPS
242                                                         if checktimer.vpsplugin_enabled and checktimer.name == "" and checktimer.vpsplugin_time is not None:
243                                                                 checktimer.eit = evt_id
244                                                                 checktimer.name = evt.getEventName()
245                                                                 checktimer.description = evt.getShortDescription()
246                                                                 checktimer.vpsplugin_time = None
247                                                                 checktimer.log(0, "[VPS] changed timer (found same PDC-Time as in other VPS-recording)")
248                                                                 canbeadded = False
249                                                                 break
250
251                                 
252                                 if canbeadded:
253                                         newevent_data = parseEvent(evt)
254                                         newEntry = RecordTimerEntry(ServiceReference(self.rec_ref), *newevent_data)
255                                         newEntry.vpsplugin_enabled = True
256                                         newEntry.vpsplugin_overwrite = True
257                                         newEntry.log(0, "[VPS] added this timer (found same PDC-Time as in other VPS-recording)")
258                                         
259                                         # Wenn kein Timer-Konflikt auftritt, wird der Timer angelegt.
260                                         NavigationInstance.instance.RecordTimer.record(newEntry)
261                                 
262         
263         def program_seek_vps_multiple_dataAvail(self, str):
264                 lines = str.split("\n")
265                 for line in lines:
266                         data = line.split()
267                         if len(data) < 2:
268                                 continue
269                         
270                         self.timer.log(0, "[VPS] "+ " ".join(data))
271                         
272                         if data[1] == "PDC_MULTIPLE_FOUND_EVENT":
273                                 neweventid = int(data[2])
274                                 epgcache = eEPGCache.getInstance()
275                                 evt = epgcache.lookupEventId(self.rec_ref, neweventid)
276                                 
277                                 if evt:
278                                         evt_begin = evt.getBeginTime() + 60
279                                         evt_end = evt.getBeginTime() + evt.getDuration() - 60
280                                         
281                                         if evt_begin > self.timer.begin:
282                                                 canbeadded = True
283                                                 now = time()
284                                                 for checktimer in self.session.nav.RecordTimer.timer_list:
285                                                         if checktimer == self.timer:
286                                                                 continue
287                                                         if (checktimer.begin - now) > 3600*24:
288                                                                 break
289                                                         if checktimer.service_ref.ref.toCompareString() == self.timer.service_ref.ref.toCompareString() or checktimer.service_ref.ref.toCompareString() == self.rec_ref.toCompareString():      
290                                                                 if checktimer.eit == neweventid:
291                                                                         canbeadded = False
292                                                                         break
293                                                                 
294                                                                 if checktimer.begin <= evt_begin and checktimer.end >= evt_end:
295                                                                         if checktimer.vpsplugin_enabled is None or checktimer.vpsplugin_enabled == False:
296                                                                                 canbeadded = False
297                                                                                 break
298                                                                                 
299                                                 
300                                                 if canbeadded:
301                                                         self.found_vps_multiple.append((evt_begin-60, neweventid, evt))
302
303         
304         # Suche nach weiteren Events mit selber VPS-Zeit
305         def program_seek_vps_multiple_start(self):
306                 if self.program_seek_vps_multiple_started == 0:
307                         self.program_seek_vps_multiple_started = time()
308                         
309                         self.rec_ref = self.timer.service_ref and self.timer.service_ref.ref
310                         if self.rec_ref and self.rec_ref.flags & eServiceReference.isGroup:
311                                 self.rec_ref = getBestPlayableServiceReference(self.rec_ref, eServiceReference())
312                         elif self.rec_ref is None:
313                                 self.program_seek_vps_multiple_started = -1
314                                 return
315                         
316                         if self.demux == -1:
317                                 stream = self.timer.record_service.stream()
318                                 if stream:
319                                         streamdata = stream.getStreamingData()
320                                         if (streamdata and ('demux' in streamdata)):
321                                                 self.demux = streamdata['demux']
322                                         else:
323                                                 self.program_seek_vps_multiple_started = -1
324                                                 return
325                         
326                         sid = self.rec_ref.getData(1)
327                         tsid = self.rec_ref.getData(2)
328                         onid = self.rec_ref.getData(3)
329                         demux = "/dev/dvb/adapter0/demux" + str(self.demux)
330                         
331                         if self.timer.vpsplugin_time is not None and self.found_pdc:
332                                 day = strftime("%d", localtime(self.timer.vpsplugin_time))
333                                 month = strftime("%m", localtime(self.timer.vpsplugin_time))
334                                 hour = strftime("%H", localtime(self.timer.vpsplugin_time))
335                                 minute = strftime("%M", localtime(self.timer.vpsplugin_time))
336                                 cmd = vps_exe + " "+ demux +" 4 "+ str(onid) +" "+ str(tsid) +" "+ str(sid) +" "+ str(self.timer.eit) +" 0 "+ day +" "+ month +" "+ hour +" "+ minute
337                         else:
338                                 cmd = vps_exe + " "+ demux +" 5 "+ str(onid) +" "+ str(tsid) +" "+ str(sid) +" "+ str(self.timer.eit) +" 0"
339                         
340                         self.program_seek_vps_multiple.execute(cmd)
341                         
342                         self.timer.log(0, "[VPS] seek another events with same PDC-Time")
343         
344         def program_seek_vps_multiple_abort(self):
345                 if self.program_seek_vps_multiple_started > 0:
346                         self.program_seek_vps_multiple.kill()
347                         self.program_seek_vps_multiple_started = -1
348                         self.timer.log(0, "[VPS] abort seeking other pdc-events")
349         
350         # startet den Hintergrundprozess
351         def program_do_start(self, mode):
352                 if self.program_running or self.program_try_search_running:
353                         self.program_abort()
354                 
355                 if mode == 1:
356                         self.demux = 0
357                         self.program_try_search_running = True
358                         self.program_running = False
359                         mode_program = 1
360                 else:
361                         self.program_try_search_running = False
362                         self.program_running = True
363                         mode_program = 0
364                 
365                 sid = self.rec_ref.getData(1)
366                 tsid = self.rec_ref.getData(2)
367                 onid = self.rec_ref.getData(3)
368                 demux = "/dev/dvb/adapter0/demux" + str(self.demux)
369                 
370                 #print "[VPS-Plugin] starte Hintergrundprozess"
371                 
372                 # PDC-Zeit?
373                 if self.timer.name == "" and self.timer.vpsplugin_time is not None and not self.found_pdc:
374                         mode_program += 2
375                         day = strftime("%d", localtime(self.timer.vpsplugin_time))
376                         month = strftime("%m", localtime(self.timer.vpsplugin_time))
377                         hour = strftime("%H", localtime(self.timer.vpsplugin_time))
378                         minute = strftime("%M", localtime(self.timer.vpsplugin_time))
379                         cmd = vps_exe + " "+ demux +" "+ str(mode_program) +" "+ str(onid) +" "+ str(tsid) +" "+ str(sid) +" 0 0 "+ day +" "+ month +" "+ hour +" "+ minute
380                         #print "[VPS-Plugin] "+ cmd
381                         self.timer.log(0, "[VPS] seek PDC-Time")
382                         self.program.execute(cmd)
383                         return
384                 
385                 cmd = vps_exe + " "+ demux +" "+ str(mode_program) +" "+ str(onid) +" "+ str(tsid) +" "+ str(sid) +" "+ str(self.timer.eit) +" 0"
386                 #print "[VPS-Plugin] "+ cmd
387                 self.timer.log(0, "[VPS] start monitoring running-status")
388                 self.program.execute(cmd)
389         
390         
391         def program_start(self):
392                 self.demux = -1
393                 
394                 if self.dont_restart_program:
395                         return
396                 
397                 self.rec_ref = self.timer.service_ref and self.timer.service_ref.ref
398                 if self.rec_ref and self.rec_ref.flags & eServiceReference.isGroup:
399                         self.rec_ref = getBestPlayableServiceReference(self.rec_ref, eServiceReference())
400                 
401                 # recordService (Simulation) ggf. starten
402                 if self.timer.state == TimerEntry.StateWaiting:
403                         if self.simulate_recordService is None:
404                                 if self.rec_ref:
405                                         self.simulate_recordService = NavigationInstance.instance.recordService(self.rec_ref, True)
406                                         if self.simulate_recordService:
407                                                 res = self.simulate_recordService.start()
408                                                 #print "[VPS-Plugin] starte Simulation, res: "+ str(res)
409                                                 self.timer.log(0, "[VPS] start recordService (simulation)")
410                                                 if res != 0 and res != -1:
411                                                         # Fehler aufgetreten (kein Tuner frei?)
412                                                         NavigationInstance.instance.stopRecordService(self.simulate_recordService)
413                                                         self.simulate_recordService = None
414                                                         
415                                                         # in einer Minute ggf. nochmal versuchen
416                                                         if 60 < self.nextExecution:
417                                                                 self.nextExecution = 60
418                                                         
419                                                         # Bei Overwrite versuchen ohne Fragen auf Sender zu schalten
420                                                         if self.timer.vpsplugin_overwrite == True:
421                                                                 cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference()
422                                                                 if cur_ref and not cur_ref.getPath():
423                                                                         self.timer.log(9, "[VPS-Plugin] zap without asking (simulation)")
424                                                                         Notifications.AddNotification(MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n"), type=MessageBox.TYPE_INFO, timeout=20)
425                                                                         NavigationInstance.instance.playService(self.rec_ref)
426                                                                         if 3 < self.nextExecution:
427                                                                                 self.nextExecution = 3
428                                                         else:
429                                                                 # ansonsten versuchen auf dem aktuellen Transponder/Kanal nach Infos zu suchen
430                                                                 if not self.program_try_search_running:
431                                                                         self.program_do_start(1)
432                                                 else: # Simulation hat geklappt
433                                                         if 1 < self.nextExecution:
434                                                                 self.nextExecution = 1
435                         else: # Simulation läuft schon
436                                 # hole Demux
437                                 stream = self.simulate_recordService.stream()
438                                 if stream:
439                                         streamdata = stream.getStreamingData()
440                                         if (streamdata and ('demux' in streamdata)):
441                                                 self.demux = streamdata['demux']
442                                 
443                                 if self.demux == -1:
444                                         # ist noch nicht soweit(?), in einer Sekunde erneut versuchen
445                                         if 1 < self.nextExecution:
446                                                 self.nextExecution = 1
447                                 else:
448                                         self.program_do_start(0)
449                                         
450                 
451                 elif self.timer.state == TimerEntry.StatePrepared or self.timer.state == TimerEntry.StateRunning:
452                         stream = self.timer.record_service.stream()
453                         if stream:
454                                 streamdata = stream.getStreamingData()
455                                 if (streamdata and ('demux' in streamdata)):
456                                         self.demux = streamdata['demux']
457                         if self.demux != -1:
458                                 self.program_do_start(0)
459         
460         
461         # überprüft, ob etwas zu tun ist und gibt die Sekunden zurück, bis die Funktion
462         # spätestens wieder aufgerufen werden sollte
463         # oder -1, um vps_timer löschen zu lassen
464         def check(self):
465                 # Simulation ggf. stoppen
466                 if self.timer.state > TimerEntry.StateWaiting and self.simulate_recordService and self.timer.vpsplugin_overwrite == False:
467                         self.stop_simulation()
468                 
469                 # VPS wurde wieder deaktiviert oder Timer wurde beendet
470                 if self.timer is None or self.timer.state == TimerEntry.StateEnded or self.timer.cancelled:
471                         self.program_abort()
472                         self.stop_simulation()
473                         #print "[VPS-Plugin] Timer wurde beendet"
474                         return -1
475                 
476                 if self.timer.vpsplugin_enabled == False or config.plugins.vps.enabled.value == False:
477                         if self.activated_auto_increase:
478                                 self.timer.autoincrease = False
479                         self.program_abort()
480                         self.stop_simulation()
481                         #print "[VPS-Plugin] VPS wurde bei Timer wieder deaktiviert"
482                         return -1
483                 
484                 self.nextExecution = 180
485                 
486                 if self.timer.vpsplugin_overwrite == True:
487                         if config.plugins.vps.allow_overwrite.value == True:
488                                 self.nextExecution = 60
489                                 if self.timer.state == TimerEntry.StateWaiting or self.timer.state == TimerEntry.StatePrepared:
490                                         # Startzeit verschieben
491                                         if (self.timer.begin - 60) < time():
492                                                 if self.org_timer_begin == 0:
493                                                         self.org_timer_begin = self.timer.begin
494                                                 elif (self.org_timer_begin + (6*3600)) < time():
495                                                         # Sendung begann immer noch nicht -> abbrechen
496                                                         self.timer.abort()
497                                                         self.session.nav.RecordTimer.doActivate(self.timer)
498                                                         self.program_abort()
499                                                         self.stop_simulation()
500                                                         self.timer.log(0, "[VPS] abort timer, waited hours to find Event-ID")
501                                                         return -1
502                                                 
503                                                 self.timer.begin += 60
504                                                 if (self.timer.end - self.timer.begin) < 300:
505                                                         self.timer.end += 180
506                                                         # auf Timer-Konflikt prüfen
507                                                         timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, self.timer)
508                                                         if not timersanitycheck.check():
509                                                                 self.timer.abort()
510                                                                 self.session.nav.RecordTimer.doActivate(self.timer)
511                                                                 self.program_abort()
512                                                                 self.stop_simulation()
513                                                                 self.timer.log(0, "[VPS] abort timer due to TimerSanityCheck")
514                                                                 return -1
515                                                         
516                                                 self.timer.timeChanged()
517                                                 #print "[VPS-Plugin] verschiebe Startzeit des Timers (overwrite)"
518                                         
519                                         if 30 < self.nextExecution:
520                                                 self.nextExecution = 30
521                                 
522                                 if self.last_overwrite_enabled == False:
523                                         self.last_overwrite_enabled = True
524                                 
525                                 # Programm wird auch bei laufendem Timer gestartet
526                                 # mind. 2 Minuten Vorlaufzeit bekommen die VPS-Timer hier
527                                 if self.program_running == False and (config.plugins.vps.initial_time.value < 2 or self.timer.state == TimerEntry.StateRunning):
528                                         if (self.timer.begin - 120) <= time():
529                                                 self.program_start()
530                                         else:
531                                                 n = self.timer.begin - 120 - time()
532                                                 if n < self.nextExecution:
533                                                         self.nextExecution = n
534                         else:
535                                 self.timer.vpsplugin_overwrite = False
536                 
537                 # Wurde Overwrite deaktiviert?
538                 if self.timer.vpsplugin_overwrite == False and self.last_overwrite_enabled == True:
539                         self.last_overwrite_enabled = False
540                         # Wenn der Timer eh schon kurz vor Ende ist, dann Programm nicht beenden.
541                         #if self.program_running == True and (self.timer.end - 180) > time():
542                         self.program_abort()
543                 
544                 # Vorlaufzeit zur Prüfung
545                 if (self.timer.state == TimerEntry.StateWaiting or self.timer.state == TimerEntry.StatePrepared) and self.program_running == False and config.plugins.vps.initial_time.value > 0:
546                         if (self.timer.begin - (config.plugins.vps.initial_time.value * 60)) <= time():
547                                 self.program_start()
548                         else:
549                                 n = self.timer.begin - (config.plugins.vps.initial_time.value * 60) - time()
550                                 if n < self.nextExecution:
551                                         self.nextExecution = n
552                 
553                 # kurz vor (eigentlichem) Ende der Aufnahme Programm starten
554                 if self.timer.state == TimerEntry.StateRunning:
555                         if self.program_running == False:
556                                 if (self.timer.end - 120) <= time():
557                                         self.program_start()
558                                 else:
559                                         n = self.timer.end - 120 - time()
560                                         if n < self.nextExecution:
561                                                 self.nextExecution = n
562                         elif self.program_running == True and (self.timer.end - 120) > time() and self.timer.vpsplugin_overwrite == False:
563                                 self.program_abort()
564                         
565                         if self.activated_auto_increase and self.org_timer_end != 0 and (self.org_timer_end + (4*3600)) < time():
566                                 # Aufnahme läuft seit 4 Stunden im Autoincrease -> abbrechen
567                                 self.timer.autoincrease = False
568                                 self.activated_auto_increase = False
569                                 self.dont_restart_program = True
570                                 self.program_abort()
571                                 self.stop_simulation()
572                                 self.timer.log(0, "[VPS] stop recording, too much autoincrease")
573                 
574                         # suche nach weiteren Sendungen mit der VPS-Zeit
575                         if self.program_seek_vps_multiple_started == 0 and config.plugins.vps.allow_seeking_multiple_pdc.value == True:
576                                 self.program_seek_vps_multiple_start()
577                         elif self.program_seek_vps_multiple_started > 0 and ((time() - self.program_seek_vps_multiple_started) > 60):
578                                 self.program_seek_vps_multiple_abort()
579                 
580                 return self.nextExecution
581
582 class vps:
583         def __init__(self):
584                 self.timer = eTimer()
585                 self.timer.callback.append(self.checkTimer)
586
587                 self.vpstimers = [ ]
588                 self.current_timers_list = [ ]
589                 self.max_activation = 900
590         
591         def checkTimer(self):
592                 nextExecution = self.max_activation
593                 
594                 # nach den Timern schauen und ggf. zur Liste hinzufügen
595                 if config.plugins.vps.enabled.value == True:
596                         now = time()
597                         try:
598                                 for timer in self.session.nav.RecordTimer.timer_list:
599                                         n = timer.begin - now - (config.plugins.vps.initial_time.value * 60) - 120
600                                         if n <= self.max_activation:
601                                                 if timer.vpsplugin_enabled == True and timer not in self.current_timers_list and not timer.justplay and not timer.repeated and not timer.disabled:
602                                                         self.addTimerToList(timer)
603                                                         #print "[VPS-Plugin] neuen VPS-Timer gefunden"
604                                         else:
605                                                 break
606                         except AttributeError:
607                                 print "[VPS-Plugin] AttributeError in Vps.py"
608                                 return
609                 else:
610                         nextExecution = 14400
611                 
612                 # eigene Timer-Liste durchgehen
613                 for o_timer in self.vpstimers[:]:
614                         newtime = int(o_timer.check())
615                         if newtime == -1:
616                                 self.current_timers_list.remove(o_timer.timer)
617                                 self.vpstimers.remove(o_timer)
618                         elif newtime < nextExecution:
619                                 nextExecution = newtime
620                 
621                 if nextExecution <= 0:
622                         nextExecution = 1
623                 
624                 self.timer.startLongTimer(nextExecution)
625                 print "[VPS-Plugin] next execution in "+ str(nextExecution) +" sec" 
626         
627         def addTimerToList(self, timer):
628                 self.vpstimers.append(vps_timer(timer, self.session))
629                 self.current_timers_list.append(timer)
630         
631         def checksoon(self, newstart = 3000):
632                 self.timer.start(newstart, True)
633         
634         def shutdown(self):
635                 for o_timer in self.vpstimers:
636                         o_timer.program_abort()
637                         o_timer.stop_simulation()
638                         o_timer.program_seek_vps_multiple_abort()
639         
640         def NextWakeup(self):
641                 if config.plugins.vps.enabled.value == False or config.plugins.vps.allow_wakeup.value == False:
642                         return -1
643                 
644                 try:
645                         for timer in self.session.nav.RecordTimer.timer_list:
646                                 if timer.vpsplugin_enabled == True and timer.state == TimerEntry.StateWaiting and not timer.justplay and not timer.repeated and not timer.disabled:
647                                         if config.plugins.vps.initial_time.value < 2 and timer.vpsplugin_overwrite:
648                                                 return (timer.begin - 180)
649                                         
650                                         return (timer.begin - (config.plugins.vps.initial_time.value * 60) - 60)
651                 except:
652                         pass
653                 
654                 return -1
655
656 vps_timers = vps()