AutoTimer: add "Fast Scan" support
[vuplus_dvbapp-plugin] / autotimer / src / AutoTimer.py
index 95f706f..ea72e13 100644 (file)
@@ -1,7 +1,7 @@
 # Plugins Config
 from xml.etree.cElementTree import parse as cet_parse
 from os import path as os_path
-from AutoTimerConfiguration import parseConfig, writeConfig
+from AutoTimerConfiguration import parseConfig, buildConfig
 
 # Navigation (RecordTimer)
 import NavigationInstance
@@ -21,7 +21,7 @@ from enigma import eEPGCache, eServiceReference
 from Components.config import config
 
 # AutoTimer Component
-from AutoTimerComponent import AutoTimerComponent
+from AutoTimerComponent import preferredAutoTimerComponent
 
 XML_CONFIG = "/etc/enigma2/autotimer.xml"
 
@@ -60,7 +60,7 @@ class AutoTimer:
                self.timers = []
                self.configMtime = -1
                self.uniqueTimerId = 0
-               self.defaultTimer = AutoTimerComponent(
+               self.defaultTimer = preferredAutoTimerComponent(
                        0,              # Id
                        "",             # Name
                        "",             # Match
@@ -100,8 +100,13 @@ class AutoTimer:
                )
                self.uniqueTimerId = len(self.timers)
 
+       def getXml(self):
+               return buildConfig(self.defaultTimer, self.timers, webif = True)
+
        def writeXml(self):
-               writeConfig(XML_CONFIG, self.defaultTimer, self.timers)
+               file = open(XML_CONFIG, 'w')
+               file.writelines(buildConfig(self.defaultTimer, self.timers))
+               file.close()
 
 # Manage List
 
@@ -162,10 +167,7 @@ class AutoTimer:
                # We include processed timers as we might search for duplicate descriptions
                recorddict = {}
                for timer in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers:
-                       if not recorddict.has_key(str(timer.service_ref)):
-                               recorddict[str(timer.service_ref)] = [timer]
-                       else:
-                               recorddict[str(timer.service_ref)].append(timer)
+                       recorddict.setdefault(str(timer.service_ref), []).append(timer)
 
                # Iterate Timer
                for timer in self.getEnabledTimerList():
@@ -179,7 +181,7 @@ class AutoTimer:
 
                        # Search EPG, default to empty list
                        epgcache = eEPGCache.getInstance()
-                       ret = epgcache.search(('RI', 100, typeMap[timer.searchType], match, caseMap[timer.searchCase])) or []
+                       ret = epgcache.search(('RI', 100, typeMap[timer.searchType], match, caseMap[timer.searchCase])) or ()
 
                        for serviceref, eit in ret:
                                eserviceref = eServiceReference(serviceref)
@@ -228,6 +230,9 @@ class AutoTimer:
                                        begin -= config.recording.margin_before.value * 60
                                        end += config.recording.margin_after.value * 60
 
+                               # Eventually change service to alternative
+                               if timer.overrideAlternatives:
+                                       serviceref = timer.getAlternative(serviceref)
 
                                total += 1
 
@@ -243,7 +248,7 @@ class AutoTimer:
                                # Check for double Timers
                                # We first check eit and if user wants us to guess event based on time
                                # we try this as backup. The allowed diff should be configurable though.
-                               for rtimer in recorddict.get(serviceref, []):
+                               for rtimer in recorddict.get(serviceref, ()):
                                        if rtimer.eit == eit or config.plugins.autotimer.try_guessing.value and getTimeDiff(rtimer, begin, end) > ((duration/10)*8):
                                                oldExists = True
 
@@ -272,7 +277,7 @@ class AutoTimer:
                                                newEntry.service_ref = ServiceReference(serviceref)
 
                                                break
-                                       elif timer.getAvoidDuplicateDescription() == 1 and rtimer.description == description:
+                                       elif timer.avoidDuplicateDescription == 1 and rtimer.description == description:
                                                oldExists = True
                                                print "[AutoTimer] We found a timer with same description, skipping event"
                                                break
@@ -284,7 +289,7 @@ class AutoTimer:
                                                continue
 
                                        # We want to search for possible doubles
-                                       if timer.getAvoidDuplicateDescription() == 2:
+                                       if timer.avoidDuplicateDescription == 2:
                                                # I thinks thats the fastest way to do this, though it's a little ugly
                                                try:
                                                        for list in recorddict.values():
@@ -328,10 +333,7 @@ class AutoTimer:
                                        if conflicts is None:
                                                timer.decrementCounter()
                                                new += 1
-                                               if recorddict.has_key(serviceref):
-                                                       recorddict[serviceref].append(newEntry)
-                                               else:
-                                                       recorddict[serviceref] = [newEntry]
+                                               recorddict.setdefault(serviceref, []).append(newEntry)
 
                return (total, new, modified, timers)