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