def addTimer(session, serviceref, begin, end, name, description, disabled, justplay, afterevent, dirname, tags, repeated, logentries=None, eit=0): rt = session.nav.RecordTimer if not dirname: dirname = preferredTimerPath() try: timer = RecordTimerEntry(ServiceReference(serviceref), begin, end, name, description, eit, disabled, justplay, afterevent, dirname=dirname, tags=tags) if repeated: timer.repeated = 1 else: timer.repeated = 0 if logentries: timer.log_entries = logentries conflicts = rt.record(timer) if conflicts: errors = [] for conflict in conflicts: errors.append(conflict.name) return { "result": False, "message": "Conflicting Timer(s) detected! %s" % " / ".join(errors) } except Exception, e: print e return {"result": False, "message": "Could not add timer '%s'!" % name}
def KeyOk(self): sel = self["list"].getCurrent()[0] if (sel == "searchEPGe2"): if self.epgserchplugin: self.epgserchplugin(session=self.session, servicelist=self) elif (sel == "searchEPG"): if config.dbp.usevkeyboard.value: self.session.openWithCallback(self.beginSearch, VirtualKeyBoard, title = _("Enter event to search:"), text = "") else: self.session.openWithCallback(self.beginSearch,InputBox, title = _("Enter event to search:"), windowTitle = _("Search in EPG cache"), text="") elif (sel == "searchEPGLast"): self.session.open(NEpgSearchLast) elif (sel == "downloadEPG"): if self.checkDevice(): self.ref = self.session.nav.getCurrentlyPlayingServiceReference() if config.nemepg.downskyit.value: self.downloadItEPG() elif config.nemepg.downskyuk.value: self.downloadUkEPG() elif (sel == "e2LoaderEpg") or (sel == "e2LoaderEpgI"): self.downIMode = { 'e2LoaderEpg':False, 'e2LoaderEpgI':True }[sel] msg = _('Do you want download EPG\nusing e2_loadepg?') self.epgDBox = self.session.openWithCallback(self.downEPG,MessageBox, msg, MessageBox.TYPE_YESNO) self.epgDBox.setTitle(_("Download EPG")) elif (sel == "reloadEPG"): if self.e2Loader: searchPaths = ['/tmp/%s','/media/usb/%s','/media/cf/%s','/media/hdd/%s'] for path in searchPaths: epgFile = (path % 'ext.epg.dat') if fileExists(epgFile): system("mv " + epgFile + " " + config.nemepg.path.value + "/epg.dat") msg = _('Load EPG data in Enigma cache from:\n%s/epg.dat.\nPlease Wait...') % config.nemepg.path.value self.epgRBox = self.session.open(MessageBox, msg, MessageBox.TYPE_INFO) self.epgRBox.setTitle(_("Loading EPG")) self.reloadEPGTimer.start(500, False) elif (sel == "eraseEPG"): msg = _('Erasing EPG Chache.\nPlease Wait...') self.epgCBox = self.session.open(MessageBox, msg, MessageBox.TYPE_INFO) self.epgCBox.setTitle(_("Erasing EPG cache")) self.clearEPGTimer.start(500, False) elif (sel == "backupEPG"): msg = _('Backup Enigma EPG data on:\n%s.\nPlease Wait...') % config.nemepg.path.value self.epgBBox = self.session.open(MessageBox, msg, MessageBox.TYPE_INFO) self.epgBBox.setTitle(_("Backing-up EPG")) self.saveEPGTimer.start(500, False) elif (sel == "createTIMER"): serviceref = ServiceReference(getSid(config.nemepg.skyitch.value)) begin = 1239332400 end = 1239333600 name = "Download EPG Daily" description = "Please do not remove this entry!" timer = RecordTimerEntry(serviceref, begin, end, name, description, 66, False, 2, 1) timer.repeated = 127 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer) elif (sel == "openTIMER"): self.session.open(TimerEditList) elif (sel == "epglog"): self.session.open(dbpShowPanel, '/usr/log/crossepg.log' ,_('EPG Timer log')) elif (sel == "configEPG"): self.session.openWithCallback(self.saveConfig, NSetup, "epg")
def addTimer(session, serviceref, begin, end, name, description, disabled, justplay, afterevent, dirname, tags, repeated, logentries=None, eit=0): rt = session.nav.RecordTimer if not dirname: dirname = preferredTimerPath() try: timer = RecordTimerEntry( ServiceReference(serviceref), begin, end, name, description, eit, disabled, justplay, afterevent, dirname=dirname, tags=tags) if repeated: timer.repeated = 1 else: timer.repeated = 0 if logentries: timer.log_entries = logentries conflicts = rt.record(timer) if conflicts: errors = [] for conflict in conflicts: errors.append(conflict.name) return { "result": False, "message": "Conflicting Timer(s) detected! %s" % " / ".join(errors) } except Exception, e: print e return { "result": False, "message": "Could not add timer '%s'!" % name }
def addTimer(session, serviceref, begin, end, name, description, disabled, justplay, afterevent, dirname, tags, repeated, vpsinfo=None, logentries=None, eit=0, always_zap=-1): serviceref = unquote(serviceref) rt = session.nav.RecordTimer print "mao1", dirname if not dirname: dirname = preferredTimerPath() print "mao2", dirname try: timer = RecordTimerEntry( ServiceReference(serviceref), begin, end, name, description, eit, disabled, justplay, afterevent, dirname=dirname, tags=tags) timer.repeated = repeated if logentries: timer.log_entries = logentries conflicts = rt.record(timer) if conflicts: errors = [] for conflict in conflicts: errors.append(conflict.name) return { "result": False, "message": _("Conflicting Timer(s) detected! %s") % " / ".join(errors) } #VPS if vpsinfo is not None: timer.vpsplugin_enabled = vpsinfo["vpsplugin_enabled"] timer.vpsplugin_overwrite = vpsinfo["vpsplugin_overwrite"] timer.vpsplugin_time = vpsinfo["vpsplugin_time"] if always_zap <> -1: if hasattr(timer,"always_zap"): timer.always_zap = always_zap == 1 except Exception, e: print e return { "result": False, "message": _("Could not add timer '%s'!") % name }
def getTimers(self): self._timer_list = [] self._processed_timers = [] baseurl = self.getBaseUrl() print("[ClientModeBoxRemoteTimer] get remote timer list") try: httprequest = urllib2.urlopen(baseurl + '/web/timerlist') xmldoc = minidom.parseString(httprequest.read()) timers = xmldoc.getElementsByTagName('e2timer') for timer in timers: serviceref = ServiceReference(getValueFromNode(timer, 'e2servicereference')) begin = int(getValueFromNode(timer, 'e2timebegin')) end = int(getValueFromNode(timer, 'e2timeend')) name = getValueFromNode(timer, 'e2name') description = getValueFromNode(timer, 'e2description') eit = int(getValueFromNode(timer, 'e2eit')) disabled = int(getValueFromNode(timer, 'e2disabled')) justplay = int(getValueFromNode(timer, 'e2justplay')) afterevent = int(getValueFromNode(timer, 'e2afterevent')) repeated = int(getValueFromNode(timer, 'e2repeated')) location = getValueFromNode(timer, 'e2location') tags = getValueFromNode(timer, 'e2tags').split(" ") entry = RecordTimerEntry(serviceref, begin, end, name, description, eit, disabled, justplay, afterevent, dirname=location, tags=tags, descramble=1, record_ecm=0, isAutoTimer=0, always_zap=0) entry.repeated = repeated entry.orig = RecordTimerEntry(serviceref, begin, end, name, description, eit, disabled, justplay, afterevent, dirname=location, tags=tags, descramble=1, record_ecm=0, isAutoTimer=0, always_zap=0) entry.orig.repeated = repeated if entry.shouldSkip() or entry.state == TimerEntry.StateEnded or (entry.state == TimerEntry.StateWaiting and entry.disabled): insort(self._processed_timers, entry) else: insort(self._timer_list, entry) except Exception as e: print("[ClientModeBoxRemoteTimer]", e) self.last_update_ts = time()
def getTimers(self): self._timer_list = [] self._processed_timers = [] baseurl = self.getBaseUrl() print "[GBIpboxRemoteTimer] get remote timer list" try: httprequest = urllib2.urlopen(baseurl + '/web/timerlist') xmldoc = minidom.parseString(httprequest.read()) timers = xmldoc.getElementsByTagName('e2timer') for timer in timers: serviceref = ServiceReference(getValueFromNode(timer, 'e2servicereference')) begin = int(getValueFromNode(timer, 'e2timebegin')) end = int(getValueFromNode(timer, 'e2timeend')) name = getValueFromNode(timer, 'e2name') description = getValueFromNode(timer, 'e2description') eit = int(getValueFromNode(timer, 'e2eit')) disabled = int(getValueFromNode(timer, 'e2disabled')) justplay = int(getValueFromNode(timer, 'e2justplay')) afterevent = int(getValueFromNode(timer, 'e2afterevent')) repeated = int(getValueFromNode(timer, 'e2repeated')) location = getValueFromNode(timer, 'e2location') tags = getValueFromNode(timer, 'e2tags').split(" ") entry = RecordTimerEntry(serviceref, begin, end, name, description, eit, disabled, justplay, afterevent, dirname = location, tags = tags, descramble = 1, record_ecm = 0, isAutoTimer = 0, always_zap = 0) entry.repeated = repeated entry.orig = RecordTimerEntry(serviceref, begin, end, name, description, eit, disabled, justplay, afterevent, dirname = location, tags = tags, descramble = 1, record_ecm = 0, isAutoTimer = 0, always_zap = 0) entry.orig.repeated = repeated if entry.shouldSkip() or entry.state == TimerEntry.StateEnded or (entry.state == TimerEntry.StateWaiting and entry.disabled): insort(self._processed_timers, entry) else: insort(self._timer_list, entry) except Exception, e: print "[GBIpboxRemoteTimer]", e
def addTimer(session, serviceref, begin, end, name, description, disabled, justplay, afterevent, dirname, tags, repeated, recordingtype, vpsinfo=None, logentries=None, eit=0, always_zap=-1, pipzap=-1, allow_duplicate=1, autoadjust=-1): rt = session.nav.RecordTimer if not dirname: dirname = preferredTimerPath() # IPTV Fix serviceref = serviceref.replace('%253a', '%3a') try: timer = RecordTimerEntry(ServiceReference(serviceref), begin, end, name, description, eit, disabled, justplay, afterevent, dirname=dirname, tags=tags) timer.repeated = repeated if logentries: timer.log_entries = logentries conflicts = rt.record(timer) if conflicts: errors = [] conflictinfo = [] for conflict in conflicts: errors.append(conflict.name) conflictinfo.append({ "serviceref": str(conflict.service_ref), "servicename": conflict.service_ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', ''), "name": conflict.name, "begin": conflict.begin, "end": conflict.end, "realbegin": strftime(_("%d.%m.%Y %H:%M"), (localtime(float(conflict.begin)))), "realend": strftime(_("%d.%m.%Y %H:%M"), (localtime(float(conflict.end)))) }) return { "result": False, "message": _("Conflicting Timer(s) detected! %s") % " / ".join(errors), "conflicts": conflictinfo } # VPS if vpsinfo is not None: timer.vpsplugin_enabled = vpsinfo["vpsplugin_enabled"] timer.vpsplugin_overwrite = vpsinfo["vpsplugin_overwrite"] timer.vpsplugin_time = vpsinfo["vpsplugin_time"] if always_zap != -1: if hasattr(timer, "always_zap"): timer.always_zap = always_zap == 1 if hasattr(timer, "zapbeforerecord"): timer.zapbeforerecord = always_zap == 1 if hasattr(timer, "autoadjust"): if autoadjust == -1: autoadjust = config.recording.adjust_time_to_event.value and 1 or 0 autoadjust = autoadjust if hasattr(timer, "allow_duplicate"): allow_duplicate = allow_duplicate if pipzap != -1: if hasattr(timer, "pipzap"): timer.pipzap = pipzap == 1 if recordingtype: timer.descramble = { "normal": True, "descrambled": True, "scrambled": False, }[recordingtype] timer.record_ecm = { "normal": False, "descrambled": True, "scrambled": True, }[recordingtype] except Exception as e: print(str(e)) return { "result": False, "message": _("Could not add timer '%s'!") % name } return {"result": True, "message": _("Timer '%s' added") % name}
def editTimer(self, param): print("[WebComponents.Timer] editTimer") #OK first we need to parse all of your Parameters #For some of them (like afterEvent or justplay) we can use default values #for others (the serviceReference or the Begin/End time of the timer #we have to quit if they are not set/have illegal values if 'sRef' not in param: return (False, _("Missing Parameter: sRef")) service_ref = ServiceReference(param['sRef']) repeated = int(param.get('repeated') or 0) if 'begin' not in param: return (False, _("Missing Parameter: begin")) begin = int(float(param['begin'])) if 'end' not in param: return (False, _("Missing Parameter: end")) end = int(float(param['end'])) tm = int(time()) if tm <= begin: pass elif tm > begin and tm < end and repeated == 0: pass elif repeated == 0: return (False, _("Illegal Parameter value for Parameter begin : '%s'") % begin) if 'applyMargin' in param: if param['applyMargin'] == "1": begin -= config.recording.margin_before.value * 60 end += config.recording.margin_after.value * 60 if 'name' not in param: return (False, _("Missing Parameter: name")) name = param['name'] if 'description' not in param: return (False, _("Missing Parameter: description")) description = param['description'].replace("\n", " ") eit = param.get("eit", None) if eit is None or eit.strip() == "": eit = 0 else: try: eit = int(eit) except ValueError: return (False, _("Illegal Parameter value for Parameter eit : '%s'") % eit) print("[WebComponents.Sources.Timer]: eit=%d" % eit) if eit != 0: #check if the given event exists, if it doesn't the timer may be already running epgcache = eEPGCache.getInstance() event = epgcache.lookupEventId(eServiceReference(param['sRef']), eit) if event: eit = event.getEventId() #TODO add some subservice handling else: print( "[WebComponents.Sources.Timer] event not found, will be ignored" ) disabled = False #Default to: Enabled if 'disabled' in param: if param['disabled'] == "1": disabled = True else: #TODO - maybe we can give the user some useful hint here pass justplay = False #Default to: Record if 'justplay' in param: if param['justplay'] == "1": justplay = True afterEvent = 3 #Default to Afterevent: Auto if 'afterevent' in param: if (param['afterevent'] == "0") or (param['afterevent'] == "1") or (param['afterevent'] == "2"): afterEvent = int(param['afterevent']) dirname = preferredTimerPath() if 'dirname' in param and param['dirname']: dirname = param['dirname'] tags = [] if 'tags' in param and param['tags']: tags = unescape(param['tags']).split(' ') delold = 0 if 'deleteOldOnSave' in param: delold = int(param['deleteOldOnSave']) #Try to edit an existing Timer if delold: if 'channelOld' in param and param['channelOld']: channelOld = ServiceReference(param['channelOld']) else: return (False, _("Missing Parameter: channelOld")) # We do need all of the following Parameters, too, for being able of finding the Timer. # Therefore so we can neither use default values in this part nor can we # continue if a parameter is missing if 'beginOld' not in param: return (False, _("Missing Parameter: beginOld")) beginOld = int(param['beginOld']) if 'endOld' not in param: return (False, _("Missing Parameter: endOld")) endOld = int(param['endOld']) #let's try to find the timer try: for timer in self.recordtimer.timer_list + self.recordtimer.processed_timers: if str(timer.service_ref) == str(channelOld): if int(timer.begin) == beginOld: if int( timer.end ) == endOld: #we've found the timer we've been searching for #set the new data timer.service_ref = service_ref timer.begin = begin timer.end = end timer.name = name timer.description = description timer.eit = eit timer.disabled = disabled timer.justplay = justplay timer.afterEvent = afterEvent timer.dirname = dirname timer.tags = tags timer.repeated = repeated timer.processRepeated() #sanity check timersanitycheck = TimerSanityCheck( self.session.nav.RecordTimer.timer_list, timer) conflicts = None if not timersanitycheck.check(): conflicts = timersanitycheck.getSimulTimerList( ) if conflicts is not None: for x in conflicts: if x.setAutoincreaseEnd(entry): self.session.nav.RecordTimer.timeChanged( x) if not timersanitycheck.check(): conflicts = timersanitycheck.getSimulTimerList( ) if conflicts is None: self.recordtimer.timeChanged( timer) #go and save it print( "[WebComponents.Timer] editTimer: Timer changed!" ) return (True, "Timer '%s' changed" % (timer.name)) else: print( "[WebComponents.Timer] editTimer conflicting Timers: %s" % (conflicts)) msg = "" for t in conflicts: msg = "%s / %s" % (msg, t.name) return ( False, _("Conflicting Timer(s) detected! %s") % (msg)) except Exception as e: #obviously some value was not good, return an error import traceback print(traceback.format_exc()) return (False, _("Changing the timer for '%s' failed!") % name) return ( False, _("Could not find timer '%s' with given start and end time!") % name) #Try adding a new Timer try: #Create a new instance of recordtimerentry timer = RecordTimerEntry(service_ref, begin, end, name, description, eit, disabled, justplay, afterEvent, dirname=dirname, tags=tags) timer.repeated = repeated #add the new timer conflicts = self.recordtimer.record(timer) if conflicts is None: return (True, _("Timer '%s' added") % (timer.name)) else: print( "[WebComponents.Timer] editTimer conflicting Timers: %s" % (conflicts)) msg = "" for timer in conflicts: msg = "%s / %s" % (msg, timer.name) return (False, _("Conflicting Timer(s) detected! %s") % (msg)) except Exception as e: #something went wrong, most possibly one of the given paramater-values was wrong print("[WebComponents.Timer] editTimer exception: %s" % (e)) return (False, _("Could not add timer '%s'!") % name) return (False, "Unexpected Error")
def addTimer(session, serviceref, begin, end, name, description, disabled, justplay, afterevent, dirname, tags, repeated, vpsinfo=None, logentries=None, eit=0, always_zap=-1): rt = session.nav.RecordTimer if not dirname: dirname = preferredTimerPath() try: timer = RecordTimerEntry(ServiceReference(serviceref), begin, end, name, description, eit, disabled, justplay, afterevent, dirname=dirname, tags=tags) timer.repeated = repeated if logentries: timer.log_entries = logentries conflicts = rt.record(timer) if conflicts: errors = [] conflictinfo = [] for conflict in conflicts: errors.append(conflict.name) conflictinfo.append({ "serviceref": str(conflict.service_ref), "servicename": mangle_epg_text(conflict.service_ref.getServiceName()), "name": conflict.name, "begin": conflict.begin, "end": conflict.end, "realbegin": strftime("%d.%m.%Y %H:%M", (localtime(float(conflict.begin)))), "realend": strftime("%d.%m.%Y %H:%M", (localtime(float(conflict.end)))) }) return { "result": False, "message": _("Conflicting Timer(s) detected! %s") % " / ".join(errors), "conflicts": conflictinfo } # VPS if vpsinfo is not None: timer.vpsplugin_enabled = vpsinfo["vpsplugin_enabled"] timer.vpsplugin_overwrite = vpsinfo["vpsplugin_overwrite"] timer.vpsplugin_time = vpsinfo["vpsplugin_time"] if always_zap != -1: if hasattr(timer, "always_zap"): timer.always_zap = always_zap == 1 except Exception as e: print e return { "result": False, "message": _("Could not add timer '%s'!") % name } return {"result": True, "message": _("Timer '%s' added") % name}
def editTimer(self, param): print "[WebComponents.Timer] editTimer" # OK first we need to parse all of your Parameters # For some of them (like afterEvent or justplay) we can use default values # for others (the serviceReference or the Begin/End time of the timer # we have to quit if they are not set/have illegal values if "sRef" not in param: return (False, "Missing Parameter: sRef") service_ref = ServiceReference(param["sRef"]) repeated = int(param.get("repeated") or 0) if "begin" not in param: return (False, "Missing Parameter: begin") begin = int(float(param["begin"])) if "end" not in param: return (False, "Missing Parameter: end") end = int(float(param["end"])) tm = time() if tm <= begin: pass elif tm > begin and tm < end and repeated == 0: begin = time() elif repeated == 0: return (False, "Illegal Parameter value for Parameter begin : '%s'" % begin) if "name" not in param: return (False, "Missing Parameter: name") name = param["name"] if "description" not in param: return (False, "Missing Parameter: description") description = param["description"].replace("\n", " ") disabled = False # Default to: Enabled if "disabled" in param: if param["disabled"] == "1": disabled = True else: # TODO - maybe we can give the user some useful hint here pass justplay = False # Default to: Record if "justplay" in param: if param["justplay"] == "1": justplay = True afterEvent = 3 # Default to Afterevent: Auto if "afterevent" in param: if (param["afterevent"] == "0") or (param["afterevent"] == "1") or (param["afterevent"] == "2"): afterEvent = int(param["afterevent"]) dirname = config.movielist.last_timer_videodir.value if "dirname" in param and param["dirname"]: dirname = param["dirname"] tags = [] if "tags" in param and param["tags"]: tags = unescape(param["tags"]).split(" ") delold = 0 if "deleteOldOnSave" in param: delold = int(param["deleteOldOnSave"]) # Try to edit an existing Timer if delold: if "channelOld" in param and param["channelOld"]: channelOld = ServiceReference(param["channelOld"]) else: return (False, "Missing Parameter: channelOld") # We do need all of the following Parameters, too, for being able of finding the Timer. # Therefore so we can neither use default values in this part nor can we # continue if a parameter is missing if "beginOld" not in param: return (False, "Missing Parameter: beginOld") beginOld = int(param["beginOld"]) if "endOld" not in param: return (False, "Missing Parameter: endOld") endOld = int(param["endOld"]) # let's try to find the timer try: for timer in self.recordtimer.timer_list + self.recordtimer.processed_timers: if str(timer.service_ref) == str(channelOld): if int(timer.begin) == beginOld: if int(timer.end) == endOld: # we've found the timer we've been searching for # Let's apply the new values timer.service_ref = service_ref timer.begin = int(begin) timer.end = int(end) timer.name = name timer.description = description timer.disabled = disabled timer.justplay = justplay timer.afterEvent = afterEvent timer.repeated = repeated timer.dirname = dirname timer.tags = tags # send the changed timer back to enigma2 and hope it's good self.session.nav.RecordTimer.timeChanged(timer) print "[WebComponents.Timer] editTimer: Timer changed!" return (True, "Timer %s has been changed!" % (timer.name)) except Exception: # obviously some value was not good, return an error return (False, "Changing the timer for '%s' failed!" % name) return (False, "Could not find timer '%s' with given start and end time!" % name) # Try adding a new Timer try: # Create a new instance of recordtimerentry timer = RecordTimerEntry( service_ref, begin, end, name, description, 0, disabled, justplay, afterEvent, dirname=dirname, tags=tags, ) timer.repeated = repeated # add the new timer self.recordtimer.record(timer) return (True, "Timer added successfully!") except Exception: # something went wrong, most possibly one of the given paramater-values was wrong return (False, "Could not add timer '%s'!" % name) return (False, "Unexpected Error")
def editTimer(self, param): print "[WebComponents.Timer] editTimer" #OK first we need to parse all of your Parameters #For some of them (like afterEvent or justplay) we can use default values #for others (the serviceReference or the Begin/End time of the timer #we have to quit if they are not set/have illegal values if 'serviceref' in param: param['sRef'] = str(param['serviceref']) if 'sRef' not in param: return ( False, "Missing Parameter: sRef" ) service_ref = ServiceReference(param['sRef']) repeated = int(param.get('repeated') or 0) if 'begin' not in param: return ( False, "Missing Parameter: begin" ) begin = int(float(param['begin'])) if 'end' not in param: return ( False, "Missing Parameter: end" ) end = int(float(param['end'])) tm = time() if tm <= begin: pass elif tm > begin and tm < end and repeated == 0: begin = time() elif repeated == 0: return ( False, "Illegal Parameter value for Parameter begin : '%s'" % begin ) if 'name' not in param: return ( False, "Missing Parameter: name" ) name = param['name'] if 'description' not in param: return ( False, "Missing Parameter: description" ) description = param['description'].replace("\n", " ") disabled = False #Default to: Enabled if 'disabled' in param: if param['disabled'] == "1": disabled = True else: #TODO - maybe we can give the user some useful hint here pass justplay = False #Default to: Record if 'justplay' in param: if param['justplay'] == "1": justplay = True afterEvent = 3 #Default to Afterevent: Auto if 'afterevent' in param: if (param['afterevent'] == "0") or (param['afterevent'] == "1") or (param['afterevent'] == "2"): afterEvent = int(param['afterevent']) dirname = preferredTimerPath() if 'dirname' in param and param['dirname']: dirname = param['dirname'] tags = [] if 'tags' in param and param['tags']: tags = unescape(param['tags']).split(' ') delold = 0 if 'deleteOldOnSave' in param: delold = int(param['deleteOldOnSave']) #Try to edit an existing Timer if delold: if 'channelOld' in param and param['channelOld']: channelOld = ServiceReference(param['channelOld']) else: return ( False, "Missing Parameter: channelOld" ) # We do need all of the following Parameters, too, for being able of finding the Timer. # Therefore so we can neither use default values in this part nor can we # continue if a parameter is missing if 'beginOld' not in param: return ( False, "Missing Parameter: beginOld" ) beginOld = int(param['beginOld']) if 'endOld' not in param: return ( False, "Missing Parameter: endOld" ) endOld = int(param['endOld']) #let's try to find the timer try: for timer in self.__recordtimer.timer_list + self.__recordtimer.processed_timers: if str(timer.service_ref) == str(channelOld): if int(timer.begin) == beginOld: if int(timer.end) == endOld: #we've found the timer we've been searching for #Delete the old entry self.__recordtimer.removeEntry(timer) old = timer timer = RecordTimerEntry(service_ref, begin, end, name, description, 0, disabled, justplay, afterEvent, dirname=dirname, tags=tags) timer.repeated = repeated timer.log_entries = old.log_entries timer.processRepeated() #send the changed timer back to enigma2 and hope it's good conflicts = self.__recordtimer.record(timer) if conflicts is None: print "[WebComponents.Timer] editTimer: Timer changed!" return ( True, "Timer '%s' changed" %(timer.name) ) else: print "[WebComponents.Timer] editTimer conflicting Timers: %s" %(conflicts) msg = "" for timer in conflicts: msg = "%s / %s" %(msg, timer.name) return (False, "Conflicting Timer(s) detected! %s" %(msg)) except Exception: #obviously some value was not good, return an error return ( False, "Changing the timer for '%s' failed!" % name ) return ( False, "Could not find timer '%s' with given start and end time!" % name ) #Try adding a new Timer try: #Create a new instance of recordtimerentry timer = RecordTimerEntry(service_ref, begin, end, name, description, 0, disabled, justplay, afterEvent, dirname=dirname, tags=tags) timer.repeated = repeated #add the new timer conflicts = self.__recordtimer.record(timer) if conflicts is None: return ( True, "Timer '%s' added" %(timer.name) ) else: print "[WebComponents.Timer] editTimer conflicting Timers: %s" %(conflicts) msg = "" for timer in conflicts: msg = "%s / %s" %(msg, timer.name) return (False, "Conflicting Timer(s) detected! %s" %(msg)) except Exception, e: #something went wrong, most possibly one of the given paramater-values was wrong print "[WebComponents.Timer] editTimer exception: %s" %(e) return ( False, "Could not add timer '%s'!" % name )
def editTimer(self, param): print "[WebComponents.Timer] editTimer" #OK first we need to parse all of your Parameters #For some of them (like afterEvent or justplay) we can use default values #for others (the serviceReference or the Begin/End time of the timer #we have to quit if they are not set/have illegal values if 'sRef' not in param: return (False, "Missing Parameter: sRef") service_ref = ServiceReference(param['sRef']) repeated = int(param.get('repeated') or 0) if 'begin' not in param: return (False, "Missing Parameter: begin") begin = int(float(param['begin'])) if 'end' not in param: return (False, "Missing Parameter: end") end = int(float(param['end'])) tm = time() if tm <= begin: pass elif tm > begin and tm < end and repeated == 0: begin = time() elif repeated == 0: return (False, "Illegal Parameter value for Parameter begin : '%s'" % begin) if 'name' not in param: return (False, "Missing Parameter: name") name = param['name'] if 'description' not in param: return (False, "Missing Parameter: description") description = param['description'].replace("\n", " ") disabled = False #Default to: Enabled if 'disabled' in param: if param['disabled'] == "1": disabled = True else: #TODO - maybe we can give the user some useful hint here pass justplay = False #Default to: Record if 'justplay' in param: if param['justplay'] == "1": justplay = True afterEvent = 3 #Default to Afterevent: Auto if 'afterevent' in param: if (param['afterevent'] == "0") or (param['afterevent'] == "1") or (param['afterevent'] == "2"): afterEvent = int(param['afterevent']) dirname = preferredTimerPath() if 'dirname' in param and param['dirname']: dirname = param['dirname'] tags = [] if 'tags' in param and param['tags']: tags = unescape(param['tags']).split(' ') delold = 0 if 'deleteOldOnSave' in param: delold = int(param['deleteOldOnSave']) #Try to edit an existing Timer if delold: if 'channelOld' in param and param['channelOld']: channelOld = ServiceReference(param['channelOld']) else: return (False, "Missing Parameter: channelOld") # We do need all of the following Parameters, too, for being able of finding the Timer. # Therefore so we can neither use default values in this part nor can we # continue if a parameter is missing if 'beginOld' not in param: return (False, "Missing Parameter: beginOld") beginOld = int(param['beginOld']) if 'endOld' not in param: return (False, "Missing Parameter: endOld") endOld = int(param['endOld']) #let's try to find the timer try: for timer in self.recordtimer.timer_list + self.recordtimer.processed_timers: if str(timer.service_ref) == str(channelOld): if int(timer.begin) == beginOld: if int(timer.end) == endOld: #we've found the timer we've been searching for #Delete the old entry self.recordtimer.removeEntry(timer) old = timer timer = RecordTimerEntry(service_ref, begin, end, name, description, 0, disabled, justplay, afterEvent, dirname=dirname, tags=tags) timer.repeated = repeated timer.log_entries = old.log_entries timer.processRepeated() #send the changed timer back to enigma2 and hope it's good conflicts = self.recordtimer.record(timer) if conflicts is None: print "[WebComponents.Timer] editTimer: Timer changed!" return (True, "Timer '%s' changed" % (timer.name)) else: print "[WebComponents.Timer] editTimer conflicting Timers: %s" % ( conflicts) msg = "" for timer in conflicts: msg = "%s / %s" % (msg, timer.name) return ( False, "Conflicting Timer(s) detected! %s" % (msg)) except Exception: #obviously some value was not good, return an error return (False, "Changing the timer for '%s' failed!" % name) return ( False, "Could not find timer '%s' with given start and end time!" % name) #Try adding a new Timer try: #Create a new instance of recordtimerentry timer = RecordTimerEntry(service_ref, begin, end, name, description, 0, disabled, justplay, afterEvent, dirname=dirname, tags=tags) timer.repeated = repeated #add the new timer conflicts = self.recordtimer.record(timer) if conflicts is None: return (True, "Timer '%s' added" % (timer.name)) else: print "[WebComponents.Timer] editTimer conflicting Timers: %s" % ( conflicts) msg = "" for timer in conflicts: msg = "%s / %s" % (msg, timer.name) return (False, "Conflicting Timer(s) detected! %s" % (msg)) except Exception, e: #something went wrong, most possibly one of the given paramater-values was wrong print "[WebComponents.Timer] editTimer exception: %s" % (e) return (False, "Could not add timer '%s'!" % name)
def addTimer( session, serviceref, begin, end, name, description, disabled, justplay, afterevent, dirname, tags, repeated, logentries=None, eit=0, ): recordHandler = NavigationInstance.instance.RecordTimer msgTimeout = config.plugins.skyrecorder.msgtimeout.value if not dirname: try: dirname = config.plugins.skyrecorder.anytimefolder.value except Exception: dirname = preferredTimerPath() print "mao1", dirname try: timer = RecordTimerEntry( ServiceReference(serviceref), begin, end, name, description, eit, disabled, justplay, afterevent, dirname=dirname, tags=tags, ) timer.repeated = repeated if logentries: timer.log_entries = logentries print "rrgggg" conflicts = recordHandler.record(timer) if conflicts: errors = [] for conflict in conflicts: errors.append(conflict.name) print "duuuupppppppeeeeee" return {"result": False, "message": "Conflicting Timer(s) detected! %s" % " / ".join(errors)} except Exception, e: print "adupppeee" print e return {"result": False, "message": "Could not add timer '%s'!" % name}
def editTimer(self, param): print "[WebComponents.Timer] editTimer" #OK first we need to parse all of your Parameters #For some of them (like afterEvent or justplay) we can use default values #for others (the serviceReference or the Begin/End time of the timer #we have to quit if they are not set/have illegal values if 'sRef' not in param: return ( False, _("Missing Parameter: sRef") ) service_ref = ServiceReference(param['sRef']) repeated = int(param.get('repeated') or 0) if 'begin' not in param: return ( False, _("Missing Parameter: begin") ) begin = int(float(param['begin'])) if 'end' not in param: return ( False, _("Missing Parameter: end") ) end = int(float(param['end'])) tm = int( time() ) if tm <= begin: pass elif tm > begin and tm < end and repeated == 0: pass elif repeated == 0: return ( False, _("Illegal Parameter value for Parameter begin : '%s'") % begin ) if 'applyMargin' in param: if param['applyMargin'] == "1": begin -= config.recording.margin_before.value * 60 end += config.recording.margin_after.value * 60 if 'name' not in param: return ( False, _("Missing Parameter: name") ) name = param['name'] if 'description' not in param: return ( False, _("Missing Parameter: description") ) description = param['description'].replace("\n", " ") eit = param.get("eit", None) if eit is None or eit.strip() == "": eit = 0 else: try: eit = int(eit) except ValueError: return ( False, _("Illegal Parameter value for Parameter eit : '%s'") % eit ) print "[WebComponents.Sources.Timer]: eit=%d" %eit if eit != 0: #check if the given event exists, if it doesn't the timer may be already running epgcache = eEPGCache.getInstance() event = epgcache.lookupEventId(eServiceReference(param['sRef']), eit) if event: eit = event.getEventId() #TODO add some subservice handling else: print "[WebComponents.Sources.Timer] event not found, will be ignored" disabled = False #Default to: Enabled if 'disabled' in param: if param['disabled'] == "1": disabled = True else: #TODO - maybe we can give the user some useful hint here pass justplay = False #Default to: Record if 'justplay' in param: if param['justplay'] == "1": justplay = True if not justplay and not config.misc.recording_allowed.value: return (False, _("Recording is currently disabled!")) afterEvent = 3 #Default to Afterevent: Auto if 'afterevent' in param: if (param['afterevent'] == "0") or (param['afterevent'] == "1") or (param['afterevent'] == "2"): afterEvent = int(param['afterevent']) dirname = preferredTimerPath() if 'dirname' in param and param['dirname']: dirname = param['dirname'] tags = [] if 'tags' in param and param['tags']: tags = unescape(param['tags']).split(' ') delold = 0 if 'deleteOldOnSave' in param: delold = int(param['deleteOldOnSave']) #Try to edit an existing Timer if delold: if 'channelOld' in param and param['channelOld']: channelOld = ServiceReference(param['channelOld']) else: return ( False, _("Missing Parameter: channelOld") ) # We do need all of the following Parameters, too, for being able of finding the Timer. # Therefore so we can neither use default values in this part nor can we # continue if a parameter is missing if 'beginOld' not in param: return ( False, _("Missing Parameter: beginOld") ) beginOld = int(param['beginOld']) if 'endOld' not in param: return ( False, _("Missing Parameter: endOld") ) endOld = int(param['endOld']) #let's try to find the timer try: for timer in self.recordtimer.timer_list + self.recordtimer.processed_timers: if str(timer.service_ref) == str(channelOld): if int(timer.begin) == beginOld: if int(timer.end) == endOld: #we've found the timer we've been searching for #set the new data timer.service_ref = service_ref timer.begin = begin timer.end = end timer.name = name timer.description = description timer.eit = eit timer.disabled = disabled timer.justplay = justplay timer.afterEvent = afterEvent timer.dirname = dirname timer.tags = tags timer.repeated = repeated timer.processRepeated() #sanity check timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, timer) conflicts = None if not timersanitycheck.check(): conflicts = timersanitycheck.getSimulTimerList() if conflicts is not None: for x in conflicts: if x.setAutoincreaseEnd(entry): self.session.nav.RecordTimer.timeChanged(x) if not timersanitycheck.check(): conflicts = timersanitycheck.getSimulTimerList() if conflicts is None: self.recordtimer.timeChanged(timer) #go and save it print "[WebComponents.Timer] editTimer: Timer changed!" return ( True, "Timer '%s' changed" %(timer.name) ) else: print "[WebComponents.Timer] editTimer conflicting Timers: %s" %(conflicts) msg = "" for t in conflicts: msg = "%s / %s" %(msg, t.name) return (False, _("Conflicting Timer(s) detected! %s") %(msg)) except Exception as e: #obviously some value was not good, return an error import traceback print traceback.format_exc() return ( False, _("Changing the timer for '%s' failed!") % name ) return ( False, _("Could not find timer '%s' with given start and end time!") % name ) #Try adding a new Timer try: #Create a new instance of recordtimerentry timer = RecordTimerEntry(service_ref, begin, end, name, description, eit, disabled, justplay, afterEvent, dirname=dirname, tags=tags) timer.repeated = repeated #add the new timer conflicts = self.recordtimer.record(timer) if conflicts is None: return ( True, _("Timer '%s' added") %(timer.name) ) else: print "[WebComponents.Timer] editTimer conflicting Timers: %s" %(conflicts) msg = "" for timer in conflicts: msg = "%s / %s" %(msg, timer.name) return (False, _("Conflicting Timer(s) detected! %s") %(msg)) except Exception, e: #something went wrong, most possibly one of the given paramater-values was wrong print "[WebComponents.Timer] editTimer exception: %s" %(e) return ( False, _("Could not add timer '%s'!") % name )
def addTimer(session, serviceref, begin, end, name, description, disabled, justplay, afterevent, dirname, tags, repeated, vpsinfo=None, logentries=None, eit=0, always_zap=-1): rt = session.nav.RecordTimer if not dirname: dirname = preferredTimerPath() try: timer = RecordTimerEntry( ServiceReference(serviceref), begin, end, name, description, eit, disabled, justplay, afterevent, dirname=dirname, tags=tags) timer.repeated = repeated if logentries: timer.log_entries = logentries conflicts = rt.record(timer) if conflicts: errors = [] conflictinfo = [] for conflict in conflicts: errors.append(conflict.name) conflictinfo.append({ "serviceref": str(conflict.service_ref), "servicename": conflict.service_ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''), "name": conflict.name, "begin" : conflict.begin, "end" : conflict.end, "realbegin":strftime("%d.%m.%Y %H:%M", (localtime(float(conflict.begin)))), "realend":strftime("%d.%m.%Y %H:%M", (localtime(float(conflict.end)))) }) return { "result": False, "message": _("Conflicting Timer(s) detected! %s") % " / ".join(errors), "conflicts" : conflictinfo } #VPS if vpsinfo is not None: timer.vpsplugin_enabled = vpsinfo["vpsplugin_enabled"] timer.vpsplugin_overwrite = vpsinfo["vpsplugin_overwrite"] timer.vpsplugin_time = vpsinfo["vpsplugin_time"] if always_zap <> -1: if hasattr(timer,"always_zap"): timer.always_zap = always_zap == 1 except Exception, e: print e return { "result": False, "message": _("Could not add timer '%s'!") % name }
def addTimer(serviceref, begin, end, name, description, eit, disabled, dirname, vpsSettings, tags, logentries=None): recordHandler = NavigationInstance.instance.RecordTimer # config.plugins.serienRec.seriensubdir # if not dirname: # try: # dirname = config.plugins.serienRec.savetopath.value # except Exception: # dirname = preferredTimerPath() try: try: timer = RecordTimerEntry( ServiceReference(serviceref), begin, end, name, description, eit, disabled=disabled, justplay=config.plugins.serienRec.justplay.value, zapbeforerecord=config.plugins.serienRec.zapbeforerecord.value, justremind=config.plugins.serienRec.justremind.value, afterEvent=int(config.plugins.serienRec.afterEvent.value), dirname=dirname) except Exception: sys.exc_clear() timer = RecordTimerEntry( ServiceReference(serviceref), begin, end, name, description, eit, disabled, config.plugins.serienRec.justplay.value | config.plugins.serienRec.justremind.value, afterEvent=int(config.plugins.serienRec.afterEvent.value), dirname=dirname, tags=None) timer.repeated = 0 # Add tags timerTags = timer.tags[:] timerTags.append('SerienRecorder') if len(tags) != 0: timerTags.extend(tags) timer.tags = timerTags # If eit = 0 the VPS plugin won't work properly for this timer, so we have to disable VPS in this case. if SerienRecorder.VPSPluginAvailable and eit is not 0: timer.vpsplugin_enabled = vpsSettings[0] timer.vpsplugin_overwrite = timer.vpsplugin_enabled and (not vpsSettings[1]) if logentries: timer.log_entries = logentries timer.log(0, "[SerienRecorder] Timer angelegt") conflicts = recordHandler.record(timer) if conflicts: errors = [] for conflict in conflicts: errors.append(conflict.name) return { "result": False, "message": "In Konflikt stehende Timer vorhanden! %s" % " / ".join(errors) } except Exception, e: print "[%s] <%s>" % (__name__, e) return { "result": False, "message": "Timer konnte nicht angelegt werden '%s'!" % e }