-# Format Counter
+# Format counter
from time import strftime
# regular expression
from re import compile as re_compile
+# Alternatives and service restriction
+from enigma import eServiceReference, eServiceCenter
+
+# To get preferred component
+from Components.config import config
+
class AutoTimerComponent(object):
"""AutoTimer Component which also handles validity checks"""
self.setValues('', '', enabled)
"""
- Create a deep copy of this instance
+ Create a deep copy of this instance
"""
def clone(self):
return self.__deepcopy__({})
afterevent = [], exclude = None, maxduration = None, destination = None, \
include = None, matchCount = 0, matchLeft = 0, matchLimit = '', matchFormatString = '', \
lastBegin = 0, justplay = False, avoidDuplicateDescription = 0, bouquets = None, \
- tags = None):
+ tags = None, encoding = 'UTF-8', searchType = "partial", searchCase = "insensitive", \
+ overrideAlternatives = False):
self.name = name
self.match = match
self.enabled = enabled
self.avoidDuplicateDescription = avoidDuplicateDescription
self.bouquets = bouquets
self.tags = tags or []
+ self.encoding = encoding
+ self.searchType = searchType
+ self.searchCase = searchCase
+ self.overrideAlternatives = overrideAlternatives
### Attributes / Properties
- def getCompleteAfterEvent(self):
- return self._afterevent
-
def setAfterEvent(self, afterevent):
- del self._afterevent[:]
- if len(afterevent):
- for definition in afterevent:
- action, timespan = definition
- if timespan is None:
- self._afterevent.append((action, (None,)))
- else:
- self._afterevent.append((action, self.calculateDayspan(*timespan)))
+ if afterevent is not self._afterevent:
+ del self._afterevent[:]
+ else:
+ self._afterevent = []
+
+ for action, timespan in afterevent:
+ if timespan is None or timespan[0] is None:
+ self._afterevent.append((action, (None,)))
+ else:
+ self._afterevent.append((action, self.calculateDayspan(*timespan)))
- afterevent = property(getCompleteAfterEvent, setAfterEvent)
+ afterevent = property(lambda self: self._afterevent, setAfterEvent)
def setBouquets(self, bouquets):
if bouquets:
else:
self._bouquets = []
- def getBouquets(self):
- return self._bouquets
+ bouquets = property(lambda self: self._bouquets , setBouquets)
- bouquets = property(getBouquets, setBouquets)
+ def setEncoding(self, encoding):
+ if encoding:
+ self._encoding = encoding
+
+ encoding = property(lambda self: self._encoding, setEncoding)
def setExclude(self, exclude):
if exclude:
else:
self._exclude = ([], [], [], [])
- def getExclude(self):
- return self._exclude
-
- exclude = property(getExclude, setExclude)
+ exclude = property(lambda self: self._exclude, setExclude)
def setInclude(self, include):
if include:
else:
self._include = ([], [], [], [])
- def getInclude(self):
- return self._include
-
- include = property(getInclude, setInclude)
-
- def setName(self, name):
- self.name = name
+ include = property(lambda self: self._include, setInclude)
- def getMatch(self):
- return self._match
+ def setSearchCase(self, case):
+ assert case in ("sensitive", "insensitive"), "search case must be sensitive or insensitive"
+ self._searchCase = case
- def setMatch(self, match):
- # XXX: a sanity check might be useful...
- self._match = match
+ searchCase = property(lambda self: self._searchCase, setSearchCase)
- match = property(getMatch, setMatch)
+ def setSearchType(self, type):
+ assert type in ("exact", "partial"), "search type must be exact or partial"
+ self._searchType = type
- def getServices(self):
- return self._services
+ searchType = property(lambda self: self._searchType, setSearchType)
def setServices(self, services):
if services:
else:
self._services = []
- services = property(getServices, setServices)
-
- def getTimespan(self):
- return self._timespan
+ services = property(lambda self: self._services, setServices)
def setTimespan(self, timespan):
- if timespan is None or len(timespan) and timespan[0] is None:
+ if timespan is None or timespan and timespan[0] is None:
self._timespan = (None,)
else:
self._timespan = self.calculateDayspan(*timespan)
- timespan = property(getTimespan, setTimespan)
+ timespan = property(lambda self: self._timespan, setTimespan)
### See if Attributes are set
return self.maxduration is not None
def hasTags(self):
- return len(self.tags) > 0
+ return len(self.tags)
def hasTimespan(self):
return self.timespan[0] is not None
return False
return True
else:
- # Check if event begins earlier than our timespan starts
+ # Check if event begins earlier than our timespan starts
if time.tm_hour < begin[0] or (time.tm_hour == begin[0] and time.tm_min < begin[1]):
# Its out of our timespan then
return True
return False
"""
- Returns a list of all allowed services by listing the bouquets
- """
- def getFullServices(self):
- list = self.services[:]
-
- from enigma import eServiceReference, eServiceCenter
- serviceHandler = eServiceCenter.getInstance()
- for bouquet in self.bouquets:
- myref = eServiceReference(str(bouquet))
- mylist = serviceHandler.list(myref)
- if mylist is not None:
- while 1:
- s = mylist.getNext()
- # TODO: I wonder if its sane to assume we get services here (and not just new lists)
- # We can ignore markers & directorys here because they won't match any event's service :-)
- if s.valid():
- # strip all after last :
- value = s.toString()
- pos = value.rfind(':')
- if pos != -1:
- value = value[:pos+1]
-
- list.append(value)
- else:
- break
-
- return list
-
- """
Called when a timer based on this component was added
"""
def update(self, begin, timestamp):
### Makes saving Config easier
- def getAvoidDuplicateDescription(self):
- return self.avoidDuplicateDescription
-
- def getCounter(self):
- return self.matchCount
-
- def getCounterFormatString(self):
- return self.matchFormatString
-
- def getCounterLeft(self):
- return self.matchLeft
-
- def getCounterLimit(self):
- return self.matchLimit
-
- def getDestination(self):
- # XXX: as this function was not added by me (ritzMo) i'll leave it like this but i'm not really sure if this is right ;-)
- return self.destination is not None
-
- def getDuration(self):
- return self.maxduration/60
+ getAvoidDuplicateDescription = lambda self: self.avoidDuplicateDescription
- def getEnabled(self):
- return self.enabled and "yes" or "no"
+ getBouquets = lambda self: self._bouquets
- def getExcludedDays(self):
- return self.exclude[3]
+ getCompleteAfterEvent = lambda self: self._afterevent
- def getExcludedDescription(self):
- return [x.pattern for x in self.exclude[2]]
+ getCounter = lambda self: self.matchCount
+ getCounterFormatString = lambda self: self.matchFormatString
+ getCounterLeft = lambda self: self.matchLeft
+ getCounterLimit = lambda self: self.matchLimit
- def getExcludedShort(self):
- return [x.pattern for x in self.exclude[1]]
+ # XXX: as this function was not added by me (ritzMo) i'll leave it like this but i'm not really sure if this is right ;-)
+ getDestination = lambda self: self.destination is not None
- def getExcludedTitle(self):
- return [x.pattern for x in self.exclude[0]]
+ getDuration = lambda self: self.maxduration/60
- def getIncludedTitle(self):
- return [x.pattern for x in self.include[0]]
+ getEnabled = lambda self: self.enabled and "yes" or "no"
- def getIncludedShort(self):
- return [x.pattern for x in self.include[1]]
+ getExclude = lambda self: self._exclude
+ getExcludedDays = lambda self: self.exclude[3]
+ getExcludedDescription = lambda self: [x.pattern for x in self.exclude[2]]
+ getExcludedShort = lambda self: [x.pattern for x in self.exclude[1]]
+ getExcludedTitle = lambda self: [x.pattern for x in self.exclude[0]]
- def getIncludedDescription(self):
- return [x.pattern for x in self.include[2]]
+ getInclude = lambda self: self._include
+ getIncludedTitle = lambda self: [x.pattern for x in self.include[0]]
+ getIncludedShort = lambda self: [x.pattern for x in self.include[1]]
+ getIncludedDescription = lambda self: [x.pattern for x in self.include[2]]
+ getIncludedDays = lambda self: self.include[3]
- def getIncludedDays(self):
- return self.include[3]
+ getJustplay = lambda self: self.justplay and "1" or "0"
- def getJustplay(self):
- return self.justplay and "1" or "0"
+ getLastBegin = lambda self: self.lastBegin
- def getLastBegin(self):
- return self.lastBegin
+ getMatch = lambda self: self.match
+ getName = lambda self: self.name
- def getName(self):
- return self.name
+ getOffsetBegin = lambda self: self.offset[0]/60
+ getOffsetEnd = lambda self: self.offset[1]/60
- def getOffsetBegin(self):
- return self.offset[0]/60
+ getOverrideAlternatives = lambda self: self.overrideAlternatives and "1" or "0"
- def getOffsetEnd(self):
- return self.offset[1]/60
+ getServices = lambda self: self._services
- def getTags(self):
- return self.tags
+ getTags = lambda self: self.tags
- def getTimespanBegin(self):
- return '%02d:%02d' % (self.timespan[0][0], self.timespan[0][1])
+ getTimespan = lambda self: self._timespan
+ getTimespanBegin = lambda self: '%02d:%02d' % (self.timespan[0][0], self.timespan[0][1])
+ getTimespanEnd = lambda self: '%02d:%02d' % (self.timespan[1][0], self.timespan[1][1])
- def getTimespanEnd(self):
- return '%02d:%02d' % (self.timespan[1][0], self.timespan[1][1])
+ isOffsetEqual = lambda self: self.offset[0] == self.offset[1]
- def isOffsetEqual(self):
- return self.offset[0] == self.offset[1]
-
### Actual functionality
def applyOffset(self, begin, end):
return True
if self.matchLeft > 0:
- self.matchLeft -= 1
return False
return True
if self.maxduration is None:
return False
return length > self.maxduration
-
+
def checkExcluded(self, title, short, extended, dayofweek):
- if len(self.exclude[3]):
- list = [x for x in self.exclude[3]]
- if "weekend" in list:
- list.extend(["5", "6"])
- if "weekday" in list:
- list.extend(["0", "1", "2", "3", "4"])
+ if self.exclude[3]:
+ list = self.exclude[3]
if dayofweek in list:
return True
+ if "weekend" in list and dayofweek in ("5", "6"):
+ return True
+ if "weekday" in list and dayofweek in ("0", "1", "2", "3", "4"):
+ return True
for exclude in self.exclude[0]:
if exclude.search(title):
return self.checkIncluded(title, short, extended, dayofweek)
def checkIncluded(self, title, short, extended, dayofweek):
- if len(self.include[3]):
- list = [x for x in self.include[3]]
+ if self.include[3]:
+ list = self.include[3][:]
if "weekend" in list:
- list.extend(["5", "6"])
+ list.extend(("5", "6"))
if "weekday" in list:
- list.extend(["0", "1", "2", "3", "4"])
+ list.extend(("0", "1", "2", "3", "4"))
if dayofweek not in list:
return True
return False
- def checkServices(self, service):
- if len(self.services) or len(self.bouquets):
- return service not in self.getFullServices()
+ def checkServices(self, check_service):
+ services = self.services
+ bouquets = self.bouquets
+ if services or bouquets:
+ addbouquets = []
+
+ for service in services:
+ if service == check_service:
+ return False
+
+ myref = eServiceReference(str(service))
+ if myref.flags & eServiceReference.isGroup:
+ addbouquets.append(service)
+
+ serviceHandler = eServiceCenter.getInstance()
+ for bouquet in bouquets + addbouquets:
+ myref = eServiceReference(str(bouquet))
+ mylist = serviceHandler.list(myref)
+ if mylist is not None:
+ while 1:
+ s = mylist.getNext()
+ # TODO: I wonder if its sane to assume we get services here (and not just new lists)
+ # We can ignore markers & directorys here because they won't match any event's service :-)
+ if s.valid():
+ # strip all after last :
+ value = s.toString()
+ pos = value.rfind(':')
+ if pos != -1:
+ if value[pos-1] == ':':
+ pos -= 1
+ value = value[:pos+1]
+
+ if value == check_service:
+ return False
+ else:
+ break
+ return True
return False
+ """
+ Return alternative service including a given ref.
+ Note that this only works for alternatives that the autotimer is restricted to.
+ """
+ def getAlternative(self, override_service):
+ services = self.services
+ if services:
+ serviceHandler = eServiceCenter.getInstance()
+
+ for service in services:
+ myref = eServiceReference(str(service))
+ if myref.flags & eServiceReference.isGroup:
+ mylist = serviceHandler.list(myref)
+ if mylist is not None:
+ while 1:
+ s = mylist.getNext()
+ if s.valid():
+ # strip all after last :
+ value = s.toString()
+ pos = value.rfind(':')
+ if pos != -1:
+ if value[pos-1] == ':':
+ pos -= 1
+ value = value[:pos+1]
+
+ if value == override_service:
+ return service
+ else:
+ break
+ return override_service
+
def checkTimespan(self, begin):
return self.checkAnyTimespan(begin, *self.timespan)
+ def decrementCounter(self):
+ if self.matchCount and self.matchLeft > 0:
+ self.matchLeft -= 1
+
def getAfterEvent(self):
for afterevent in self.afterevent:
if afterevent[1][0] is None:
justplay = self.justplay,
avoidDuplicateDescription = self.avoidDuplicateDescription,
bouquets = self.bouquets,
- tags = self.tags
+ tags = self.tags,
+ encoding = self.encoding,
+ searchType = self.searchType,
+ searchCase = self.searchCase,
+ overrideAlternatives = self.overrideAlternatives
)
def __deepcopy__(self, memo):
justplay = self.justplay,
avoidDuplicateDescription = self.avoidDuplicateDescription,
bouquets = self.bouquets[:],
- tags = self.tags[:]
+ tags = self.tags[:],
+ encoding = self.encoding,
+ searchType = self.searchType,
+ searchCase = self.searchCase,
+ overrideAlternatives = self.overrideAlternatives
)
def __eq__(self, other):
- if hasattr(other, "id"):
+ if isinstance(other, AutoTimerComponent):
return self.id == other.id
return False
def __lt__(self, other):
- if hasattr(other, "name"):
+ if isinstance(other, AutoTimerComponent):
return self.name.lower() < other.name.lower()
return False
return not self.__eq__(other)
def __repr__(self):
- return ''.join([
+ return ''.join((
'<AutomaticTimer ',
self.name,
' (',
- ', '.join([
+ ', '.join((
str(self.match),
+ str(self.encoding),
+ str(self.searchCase),
+ str(self.searchType),
str(self.timespan),
str(self.services),
str(self.offset),
str(self.justplay),
str(self.avoidDuplicateDescription),
str(self.bouquets),
- str(self.tags)
- ]),
+ str(self.tags),
+ str(self.overrideAlternatives),
+ )),
")>"
- ])
+ ))
+
+class AutoTimerFastscanComponent(AutoTimerComponent):
+ def __init__(self, *args, **kwargs):
+ AutoTimerComponent.__init__(self, *args, **kwargs)
+ self._fastServices = None
+
+ def setBouquets(self, bouquets):
+ AutoTimerComponent.setBouquets(self, bouquets)
+ self._fastServices = None
+ def setServices(self, services):
+ AutoTimerComponent.setServices(self, services)
+ self._fastServices = None
+
+ def getFastServices(self):
+ if self._fastServices is None:
+ fastServices = []
+ append = fastServices.append
+ addbouquets = []
+ for service in self.services:
+ myref = eServiceReference(str(service))
+ if myref.flags & eServiceReference.isGroup:
+ addbouquets.append(service)
+ else:
+ comp = service.split(':')
+ append(':'.join(comp[3:]))
+
+ serviceHandler = eServiceCenter.getInstance()
+ for bouquet in bouquets + addbouquets:
+ myref = eServiceReference(str(bouquet))
+ mylist = serviceHandler.list(myref)
+ if mylist is not None:
+ while 1:
+ s = mylist.getNext()
+ # TODO: I wonder if its sane to assume we get services here (and not just new lists)
+ # We can ignore markers & directorys here because they won't match any event's service :-)
+ if s.valid():
+ # strip all after last :
+ value = s.toString()
+ pos = value.rfind(':')
+ if pos != -1:
+ if value[pos-1] == ':':
+ pos -= 1
+ value = value[:pos+1]
+
+ comp = value.split(':')
+ append(':'.join(value[3:]))
+ else:
+ break
+ self._fastServices = fastServices
+ return self._fastServices
+
+ def checkServices(self, check_service):
+ services = self.getFastServices()
+ if services:
+ check = ':'.join(check_service.split(':')[3:])
+ for service in services:
+ if service == check:
+ return False # included
+ return True # not included
+ return False # no restriction
+
+ def getAlternative(self, override_service):
+ services = self.services
+ if services:
+ override = ':'.join(override_service.split(':')[3:])
+ serviceHandler = eServiceCenter.getInstance()
+
+ for service in services:
+ myref = eServiceReference(str(service))
+ if myref.flags & eServiceReference.isGroup:
+ mylist = serviceHandler.list(myref)
+ if mylist is not None:
+ while 1:
+ s = mylist.getNext()
+ if s.valid():
+ # strip all after last :
+ value = s.toString()
+ pos = value.rfind(':')
+ if pos != -1:
+ if value[pos-1] == ':':
+ pos -= 1
+ value = value[:pos+1]
+
+ if ':'.join(value.split(':')[3:]) == override:
+ return service
+ else:
+ break
+ return override_service
+
+# very basic factory ;-)
+preferredAutoTimerComponent = lambda *args, **kwargs: AutoTimerFastscanComponent(*args, **kwargs) if config.plugins.autotimer.fastscan.value else AutoTimerComponent(*args, **kwargs)