def enterStandBy(self): print "[AutoShutDown] STANDBY . . . " if not Screens.Standby.inTryQuitMainloop and Screens.Standby.inStandby is None: Notifications.AddNotification(Screens.Standby.Standby)
def gotostandby(self): if not Screens.Standby.inStandby: from Tools import Notifications print '[NAVIGATION] now entering standby' Notifications.AddNotification(Screens.Standby.Standby)
def sendStandbyNotification(self, answer): if answer: Notifications.AddNotification(Screens.Standby.Standby)
def DoElektroStandby(self, retval): if (retval): #Yes, go to sleep Notifications.AddNotification(Standby.Standby)
def render_SETUP(self, request): self.render_startCSeqDate(request, request.method) print '[AirTunes] render SETUP' self.handleChallengeResponse(request) if self.aesiv is not None and self.rsaaeskey is not None and self.fmtp is not None and 'transport' in request.received_headers: print '[AirTunes] alles da' if self.process is not None: print '[AirTunes] killing old instance of hairtunes' self.process.kill() self.process = None data_port = 0 timing_port = 59010 control_port = 59012 response = create_string_buffer(1024) if not os.path.exists(HAIRTUNES_BINARY) and not os.path.exists( AIRTUNES_PROXY_BINARY): Notifications.AddNotification( MessageBox, _('AirTunes Audio-Streaming is not available on this Boxtype' ), type=MessageBox.TYPE_INFO, timeout=10) return for row in request.received_headers['transport'].split(';'): row = row.strip() seppos = row.find('=') if seppos == -1: continue key = row[:seppos].strip() value = row[seppos + 1:].strip() if key == 'timing_port': timing_port = int(value) elif key == 'control_port': control_port = int(value) aesiv_plain = base64.b64decode(self.aesiv) aesiv = '' for ch in aesiv_plain: aesiv += '%02X' % ord(ch) try: print '[AirTunes] setting downmix' blockingCallFromMainThread(self.backend.setDownmix) except Exception as e: print '[AirTunes] setting downmix failed: ', e if config.plugins.airplayer.audioBackend.value == 'proxy': binary = AIRTUNES_PROXY_BINARY else: binary = HAIRTUNES_BINARY args = [ binary, 'aesiv', aesiv, 'aeskey', self.rsaaeskey, 'valid', config.plugins.airplayer.validationKey.value, 'fmtp', self.fmtp, 'cport', str(control_port), 'tport', str(timing_port), 'dport', '0' ] print '[AirTunes] starting AirTunes reciever' print args[0], ' ', args[1], ' ', args[2], ' ', args[3], ' ', args[ 4], ' ', args[5], ' ', args[6], ' ', args[7], ' ', args[ 8], ' ', args[9], ' ', args[10], ' ', args[11], ' ', args[ 12] self.process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) while self.process.poll() == None: buff = self.process.stdout.readline() if len(buff) > 0: if buff[:6] == 'port: ': data_port = buff[6:-1] break if data_port != 0: request.setHeader( 'transport', request.received_headers['transport'] + ';server_port=' + str(data_port)) request.setHeader('session', 'DEADBEEF') if config.plugins.airplayer.delayAudioPlayback.value: print '[AirTunes] starting AudioPlayer in one sec' start_new_thread(self.playerStarter, (self, )) else: print '[AirTunes] starting AudioPlayer now' blockingCallFromMainThread(self.backend.play_airtunes, self.validationMessage) print 'player started: ' else: request.setHeader( 'transport', request.received_headers['transport'] + ';server_port=' + str(9999)) request.setHeader('session', 'DEADBEEF') Notifications.AddNotification( MessageBox, _('AirTunes Audio-Streaming is not possible on this Boxtype' ), type=MessageBox.TYPE_INFO, timeout=10) else: print '[AirTunes] missing some parameters' if self.aesiv is not None: print '[AirTunes] aesiv:', self.aesiv if self.rsaaeskey is not None: print '[AirTunes] rsaaeskey:', self.rsaaeskey if self.fmtp is not None: print '[AirTunes] fmtp:', self.fmtp if 'transport' in request.received_headers: print '[AirTunes] transport:', request.received_headers[ 'transport'] print '[AirTunes] setup done' return ''
def standby(self): from Screens.Standby import Standby, inStandby if not inStandby: from Tools import Notifications Notifications.AddNotification(Standby)
def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == self.StatePrepared: if self.tryPrepare(): self.log(6, "prepare ok, waiting for begin") # create file to "reserve" the filename # because another recording at the same time on another service can try to record the same event # i.e. cable / sat.. then the second recording needs an own extension... when we create the file # here than calculateFilename is happy if not self.justplay: open(self.Filename + ".ts", "w").close() # Give the Trashcan a chance to clean up try: Trashcan.instance.cleanIfIdle() except Exception, e: print "[TIMER] Failed to call Trashcan.instance.cleanIfIdle()" print "[TIMER] Error:", e # fine. it worked, resources are allocated. self.next_activation = self.begin self.backoff = 0 return True if not self.freespace(): Notifications.AddPopup( text=_("Write error while recording. Disk full?\n%s") % self.name, type=MessageBox.TYPE_ERROR, timeout=5, id="DiskFullMessage") self.state = 4 # self.disabled = True self.failed = True return False self.log(7, "prepare failed") if self.first_try_prepare: self.first_try_prepare = False cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_ref and not cur_ref.getPath(): if not config.recording.asktozap.getValue(): self.log(8, "asking user to zap away") Notifications.AddNotificationWithCallback( self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n" ), timeout=20) else: # zap without asking self.log(9, "zap without asking") Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.failureCB(True) elif cur_ref: self.log( 8, "currently running service is not a live service.. so stop it makes no sense" ) else: self.log( 8, "currently no service running... so we dont need to stop it" ) return False
def sendStandbyNotification(self, answer): RecordTimerEntry.keypress() if answer: Notifications.AddNotification(Screens.Standby.Standby)
def sendTryQuitMainloopNotification(self, answer): RecordTimerEntry.keypress() if answer: Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)
def startedConnecting(self, connector): #@UnusedVariable # pylint: disable=W0613 if config.plugins.NcidClient.connectionVerbose.value: Notifications.AddNotification(MessageBox, _("Connecting to NCID Server..."), type=MessageBox.TYPE_INFO, timeout=2)
def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == 1: if self.always_zap: if Screens.Standby.inStandby: self.log(5, "wakeup and zap to recording service") RecordTimerEntry.setWasInStandby() #set service to zap after standby Screens.Standby.inStandby.prev_running_service = self.service_ref.ref Screens.Standby.inStandby.paused_service = None #wakeup standby Screens.Standby.inStandby.Power() else: if RecordTimerEntry.wasInDeepStandby: RecordTimerEntry.setWasInStandby() cur_zap_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_zap_ref and not cur_zap_ref.getPath( ): # we do not zap away if it is no live service Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.setRecordingPreferredTuner() self.failureCB(True) self.log(5, "zap to recording service") if next_state == self.StatePrepared: if self.tryPrepare(): self.log(6, "prepare ok, waiting for begin") # create file to "reserve" the filename # because another recording at the same time on another service can try to record the same event # i.e. cable / sat.. then the second recording needs an own extension... when we create the file # here than calculateFilename is happy if not self.justplay: open(self.Filename + ".ts", "w").close() # Give the Trashcan a chance to clean up try: Trashcan.instance.cleanIfIdle(self.Filename) except Exception, e: print "[TIMER] Failed to call Trashcan.instance.cleanIfIdle()" print "[TIMER] Error:", e # fine. it worked, resources are allocated. self.next_activation = self.begin self.backoff = 0 return True self.log(7, "prepare failed") if self.first_try_prepare: self.first_try_prepare = False cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_ref and not cur_ref.getPath(): if Screens.Standby.inStandby: self.setRecordingPreferredTuner() self.failureCB(True) elif not config.recording.asktozap.value: self.log(8, "asking user to zap away") Notifications.AddNotificationWithCallback( self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n" ), timeout=20, default=True) else: # zap without asking self.log(9, "zap without asking") Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.setRecordingPreferredTuner() self.failureCB(True) elif cur_ref: self.log( 8, "currently running service is not a live service.. so stop it makes no sense" ) else: self.log( 8, "currently no service running... so we dont need to stop it" ) return False
def __init__(self, session, service, backend, start=None, lastservice=None): self.backend = backend self.startNewServiceOnPlay = False self.start = start self.service = service self.session = session self.useProxy = False self.url = self.service.getPath() self.proxyReady = False self.proxyError = False self['useProxy'] = Boolean(False) self['premiumUser'] = Boolean(False) self.azBoxLastService = None self.proxyCaching = False print '[AirPlayMoviePlayer] MoviePlayer play url: ', self.url if self.url[:7] == 'http://' or self.url[:8] == 'https://': print '[AirPlayMoviePlayer] found http(s) link' if self.checkProxyUsable( ) and config.plugins.airplayer.useProxyIfPossible.value: print '[AirPlayMoviePlayer] using proxy' self.service = None self.startNewServiceOnPlay = True self.proxyCaching = True self.useProxy = True self['useProxy'] = Boolean(True) if 'm3u8' in self.url and self.useProxy == False: Notifications.AddNotification( MessageBox, _('You are trying to play an m3u8 stream. Playing m3u8 streams requires a Premium-Key to use the embedded proxy or a very new version of GStreamer and the gst-fragmented plugin. Otherwise the playback might not work!' ), type=MessageBox.TYPE_INFO, timeout=10) if self.backend.ENIGMA_SERVICE_ID == self.backend.ENIGMA_SERVICEAZ_ID: self.azBoxLastService = lastservice or self.session.nav.getCurrentlyPlayingServiceReference( ) self.session.nav.stopService() open('/proc/player', 'w').write('0') open('/proc/player', 'w').write('2') MoviePlayer.__init__(self, session, self.service) if self.backend.ENIGMA_SERVICE_ID == self.backend.ENIGMA_SERVICEAZ_ID: self.lastservice = self.azBoxLastService backend.MovieWindow = self self.skinName = 'AirPlayerMoviePlayer' if lastservice is not None: self.lastservice = lastservice self.bufferslider = Slider(0, 100) self.bufferslider.setValue(0) self['bufferslider'] = self.bufferslider self['bufferslider'].setValue(0) self['label_speed'] = StaticText('DL-Speed: N/A') self['label_update'] = StaticText('') self['label_cache'] = StaticText('Cache: N/A') self.endReached = False self.localCache = False self.dlactive = False self.localsize = 0 self.proxyProcess = None self.liveStream = False self.m3u8Stream = False self['actions'] = ActionMap( ['InfobarInstantRecord', 'MoviePlayerActions'], { 'instantRecord': self.keyStartLocalCache, 'leavePlayer': self.leavePlayer }, -2) if config.plugins.airplayer.setSeekOnStart.value and self.start != None and self.start > 0.0: start_new_thread(self.seekWatcher, (self, )) start_new_thread(self.checkForUpdate, (self, )) self.__event_tracker = ServiceEventTracker( screen=self, eventmap={ iPlayableService.evUser + 10: self.__evAudioDecodeError, iPlayableService.evUser + 11: self.__evVideoDecodeError, iPlayableService.evUser + 12: self.__evPluginError, iPlayableService.evEOF: self.__evEOF }) if self.useProxy: start_new_thread(self.proxyWatcher, (self, )) self.backend.updateEventInfo('loading') self.onHide.append(self.lockInfoBar) self.proxyCaching = True self.checkProxyTimer = eTimer() self.checkProxyTimer.timeout.get().append(self.checkProxyStatus) self.checkProxyTimer.start(500, True)
def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == self.StatePrepared: if self.tryPrepare(): self.log(6, "prepare ok, waiting for begin") # create file to "reserve" the filename # because another recording at the same time on another service can try to record the same event # i.e. cable / sat.. then the second recording needs an own extension... when we create the file # here than calculateFilename is happy if not self.justplay: open(self.Filename + ".ts", "w").close() # fine. it worked, resources are allocated. self.next_activation = self.begin self.backoff = 0 return True self.log(7, "prepare failed") if self.first_try_prepare: self.first_try_prepare = False cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_ref and not cur_ref.getPath(): if not config.recording.asktozap.value: self.log(8, "asking user to zap away") Notifications.AddNotificationWithCallback( self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n" ), timeout=20) else: # zap without asking self.log(9, "zap without asking") Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.failureCB(True) elif cur_ref: self.log( 8, "currently running service is not a live service.. so stop it makes no sense" ) else: self.log( 8, "currently no service running... so we dont need to stop it" ) return False elif next_state == self.StateRunning: # if this timer has been cancelled, just go to "end" state. if self.cancelled: return True if self.justplay: if Screens.Standby.inStandby: self.log(11, "wakeup and zap") #set service to zap after standby Screens.Standby.inStandby.prev_running_service = self.service_ref.ref #wakeup standby Screens.Standby.inStandby.Power() else: self.log(11, "zapping") NavigationInstance.instance.playService( self.service_ref.ref) return True else: self.log(11, "start recording") record_res = self.record_service.start() if record_res: self.log(13, "start record returned %d" % record_res) self.do_backoff() # retry self.begin = time() + self.backoff return False return True elif next_state == self.StateEnded: old_end = self.end if self.setAutoincreaseEnd(): self.log( 12, "autoincrase recording %d minute(s)" % int( (self.end - old_end) / 60)) self.state -= 1 return True self.log(12, "stop recording") if not self.justplay: NavigationInstance.instance.stopRecordService( self.record_service) self.record_service = None if self.afterEvent == AFTEREVENT.STANDBY: if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithCallback( self.sendStandbyNotification, MessageBox, _("A finished record timer wants to set your\nSTB to standby. Do that now?" ), timeout=20) elif self.afterEvent == AFTEREVENT.DEEPSTANDBY: if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby RecordTimerEntry.TryQuitMainloop( ) # start shutdown handling without screen else: Notifications.AddNotificationWithCallback( self.sendTryQuitMainloopNotification, MessageBox, _("A finished record timer wants to shut down\nyour STB. Shutdown now?" ), timeout=20) return True
def showReceivedMessage(self, numReceived, peer): text = _("Birthday Reminder received %s birthdays from %s.") % (numReceived, peer) Notifications.AddNotification(MessageBox, text, type = MessageBox.TYPE_INFO)
def gotostandby(self): from Tools import Notifications Notifications.AddNotification(Screens.Standby.Standby)
class RecordTimerEntry(timer.TimerEntry, object): ######### the following static methods and members are only in use when the box is in (soft) standby wasInStandby = False wasInDeepStandby = False receiveRecordEvents = False @staticmethod def keypress(key=None, flag=1): if flag and (RecordTimerEntry.wasInStandby or RecordTimerEntry.wasInDeepStandby): RecordTimerEntry.wasInStandby = False RecordTimerEntry.wasInDeepStandby = False eActionMap.getInstance().unbindAction('', RecordTimerEntry.keypress) @staticmethod def setWasInDeepStandby(): RecordTimerEntry.wasInDeepStandby = True eActionMap.getInstance().bindAction('', -maxint - 1, RecordTimerEntry.keypress) @staticmethod def setWasInStandby(): if not RecordTimerEntry.wasInStandby: if not RecordTimerEntry.wasInDeepStandby: eActionMap.getInstance().bindAction('', -maxint - 1, RecordTimerEntry.keypress) RecordTimerEntry.wasInDeepStandby = False RecordTimerEntry.wasInStandby = True @staticmethod def shutdown(): quitMainloop(1) @staticmethod def staticGotRecordEvent(recservice, event): if event == iRecordableService.evEnd: print "RecordTimer.staticGotRecordEvent(iRecordableService.evEnd)" if not checkForRecordings(): print "No recordings busy of sceduled within 6 minutes so shutdown" RecordTimerEntry.shutdown() # immediate shutdown elif event == iRecordableService.evStart: print "RecordTimer.staticGotRecordEvent(iRecordableService.evStart)" @staticmethod def stopTryQuitMainloop(): print "RecordTimer.stopTryQuitMainloop" NavigationInstance.instance.record_event.remove( RecordTimerEntry.staticGotRecordEvent) RecordTimerEntry.receiveRecordEvents = False @staticmethod def TryQuitMainloop(): if not RecordTimerEntry.receiveRecordEvents and Screens.Standby.inStandby: print "RecordTimer.TryQuitMainloop" NavigationInstance.instance.record_event.append( RecordTimerEntry.staticGotRecordEvent) RecordTimerEntry.receiveRecordEvents = True # send fake event.. to check if another recordings are running or # other timers start in a few seconds RecordTimerEntry.staticGotRecordEvent(None, iRecordableService.evEnd) ################################################################# def __init__(self, serviceref, begin, end, name, description, eit, disabled=False, justplay=False, afterEvent=AFTEREVENT.AUTO, checkOldTimers=False, dirname=None, tags=None, descramble=True, record_ecm=False, always_zap=False, zap_wakeup="always", rename_repeat=True): timer.TimerEntry.__init__(self, int(begin), int(end)) if checkOldTimers == True: if self.begin < time() - 1209600: self.begin = int(time()) if self.end < self.begin: self.end = self.begin assert isinstance(serviceref, ServiceReference) if serviceref and serviceref.isRecordable(): self.service_ref = serviceref else: self.service_ref = ServiceReference(None) self.eit = eit self.dontSave = False self.name = name self.description = description self.disabled = disabled self.timer = None self.__record_service = None self.start_prepare = 0 self.justplay = justplay self.always_zap = always_zap self.zap_wakeup = zap_wakeup self.afterEvent = afterEvent self.dirname = dirname self.dirnameHadToFallback = False self.autoincrease = False self.autoincreasetime = 3600 * 24 # 1 day self.tags = tags or [] self.descramble = descramble self.record_ecm = record_ecm self.rename_repeat = rename_repeat self.needChangePriorityFrontend = config.usage.recording_frontend_priority.value != "-2" and config.usage.recording_frontend_priority.value != config.usage.frontend_priority.value self.change_frontend = False self.log_entries = [] self.resetState() def __repr__(self): return "RecordTimerEntry(name=%s, begin=%s, serviceref=%s, justplay=%s)" % ( self.name, ctime(self.begin), self.service_ref, self.justplay) def log(self, code, msg): self.log_entries.append((int(time()), code, msg)) print "[TIMER]", msg def calculateFilename(self, name=None): service_name = self.service_ref.getServiceName() begin_date = strftime("%Y%m%d %H%M", localtime(self.begin)) name = name or self.name filename = begin_date + " - " + service_name if name: if config.recording.filename_composition.value == "short": filename = strftime("%Y%m%d", localtime( self.begin)) + " - " + name elif config.recording.filename_composition.value == "long": filename += " - " + name + " - " + self.description else: filename += " - " + name # standard if config.recording.ascii_filenames.value: filename = ASCIItranslit.legacyEncode(filename) if not self.dirname: dirname = findSafeRecordPath(defaultMoviePath()) else: dirname = findSafeRecordPath(self.dirname) if dirname is None: dirname = findSafeRecordPath(defaultMoviePath()) self.dirnameHadToFallback = True if not dirname: return None self.Filename = Directories.getRecordingFilename(filename, dirname) self.log(0, "Filename calculated as: '%s'" % self.Filename) return self.Filename def tryPrepare(self): if self.justplay: return True else: if not self.calculateFilename(): self.do_backoff() self.start_prepare = time() + self.backoff return False rec_ref = self.service_ref and self.service_ref.ref if rec_ref and rec_ref.flags & eServiceReference.isGroup: rec_ref = getBestPlayableServiceReference( rec_ref, eServiceReference()) if not rec_ref: self.log( 1, "'get best playable service for group... record' failed" ) return False self.setRecordingPreferredTuner() self.record_service = rec_ref and NavigationInstance.instance.recordService( rec_ref) if not self.record_service: self.log(1, "'record service' failed") self.setRecordingPreferredTuner(setdefault=True) return False name = self.name description = self.description if self.repeated: epgcache = eEPGCache.getInstance() queryTime = self.begin + (self.end - self.begin) / 2 evt = epgcache.lookupEventTime(rec_ref, queryTime) if evt: if self.rename_repeat: event_description = evt.getShortDescription() if not event_description: event_description = evt.getExtendedDescription() if event_description and event_description != description: description = event_description event_name = evt.getEventName() if event_name and event_name != name: name = event_name if not self.calculateFilename(event_name): self.do_backoff() self.start_prepare = time() + self.backoff return False event_id = evt.getEventId() else: event_id = -1 else: event_id = self.eit if event_id is None: event_id = -1 prep_res = self.record_service.prepare( self.Filename + ".ts", self.begin, self.end, event_id, name.replace("\n", ""), description.replace("\n", ""), ' '.join(self.tags), bool(self.descramble), bool(self.record_ecm)) if prep_res: if prep_res == -255: self.log(4, "failed to write meta information") else: self.log(2, "'prepare' failed: error %d" % prep_res) # we must calc nur start time before stopRecordService call because in Screens/Standby.py TryQuitMainloop tries to get # the next start time in evEnd event handler... self.do_backoff() self.start_prepare = time() + self.backoff NavigationInstance.instance.stopRecordService( self.record_service) self.record_service = None self.setRecordingPreferredTuner(setdefault=True) return False return True def do_backoff(self): if self.backoff == 0: self.backoff = 5 else: self.backoff *= 2 if self.backoff > 100: self.backoff = 100 self.log(10, "backoff: retry in %d seconds" % self.backoff) def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == 1: if self.always_zap: if Screens.Standby.inStandby: self.log(5, "wakeup and zap to recording service") RecordTimerEntry.setWasInStandby() #set service to zap after standby Screens.Standby.inStandby.prev_running_service = self.service_ref.ref Screens.Standby.inStandby.paused_service = None #wakeup standby Screens.Standby.inStandby.Power() else: if RecordTimerEntry.wasInDeepStandby: RecordTimerEntry.setWasInStandby() cur_zap_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_zap_ref and not cur_zap_ref.getPath( ): # we do not zap away if it is no live service Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.setRecordingPreferredTuner() self.failureCB(True) self.log(5, "zap to recording service") if next_state == self.StatePrepared: if self.tryPrepare(): self.log(6, "prepare ok, waiting for begin") # create file to "reserve" the filename # because another recording at the same time on another service can try to record the same event # i.e. cable / sat.. then the second recording needs an own extension... when we create the file # here than calculateFilename is happy if not self.justplay: open(self.Filename + ".ts", "w").close() # Give the Trashcan a chance to clean up try: Trashcan.instance.cleanIfIdle(self.Filename) except Exception, e: print "[TIMER] Failed to call Trashcan.instance.cleanIfIdle()" print "[TIMER] Error:", e # fine. it worked, resources are allocated. self.next_activation = self.begin self.backoff = 0 return True self.log(7, "prepare failed") if self.first_try_prepare: self.first_try_prepare = False cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_ref and not cur_ref.getPath(): if Screens.Standby.inStandby: self.setRecordingPreferredTuner() self.failureCB(True) elif not config.recording.asktozap.value: self.log(8, "asking user to zap away") Notifications.AddNotificationWithCallback( self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n" ), timeout=20, default=True) else: # zap without asking self.log(9, "zap without asking") Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) self.setRecordingPreferredTuner() self.failureCB(True) elif cur_ref: self.log( 8, "currently running service is not a live service.. so stop it makes no sense" ) else: self.log( 8, "currently no service running... so we dont need to stop it" ) return False elif next_state == self.StateRunning: # if this timer has been cancelled, just go to "end" state. if self.cancelled: return True if self.justplay: if Screens.Standby.inStandby: if RecordTimerEntry.wasInDeepStandby and self.zap_wakeup in ( "always", "from_deep_standby" ) or self.zap_wakeup in ("always", "from_standby"): self.log(11, "wakeup and zap") RecordTimerEntry.setWasInStandby() #set service to zap after standby Screens.Standby.inStandby.prev_running_service = self.service_ref.ref Screens.Standby.inStandby.paused_service = None #wakeup standby Screens.Standby.inStandby.Power() else: if RecordTimerEntry.wasInDeepStandby: RecordTimerEntry.setWasInStandby() self.log(11, "zapping") NavigationInstance.instance.playService( self.service_ref.ref) return True else: self.log(11, "start recording") if RecordTimerEntry.wasInDeepStandby: RecordTimerEntry.keypress() if Screens.Standby.inStandby: #In case some plugin did put the receiver already in standby config.misc.standbyCounter.value = 0 else: Notifications.AddNotification( Screens.Standby.Standby, StandbyCounterIncrease=False) record_res = self.record_service.start() self.setRecordingPreferredTuner(setdefault=True) if record_res: self.log(13, "start record returned %d" % record_res) self.do_backoff() # retry self.begin = time() + self.backoff return False # Tell the trashcan we started recording. The trashcan gets events, # but cannot tell what the associated path is. Trashcan.instance.markDirty(self.Filename) return True
def __init__(self, nextRecordTimerAfterEventActionAuto=False): if NavigationInstance.instance is not None: raise NavigationInstance.instance NavigationInstance.instance = self self.ServiceHandler = eServiceCenter.getInstance() import Navigation as Nav Nav.navcore = self self.pnav = pNavigation() self.pnav.m_event.get().append(self.dispatchEvent) self.pnav.m_record_event.get().append(self.dispatchRecordEvent) self.event = [] self.record_event = [] self.currentlyPlayingServiceReference = None self.currentlyPlayingServiceOrGroup = None self.currentlyPlayingService = None self.RecordTimer = None for p in plugins.getPlugins(PluginDescriptor.WHERE_RECORDTIMER): self.RecordTimer = p() if self.RecordTimer: break if not self.RecordTimer: self.RecordTimer = RecordTimer.RecordTimer() self.nextRecordTimerAfterEventActionAuto = nextRecordTimerAfterEventActionAuto self.__wasTimerWakeup = False self.__wasRecTimerWakeup = False self.syncCount = 0 self.__isRestartUI = config.misc.RestartUI.value startup_to_standby = config.usage.startup_to_standby.value wakeup_time_type = config.misc.prev_wakeup_time_type.value wasTimerWakeup = getFPWasTimerWakeup() if not wasTimerWakeup: #work-around for boxes where driver not sent was_timer_wakeup signal to e2 print "[NAVIGATION] getNextRecordingTime= %s" % self.RecordTimer.getNextRecordingTime( ) print "[NAVIGATION] current Time=%s" % time() print "[NAVIGATION] timediff=%s" % abs( self.RecordTimer.getNextRecordingTime() - time()) if time( ) <= 31536000: # check for NTP-time sync, if no sync, wait for transponder time self.timesynctimer = eTimer() self.timesynctimer.callback.append(self.TimeSynctimer) self.timesynctimer.start(5000, True) print "[NAVIGATION] wait for time sync" elif abs( self.RecordTimer.getNextRecordingTime() - time() ) <= 360: # if there is a recording sheduled in the next 5 mins, set the wasTimerWakeup flag wasTimerWakeup = True f = open("/tmp/was_timer_wakeup_workaround.txt", "w") file = f.write(str(wasTimerWakeup)) f.close() print "[NAVIGATION] wasTimerWakeup = %s" % wasTimerWakeup if wasTimerWakeup: self.__wasTimerWakeup = True if time() <= 31536000: self.timesynctimer = eTimer() self.timesynctimer.callback.append(self.TimeSynctimer) self.timesynctimer.start(5000, True) print "[NAVIGATION] wait for time sync" elif nextRecordTimerAfterEventActionAuto and abs( self.RecordTimer.getNextRecordingTime() - time()) <= 360: self.__wasRecTimerWakeup = True print 'RECTIMER: wakeup to standby detected.' f = open("/tmp/was_rectimer_wakeup", "w") f.write('1') f.close() # as we woke the box to record, place the box in standby. self.standbytimer = eTimer() self.standbytimer.callback.append(self.gotostandby) self.standbytimer.start(15000, True) if config.usage.remote_fallback_import_restart.value: ImportChannels() if config.misc.RestartUI.value: config.misc.RestartUI.value = False config.misc.RestartUI.save() configfile.save() else: if config.usage.remote_fallback_import.value and not config.usage.remote_fallback_import_restart.value: ImportChannels() if startup_to_standby == "yes" or self.__wasTimerWakeup and config.misc.prev_wakeup_time.value and ( (wakeup_time_type == 0 or wakeup_time_type == 1) or (wakeup_time_type == 3 and startup_to_standby == "except")): if not Screens.Standby.inTryQuitMainloop: Notifications.AddNotification(Screens.Standby.Standby) if config.misc.prev_wakeup_time.value: config.misc.prev_wakeup_time.value = 0 config.misc.prev_wakeup_time.save() configfile.save()
def activate(self): global wasRecTimerWakeup next_state = self.state + 1 self.log(5, "activating state %d" % next_state) # print "[TIMER] activate called",time(),next_state,self.first_try_prepare,' pending ',self.messageBoxAnswerPending,' justTried ',self.justTriedFreeingTuner,' show ',self.messageStringShow,self.messageString #TODO remove if next_state == self.StatePrepared: if self.messageBoxAnswerPending: self.start_prepare = time() + 1 # call again in 1 second return False if self.justTriedFreeingTuner: self.start_prepare = time() + 5 # tryPrepare in 5 seconds self.justTriedFreeingTuner = False return False if not self.justplay and not self.freespace(): Notifications.AddPopup(text = _("Write error while recording. Disk full?\n%s") % self.name, type = MessageBox.TYPE_ERROR, timeout = 5, id = "DiskFullMessage") self.failed = True self.next_activation = time() self.end = time() + 5 self.backoff = 0 return True if self.always_zap: if Screens.Standby.inStandby: self.wasInStandby = True eActionMap.getInstance().bindAction('', -maxint - 1, self.keypress) #set service to zap after standby Screens.Standby.inStandby.prev_running_service = self.service_ref.ref Screens.Standby.inStandby.paused_service = None #wakeup standby Screens.Standby.inStandby.Power() self.log(5, "wakeup and zap to recording service") else: cur_zap_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference() if cur_zap_ref and not cur_zap_ref.getPath():# we do not zap away if it is no live service self.messageString += _("The TV was switched to the recording service!\n") self.messageStringShow = True self.setRecordingPreferredTuner() self.failureCB(True) self.log(5, "zap to recording service") if self.tryPrepare(): self.log(6, "prepare ok, waiting for begin") if self.messageStringShow: Notifications.AddNotification(MessageBox, _("In order to record a timer, a tuner was freed successfully:\n\n") + self.messageString, type=MessageBox.TYPE_INFO, timeout=20) # create file to "reserve" the filename # because another recording at the same time on another service can try to record the same event # i.e. cable / sat.. then the second recording needs an own extension... when we create the file # here then calculateFilename is happy if not self.justplay: open(self.Filename + ".ts", "w").close() # give the Trashcan a chance to clean up try: Trashcan.instance.cleanIfIdle() except Exception, e: print "[TIMER] Failed to call Trashcan.instance.cleanIfIdle()" print "[TIMER] Error:", e # fine. it worked, resources are allocated. self.next_activation = self.begin self.backoff = 0 return True self.log(7, "prepare failed") if self.first_try_prepare == 0: # (0) try to make a tuner available by disabling PIP self.first_try_prepare += 1 from Screens.InfoBar import InfoBar from Screens.InfoBarGenerics import InfoBarPiP from Components.ServiceEventTracker import InfoBarCount InfoBarInstance = InfoBarCount == 1 and InfoBar.instance if InfoBarInstance and InfoBarPiP.pipShown(InfoBarInstance) == True: if config.recording.ask_to_abort_pip.value == "ask": self.log(8, "asking user to disable PIP") self.messageBoxAnswerPending = True Notifications.AddNotificationWithCallback(self.failureCB_pip, MessageBox, _("A timer failed to record!\nDisable PIP and try again?\n"), timeout=20) elif config.recording.ask_to_abort_pip.value in ("abort_no_msg", "abort_msg"): self.log(8, "disable PIP without asking") self.setRecordingPreferredTuner() self.failureCB_pip(True) return False else: self.log(8, "currently no PIP active... so we dont need to stop it") if self.first_try_prepare == 1: # (1) try to make a tuner available by aborting pseudo recordings self.first_try_prepare += 1 self.backoff = 0 if len(NavigationInstance.instance.getRecordings(False,pNavigation.isPseudoRecording)) > 0: if config.recording.ask_to_abort_pseudo_rec.value == "ask": self.log(8, "asking user to abort pseudo recordings") self.messageBoxAnswerPending = True Notifications.AddNotificationWithCallback(self.failureCB_pseudo_rec, MessageBox, _("A timer failed to record!\nAbort pseudo recordings (e.g. EPG refresh) and try again?\n"), timeout=20) elif config.recording.ask_to_abort_pseudo_rec.value in ("abort_no_msg", "abort_msg"): self.log(8, "abort pseudo recordings without asking") self.setRecordingPreferredTuner() self.failureCB_pseudo_rec(True) return False else: self.log(8, "currently no pseudo recordings active... so we dont need to stop it") if self.first_try_prepare == 2: # (2) try to make a tuner available by aborting streaming self.first_try_prepare += 1 self.backoff = 0 if len(NavigationInstance.instance.getRecordings(False,pNavigation.isStreaming)) > 0: if config.recording.ask_to_abort_streaming.value == "ask": self.log(8, "asking user to abort streaming") self.messageBoxAnswerPending = True Notifications.AddNotificationWithCallback(self.failureCB_streaming, MessageBox, _("A timer failed to record!\nAbort streaming and try again?\n"), timeout=20) elif config.recording.ask_to_abort_streaming.value in ("abort_no_msg", "abort_msg"): self.log(8, "abort streaming without asking") self.setRecordingPreferredTuner() self.failureCB_streaming(True) return False else: self.log(8, "currently no streaming active... so we dont need to stop it") if self.first_try_prepare == 3: # (3) try to make a tuner available by switching live TV to the recording service self.first_try_prepare += 1 self.backoff = 0 cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference() if cur_ref and not cur_ref.getPath(): if Screens.Standby.inStandby: self.setRecordingPreferredTuner() self.failureCB(True) elif not config.recording.asktozap.value: self.log(8, "asking user to zap away") self.messageBoxAnswerPending = True Notifications.AddNotificationWithCallback(self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n"), timeout=20) else: # zap without asking self.log(9, "zap without asking") self.setRecordingPreferredTuner() self.failureCB(True) return False elif cur_ref: self.log(8, "currently running service is not a live service.. so stopping it makes no sense") else: self.log(8, "currently no service running... so we dont need to stop it") if self.first_try_prepare == 4: # (4) freeing a tuner failed self.first_try_prepare += 1 self.log(8, "freeing a tuner failed") if self.messageString: Notifications.AddNotification(MessageBox, _("No tuner is available for recording a timer!\n\nThe following methods of freeing a tuner were tried without success:\n\n") + self.messageString, type=MessageBox.TYPE_INFO, timeout=20) else: Notifications.AddNotification(MessageBox, _("No tuner is available for recording a timer!\n"), type=MessageBox.TYPE_INFO, timeout=20) return False
def popupTaskView(self, job): if not self.visible: from Tools import Notifications from Screens.TaskView import JobView self.visible = True Notifications.AddNotification(JobView, job)
def goStandby(self): Notifications.AddNotification(RealStandby, self.StandbyCounterIncrease)
def gotostandby(self): print('[Navigation] TIMER: now entering standby') Notifications.AddNotification(Screens.Standby.Standby)
def standby(self, answer): if answer is not None: if answer and not Screens.Standby.inStandby: Notifications.AddNotification(Screens.Standby.Standby) else: self.close()
def program_start(self): self.demux = -1 if self.dont_restart_program: return self.rec_ref = self.timer.service_ref and self.timer.service_ref.ref if self.rec_ref and self.rec_ref.flags & eServiceReference.isGroup: self.rec_ref = getBestPlayableServiceReference( self.rec_ref, eServiceReference()) # recordService (Simulation) ggf. starten if self.timer.state == TimerEntry.StateWaiting: if self.simulate_recordService is None: if self.rec_ref: self.simulate_recordService = NavigationInstance.instance.recordService( self.rec_ref, True) if self.simulate_recordService: res = self.simulate_recordService.start() self.timer.log( 0, "[VPS] start recordService (simulation) " + str(res)) if res != 0 and res != -1: # Fehler aufgetreten (kein Tuner frei?) NavigationInstance.instance.stopRecordService( self.simulate_recordService) self.simulate_recordService = None # in einer Minute ggf. nochmal versuchen if 60 < self.nextExecution: self.nextExecution = 60 # Bei Overwrite versuchen ohne Fragen auf Sender zu schalten if self.timer.vpsplugin_overwrite == True: cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference( ) if cur_ref and not cur_ref.getPath( ) and self.rec_ref.toCompareString( ) != cur_ref.toCompareString(): self.timer.log( 9, "[VPS-Plugin] zap without asking (simulation)" ) Notifications.AddNotification( MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n" ), type=MessageBox.TYPE_INFO, timeout=20) NavigationInstance.instance.playService( self.rec_ref) if 3 < self.nextExecution: self.nextExecution = 3 else: # ansonsten versuchen auf dem aktuellen Transponder/Kanal nach Infos zu suchen if not self.program_try_search_running: self.program_do_start(1) else: # Simulation hat geklappt if 1 < self.nextExecution: self.nextExecution = 1 else: # Simulation läuft schon # hole Demux stream = self.simulate_recordService.stream() if stream: streamdata = stream.getStreamingData() if (streamdata and ('demux' in streamdata)): self.demux = streamdata['demux'] if self.demux == -1: # ist noch nicht soweit(?), in einer Sekunde erneut versuchen if 1 < self.nextExecution: self.nextExecution = 1 else: self.program_do_start(0) elif self.timer.state == TimerEntry.StatePrepared or self.timer.state == TimerEntry.StateRunning: stream = self.timer.record_service.stream() if stream: streamdata = stream.getStreamingData() if (streamdata and ('demux' in streamdata)): self.demux = streamdata['demux'] if self.demux != -1: self.program_do_start(0)
def shutdown(self, answer): if answer is not None: if answer and not Screens.Standby.inTryQuitMainloop: Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1) else: self.close()
def gotostandby(self): print 'TIMER: now entering standby' from Tools import Notifications Notifications.AddNotification(Screens.Standby.Standby)
def sendTryQuitMainloopNotification(self, answer): if answer: Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1) else: global wasRecTimerWakeup wasRecTimerWakeup = False
def doStandby(self): Notifications.AddNotification(Screens.Standby.Standby2)
def goStandby(self): Notifications.AddNotification(StandbyScreen, self.StandbyCounterIncrease)
def sendTryQuitMainloopNotification(self, answer): if answer: Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)
def activate(self): next_state = self.state + 1 self.log(5, "activating state %d" % next_state) if next_state == self.StatePrepared: if self.tryPrepare(): self.log(6, "prepare ok, waiting for begin") # create file to "reserve" the filename # because another recording at the same time on another service can try to record the same event # i.e. cable / sat.. then the second recording needs an own extension... when we create the file # here than calculateFilename is happy if not self.justplay: open(self.Filename, "we").close() # fine. it worked, resources are allocated. self.next_activation = self.begin self.backoff = 0 return True self.log(7, "prepare failed") if self.first_try_prepare: self.first_try_prepare = False cur_ref = NavigationInstance.instance.getCurrentlyPlayingServiceReference() if cur_ref and (not cur_ref.getPath() or cur_ref.getPath()[0] != '/'): if not config.recording.asktozap.value: self.log(8, "asking user to zap away") Notifications.AddNotificationWithCallback(self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n"), timeout=20, domain="RecordTimer") else: # zap without asking self.log(9, "zap without asking") Notifications.AddNotification(MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n"), type=MessageBox.TYPE_INFO, timeout=20, domain="RecordTimer") self.failureCB(True) elif cur_ref: self.log(8, "currently running service is not a live service.. so stop it makes no sense") else: self.log(8, "currently no service running... so we dont need to stop it") return False elif next_state == self.StateRunning: # if this timer has been cancelled, just go to "end" state. if self.cancelled: return True if self.justplay: if Screens.Standby.inStandby: if config.usage.standby_zaptimer_wakeup.value: self.log(11, "wakeup and zap") #set service to zap after standby Screens.Standby.inStandby.prev_running_service = self.service_ref.ref #wakeup standby Screens.Standby.inStandby.Power() else: print "ignore zaptimer in idle mode" else: from API import session self.log(11, "zapping") if session and session.current_player: current_player = session.current_player while current_player and current_player.prev_player: current_player.lastservice = None current_player = current_player.prev_player if current_player: current_player.lastservice = self.service_ref.ref session.current_player.onClose.append(self.__playerClosed) session.current_player.close() return True NavigationInstance.instance.playService(self.service_ref.ref) return True else: self.log(11, "start recording") record_res = self.record_service.start() if record_res: self.log(13, "start record returned %d" % record_res) self.do_backoff() # retry self.begin = time() + self.backoff return False return True elif next_state == self.StateEnded: old_end = self.end # autoincrease (maybe reduced by other timers) instanttimer if possible if self.setAutoincreaseEnd(): self.log(12, "autoincrase recording %d minute(s)" % int((self.end - old_end)/60)) self.state -= 1 return True self.log(12, "stop recording") force_auto_shutdown = NavigationInstance.instance.wasTimerWakeup() and \ config.misc.isNextRecordTimerAfterEventActionAuto.value and \ Screens.Standby.inStandby and config.misc.standbyCounter.value == 1 if not self.justplay: NavigationInstance.instance.stopRecordService(self.record_service) self.record_service = None if self.afterEvent == AFTEREVENT.STANDBY: if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished record timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20, domain="RecordTimer") elif self.afterEvent == AFTEREVENT.DEEPSTANDBY or force_auto_shutdown: if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open if Screens.Standby.inStandby: # in standby RecordTimerEntry.TryQuitMainloop() # start shutdown handling without screen else: Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished record timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20, domain="RecordTimer") if self.plugins: from Plugins.Plugin import PluginDescriptor from Components.PluginComponent import plugins for pname, (pval, pdata) in self.plugins.iteritems(): if pval == 'True': for p in plugins.getPlugins(PluginDescriptor.WHERE_TIMEREDIT): if pname == p.name: if p.__call__.has_key("finishedFnc"): fnc = p.__call__["finishedFnc"] print "calling finishedFnc of WHERE_TIMEREDIT plugin:", p.name, fnc, pval, pdata Notifications.AddNotification(fnc, pval, pdata, self, domain="RecordTimer") return True