def addAutotimerFromSearchString(session, match): from AutoTimerComponent import preferredAutoTimerComponent from AutoTimerImporter import AutoTimerImporter from plugin import autotimer autotimer.readXml() newTimer = autotimer.defaultTimer.clone() newTimer.id = autotimer.getUniqueId() newTimer.name = match newTimer.match = '' newTimer.enabled = True session.openWithCallback( importerCallback, AutoTimerImporter, newTimer, match, # Proposed Match None, # Proposed Begin None, # Proposed End None, # Proposed Disabled None, # Proposed ServiceReference None, # Proposed afterEvent None, # Proposed justplay None, # Proposed dirname, can we get anything useful here? [] # Proposed tags )
def addAutotimerFromSearchString(session, match): from AutoTimerComponent import preferredAutoTimerComponent from AutoTimerImporter import AutoTimerImporter from plugin import autotimer # Create instance if needed if autotimer is None: from AutoTimer import AutoTimer autotimer = AutoTimer() autotimer.readXml() session.openWithCallback( importerCallback, AutoTimerImporter, preferredAutoTimerComponent( autotimer.getUniqueId(), match, '', # Match True # Enabled ), match, # Proposed Match None, # Proposed Begin None, # Proposed End None, # Proposed Disabled None, # Proposed ServiceReference None, # Proposed afterEvent None, # Proposed justplay None, # Proposed dirname, can we get anything useful here? [] # Proposed tags )
def addAutotimerFromService(session, service = None): from AutoTimerComponent import preferredAutoTimerComponent from AutoTimerImporter import AutoTimerImporter from plugin import autotimer autotimer.readXml() serviceHandler = eServiceCenter.getInstance() info = serviceHandler.info(service) match = info and info.getName(service) or "" name = match or "New AutoTimer" sref = info and info.getInfoString(service, iServiceInformation.sServiceref) if sref: # strip all after last : pos = sref.rfind(':') if pos != -1: if sref[pos-1] == ':': pos -= 1 sref = sref[:pos+1] sref = ServiceReference(sref) if info: begin = info.getInfo(service, iServiceInformation.sTimeCreate) end = begin + info.getLength(service) else: begin = end = 0 from os.path import dirname path = dirname(service.getPath()) if not path == '/': path += '/' tags = info.getInfoString(service, iServiceInformation.sTags) tags = tags and tags.split(' ') or [] newTimer = autotimer.defaultTimer.clone() newTimer.id = autotimer.getUniqueId() newTimer.name = name newTimer.match = '' newTimer.enabled = True # XXX: we might want to make sure that we actually collected any data because the importer does not do so :-) session.openWithCallback( importerCallback, AutoTimerImporter, newTimer, match, # Proposed Match begin, # Proposed Begin end, # Proposed End None, # Proposed Disabled sref, # Proposed ServiceReference None, # Proposed afterEvent None, # Proposed justplay path, # Proposed dirname tags # Proposed tags )
def addAutotimerFromEvent(session, evt = None, service = None): from AutoTimerComponent import preferredAutoTimerComponent from AutoTimerImporter import AutoTimerImporter from plugin import autotimer # Create instance if needed if autotimer is None: from AutoTimer import AutoTimer autotimer = AutoTimer() autotimer.readXml() else: autotimer.readXml() match = evt and evt.getEventName() or "" name = match or "New AutoTimer" sref = None if service is not None: service = str(service) myref = eServiceReference(service) if not (myref.flags & eServiceReference.isGroup): # strip all after last : pos = service.rfind(':') if pos != -1: if service[pos-1] == ':': pos -= 1 service = service[:pos+1] sref = ServiceReference(myref) if evt: # timespan defaults to +- 1h begin = evt.getBeginTime()-3600 end = begin + evt.getDuration()+7200 else: begin = end = 0 # XXX: we might want to make sure that we actually collected any data because the importer does not do so :-) newTimer = autotimer.defaultTimer.clone() newTimer.id = autotimer.getUniqueId() newTimer.name = name newTimer.match = '' newTimer.enabled = True session.openWithCallback( importerCallback, AutoTimerImporter, newTimer, match, # Proposed Match begin, # Proposed Begin end, # Proposed End None, # Proposed Disabled sref, # Proposed ServiceReference None, # Proposed afterEvent None, # Proposed justplay None, # Proposed dirname, can we get anything useful here? [] # Proposed tags )
def addAutotimerFromEvent(session, evt = None, service = None): from AutoTimerComponent import preferredAutoTimerComponent from AutoTimerImporter import AutoTimerImporter from plugin import autotimer # Create instance if needed if autotimer is None: from AutoTimer import AutoTimer autotimer = AutoTimer() autotimer.readXml() match = evt and evt.getEventName() or "" name = match or "New AutoTimer" sref = None if service is not None: service = str(service) myref = eServiceReference(service) if not (myref.flags & eServiceReference.isGroup): # strip all after last : pos = service.rfind(':') if pos != -1: if service[pos-1] == ':': pos -= 1 service = service[:pos+1] sref = ServiceReference(myref) if evt: # timespan defaults to +- 1h begin = evt.getBeginTime()-3600 end = begin + evt.getDuration()+7200 else: begin = end = 0 # XXX: we might want to make sure that we actually collected any data because the importer does not do so :-) newTimer = autotimer.defaultTimer.clone() newTimer.id = autotimer.getUniqueId() newTimer.name = name newTimer.match = '' newTimer.enabled = True session.openWithCallback( importerCallback, AutoTimerImporter, newTimer, match, # Proposed Match begin, # Proposed Begin end, # Proposed End None, # Proposed Disabled sref, # Proposed ServiceReference None, # Proposed afterEvent None, # Proposed justplay None, # Proposed dirname, can we get anything useful here? [] # Proposed tags )
def addAutotimerFromEventSilent(session, evt = None, service = None): from plugin import autotimer autotimer.readXml() match = evt and evt.getEventName() or "" name = match or "New AutoTimer" if service is not None: service = str(service) myref = eServiceReference(service) if not (myref.flags & eServiceReference.isGroup): # strip all after last : pos = service.rfind(':') if pos != -1: if service[pos-1] == ':': pos -= 1 service = service[:pos+1] if evt: # timespan defaults to +- 1h begin = evt.getBeginTime()-3600 end = begin + evt.getDuration()+7200 else: begin = end = 0 begin = localtime(begin) end = localtime(end) newTimer = autotimer.defaultTimer.clone() newTimer.id = autotimer.getUniqueId() newTimer.name = name newTimer.match = name if newTimer.timespan[0]: newTimer.timespan = ((begin[3], begin[4]), (end[3], end[4]),False) if newTimer.include: includes = [ newTimer.getIncludedTitle(), newTimer.getIncludedShort(), newTimer.getIncludedDescription(), [str(begin.tm_wday)], ] newTimer.include = includes newTimer.services = [service] newTimer.enabled = True AutoTimerEditorSilentDialog = session.instantiateDialog(AutoTimerEditorSilent, newTimer) retval = AutoTimerEditorSilentDialog.retval() session.deleteDialogWithCallback(editorCallback, AutoTimerEditorSilentDialog, retval)
def render(self, req): def get(name, default=None): ret = req.args.get(name) return ret[0] if ret else default id = get("id") timer = None newTimer = True if id is None: id = autotimer.getUniqueId() timer = autotimer.defaultTimer.clone() timer.id = id else: id = int(id) for possibleMatch in autotimer.getTimerList(): if possibleMatch.id == id: timer = possibleMatch newTimer = False break if timer is None: return self.returnResult(req, False, _("unable to find timer with id %i" % (id,))) if id != -1: # Match timer.match = unquote(get("match", timer.match)) if not timer.match: return self.returnResult(req, False, _("autotimers need a match attribute")) # Name timer.name = unquote(get("name", timer.name)).strip() if not timer.name: timer.name = timer.match # Enabled enabled = get("enabled") if enabled is not None: try: enabled = int(enabled) except ValueError: enabled = enabled == "yes" timer.enabled = enabled # Timeframe before = get("before") after = get("after") if before and after: timer.timeframe = (int(after), int(before)) elif before == "" or after == "": timer.timeframe = None # ... timer.searchType = get("searchType", timer.searchType) timer.searchCase = get("searchCase", timer.searchCase) # Alternatives timer.overrideAlternatives = int(get("overrideAlternatives", timer.overrideAlternatives)) # Justplay justplay = get("justplay") if justplay is not None: try: justplay = int(justplay) except ValueError: justplay = justplay == "zap" timer.justplay = justplay setEndtime = get("setEndtime") if setEndtime is not None: timer.setEndtime = int(setEndtime) # Timespan start = get("timespanFrom") end = get("timespanTo") if start and end: start = [int(x) for x in start.split(":")] end = [int(x) for x in end.split(":")] timer.timespan = (start, end) elif start == "" and end == "": timer.timespan = None # Services servicelist = get("services") if servicelist is not None: servicelist = unquote(servicelist).split(",") appendlist = [] for value in servicelist: myref = eServiceReference(str(value)) if not (myref.flags & eServiceReference.isGroup): # strip all after last : pos = value.rfind(":") if pos != -1: if value[pos - 1] == ":": pos -= 1 value = value[: pos + 1] if myref.valid(): appendlist.append(value) timer.services = appendlist # Bouquets servicelist = get("bouquets") if servicelist is not None: servicelist = unquote(servicelist).split(",") while "" in servicelist: servicelist.remove("") timer.bouquets = servicelist # Offset offset = get("offset") if offset: offset = offset.split(",") if len(offset) == 1: before = after = int(offset[0] or 0) * 60 else: before = int(offset[0] or 0) * 60 after = int(offset[1] or 0) * 60 timer.offset = (before, after) elif offset == "": timer.offset = None # AfterEvent afterevent = get("afterevent") if afterevent: if afterevent == "default": timer.afterevent = [] else: try: afterevent = int(afterevent) except ValueError: afterevent = { "nothing": AFTEREVENT.NONE, "deepstandby": AFTEREVENT.DEEPSTANDBY, "standby": AFTEREVENT.STANDBY, "auto": AFTEREVENT.AUTO, }.get(afterevent, AFTEREVENT.AUTO) start = get("aftereventFrom") end = get("aftereventTo") if start and end: start = [int(x) for x in start.split(":")] end = [int(x) for x in end.split(":")] timer.afterevent = [(afterevent, (start, end))] else: timer.afterevent = [(afterevent, None)] # Maxduration maxduration = get("maxduration") if maxduration: timer.maxduration = int(maxduration) * 60 elif maxduration == "": timer.maxduration = None # Includes title = req.args.get("title") shortdescription = req.args.get("shortdescription") description = req.args.get("description") dayofweek = req.args.get("dayofweek") if title or shortdescription or description or dayofweek: includes = timer.include title = [unquote(x) for x in title] if title else includes[0] shortdescription = [unquote(x) for x in shortdescription] if shortdescription else includes[1] description = [unquote(x) for x in description] if description else includes[2] dayofweek = [unquote(x) for x in dayofweek] if dayofweek else includes[3] while "" in title: title.remove("") while "" in shortdescription: shortdescription.remove("") while "" in description: description.remove("") while "" in dayofweek: dayofweek.remove("") timer.include = (title, shortdescription, description, dayofweek) # Excludes title = req.args.get("!title") shortdescription = req.args.get("!shortdescription") description = req.args.get("!description") dayofweek = req.args.get("!dayofweek") if title or shortdescription or description or dayofweek: excludes = timer.exclude title = [unquote(x) for x in title] if title else excludes[0] shortdescription = [unquote(x) for x in shortdescription] if shortdescription else excludes[1] description = [unquote(x) for x in description] if description else excludes[2] dayofweek = [unquote(x) for x in dayofweek] if dayofweek else excludes[3] while "" in title: title.remove("") while "" in shortdescription: shortdescription.remove("") while "" in description: description.remove("") while "" in dayofweek: dayofweek.remove("") timer.exclude = (title, shortdescription, description, dayofweek) tags = req.args.get("tag") if tags: while "" in tags: tags.remove("") timer.tags = [unquote(x) for x in tags] timer.matchCount = int(get("counter", timer.matchCount)) timer.matchFormatString = get("counterFormat", timer.matchFormatString) if id != -1: matchLeft = get("left") timer.matchLeft = int(matchLeft) if matchLeft else (timer.matchCount if newTimer else timer.matchLeft) timer.matchLimit = get("lastActivation", timer.matchLimit) timer.lastBegin = int(get("lastBegin", timer.lastBegin)) timer.avoidDuplicateDescription = int(get("avoidDuplicateDescription", timer.avoidDuplicateDescription)) timer.searchForDuplicateDescription = int( get("searchForDuplicateDescription", timer.searchForDuplicateDescription) ) timer.destination = get("location", timer.destination) or None # vps enabled = get("vps_enabled") if enabled is not None: try: enabled = int(enabled) except ValueError: enabled = enabled == "yes" timer.vps_enabled = enabled vps_overwrite = get("vps_overwrite") if vps_overwrite is not None: try: vps_overwrite = int(vps_overwrite) except ValueError: vps_overwrite = vps_overwrite == "yes" timer.vps_overwrite = vps_overwrite if not timer.vps_enabled and timer.vps_overwrite: timer.vps_overwrite = False # SeriesPlugin series_labeling = get("series_labeling") if series_labeling is not None: try: series_labeling = int(series_labeling) except ValueError: series_labeling = series_labeling == "yes" timer.series_labeling = series_labeling if newTimer: autotimer.add(timer) message = _("AutoTimer was added successfully") else: message = _("AutoTimer was changed successfully") # Save modified xml if config.plugins.autotimer.always_write_config.value: autotimer.writeXml() return self.returnResult(req, True, message)
def render(self, req): def get(name, default=None): ret = req.args.get(name) return ret[0] if ret else default id = get("id") timer = None newTimer = True if id is None: id = autotimer.getUniqueId() timer = autotimer.defaultTimer.clone() timer.id = id else: id = int(id) for possibleMatch in autotimer.getTimerList(): if possibleMatch.id == id: timer = possibleMatch newTimer = False break if timer is None: return self.returnResult( req, False, _("unable to find timer with id %i" % (id, ))) if id != -1: # Match timer.match = unquote(get("match", timer.match)) if not timer.match: return self.returnResult( req, False, _("autotimers need a match attribute")) # Name timer.name = unquote(get("name", timer.name)).strip() if not timer.name: timer.name = timer.match # Enabled enabled = get("enabled") if enabled is not None: try: enabled = int(enabled) except ValueError: enabled = enabled == "yes" timer.enabled = enabled # Timeframe before = get("before") after = get("after") if before and after: timer.timeframe = (int(after), int(before)) elif before == '' or after == '': timer.timeframe = None # Encoding timer.encoding = get("encoding", timer.encoding) # ... timer.searchType = get("searchType", timer.searchType) timer.searchCase = get("searchCase", timer.searchCase) # Alternatives timer.overrideAlternatives = int( get("overrideAlternatives", timer.overrideAlternatives)) # Justplay justplay = get("justplay") if justplay is not None: try: justplay = int(justplay) except ValueError: justplay = justplay == "zap" timer.justplay = justplay setEndtime = get("setEndtime") if setEndtime is not None: timer.setEndtime = int(setEndtime) # Timespan start = get("timespanFrom") end = get("timespanTo") if start and end: start = [int(x) for x in start.split(':')] end = [int(x) for x in end.split(':')] timer.timespan = (start, end) elif start == '' and end == '': timer.timespan = None # Services servicelist = get("services") if servicelist is not None: servicelist = unquote(servicelist).split(',') appendlist = [] for value in servicelist: myref = eServiceReference(str(value)) if not (myref.flags & eServiceReference.isGroup): # strip all after last : pos = value.rfind(':') if pos != -1: if value[pos - 1] == ':': pos -= 1 value = value[:pos + 1] if myref.valid(): appendlist.append(value) timer.services = appendlist # Bouquets servicelist = get("bouquets") if servicelist is not None: servicelist = unquote(servicelist).split(',') while '' in servicelist: servicelist.remove('') timer.bouquets = servicelist # Offset offset = get("offset") if offset: offset = offset.split(',') if len(offset) == 1: before = after = int(offset[0] or 0) * 60 else: before = int(offset[0] or 0) * 60 after = int(offset[1] or 0) * 60 timer.offset = (before, after) elif offset == '': timer.offset = None # AfterEvent afterevent = get("afterevent") if afterevent: if afterevent == "default": timer.afterevent = [] else: try: afterevent = int(afterevent) except ValueError: afterevent = { "nothing": AFTEREVENT.NONE, "deepstandby": AFTEREVENT.DEEPSTANDBY, "standby": AFTEREVENT.STANDBY, "auto": AFTEREVENT.AUTO }.get(afterevent, AFTEREVENT.AUTO) start = get("aftereventFrom") end = get("aftereventTo") if start and end: start = [int(x) for x in start.split(':')] end = [int(x) for x in end.split(':')] timer.afterevent = [(afterevent, (start, end))] else: timer.afterevent = [(afterevent, None)] # Maxduration maxduration = get("maxduration") if maxduration: timer.maxduration = int(maxduration) * 60 elif maxduration == '': timer.maxduration = None # Includes title = req.args.get("title") shortdescription = req.args.get("shortdescription") description = req.args.get("description") dayofweek = req.args.get("dayofweek") if title or shortdescription or description or dayofweek: includes = timer.include title = [unquote(x) for x in title] if title else includes[0] shortdescription = [unquote(x) for x in shortdescription ] if shortdescription else includes[1] description = [unquote(x) for x in description ] if description else includes[2] dayofweek = [unquote(x) for x in dayofweek] if dayofweek else includes[3] while '' in title: title.remove('') while '' in shortdescription: shortdescription.remove('') while '' in description: description.remove('') while '' in dayofweek: dayofweek.remove('') timer.include = (title, shortdescription, description, dayofweek) # Excludes title = req.args.get("!title") shortdescription = req.args.get("!shortdescription") description = req.args.get("!description") dayofweek = req.args.get("!dayofweek") if title or shortdescription or description or dayofweek: excludes = timer.exclude title = [unquote(x) for x in title] if title else excludes[0] shortdescription = [unquote(x) for x in shortdescription ] if shortdescription else excludes[1] description = [unquote(x) for x in description ] if description else excludes[2] dayofweek = [unquote(x) for x in dayofweek] if dayofweek else excludes[3] while '' in title: title.remove('') while '' in shortdescription: shortdescription.remove('') while '' in description: description.remove('') while '' in dayofweek: dayofweek.remove('') timer.exclude = (title, shortdescription, description, dayofweek) tags = req.args.get("tag") if tags: while '' in tags: tags.remove('') timer.tags = [unquote(x) for x in tags] timer.matchCount = int(get("counter", timer.matchCount)) timer.matchFormatString = get("counterFormat", timer.matchFormatString) if id != -1: matchLeft = get("left") timer.matchLeft = int(matchLeft) if matchLeft else ( timer.matchCount if newTimer else timer.matchLeft) timer.matchLimit = get("lastActivation", timer.matchLimit) timer.lastBegin = int(get("lastBegin", timer.lastBegin)) timer.avoidDuplicateDescription = int( get("avoidDuplicateDescription", timer.avoidDuplicateDescription)) timer.searchForDuplicateDescription = int( get("searchForDuplicateDescription", timer.searchForDuplicateDescription)) timer.destination = get("location", timer.destination) or None # vps enabled = get("vps_enabled") if enabled is not None: try: enabled = int(enabled) except ValueError: enabled = enabled == "yes" timer.vps_enabled = enabled vps_overwrite = get("vps_overwrite") if vps_overwrite is not None: try: vps_overwrite = int(vps_overwrite) except ValueError: vps_overwrite = vps_overwrite == "yes" timer.vps_overwrite = vps_overwrite if not timer.vps_enabled and timer.vps_overwrite: timer.vps_overwrite = False # SeriesPlugin series_labeling = get("series_labeling") if series_labeling is not None: try: series_labeling = int(series_labeling) except ValueError: series_labeling = series_labeling == "yes" timer.series_labeling = series_labeling if newTimer: autotimer.add(timer) message = _("AutoTimer was added successfully") else: message = _("AutoTimer was changed successfully") return self.returnResult(req, True, message)