예제 #1
0
class serienRecCheckForRecording:

	instance = None
	epgrefresh_instance = None

	def __init__(self, session, manuell, tvplaner_manuell=False):
		assert not serienRecCheckForRecording.instance, "Go is a singleton class!"
		serienRecCheckForRecording.instance = self
		self.session = session
		self.database = None
		self.manuell = manuell
		self.tvplaner_manuell = tvplaner_manuell
		print "[SerienRecorder] 1__init__ tvplaner_manuell: ", tvplaner_manuell
		self.newSeriesOrEpisodesFound = False
		self.senderListe = {}
		self.markers = []
		self.messageList = []
		self.speedStartTime = 0
		self.speedEndTime = 0
		self.konflikt = ""
		self.count_url = 0
		self.countSerien = 0
		self.countActivatedSeries = 0
		self.noOfRecords = int(config.plugins.serienRec.NoOfRecords.value)
		self.emailData = None

		SRLogger.checkFileAccess()

		lt = time.localtime()
		self.uhrzeit = time.strftime("%d.%m.%Y - %H:%M:%S", lt)
		SRLogger.writeLog("\n---------' %s '---------" % self.uhrzeit, True)
		self.daypage = 0

		global refreshTimer
		if refreshTimer:
			refreshTimer.stop()
			refreshTimer = None

		global refreshTimerConnection
		if refreshTimerConnection:
			refreshTimerConnection = None

		self.tempDB = None

		if config.plugins.serienRec.autochecktype.value == "0":
			SRLogger.writeLog("Auto-Check ist deaktiviert - nur manuelle Timersuche", True)
		elif config.plugins.serienRec.autochecktype.value == "1":
			SRLogger.writeLog("Auto-Check ist aktiviert - er wird zur gewählten Uhrzeit gestartet", True)
		elif config.plugins.serienRec.autochecktype.value == "2":
			SRLogger.writeLog("Auto-Check ist aktiviert - er wird nach dem EPGRefresh ausgeführt", True)

		if not self.manuell and config.plugins.serienRec.autochecktype.value == "1" and config.plugins.serienRec.timeUpdate.value:
			deltatime = self.getNextAutoCheckTimer(lt)
			refreshTimer = eTimer()
			if isDreamOS():
				refreshTimerConnection = refreshTimer.timeout.connect(self.startCheck)
			else:
				refreshTimer.callback.append(self.startCheck)
			refreshTimer.start(((deltatime * 60) + random.randint(0, int(config.plugins.serienRec.maxDelayForAutocheck.value)*60)) * 1000, True)
			print "[SerienRecorder] Auto-Check Uhrzeit-Timer gestartet."
			print "[SerienRecorder] Verbleibende Zeit: %s Stunden" % (TimeHelpers.td2HHMMstr(datetime.timedelta(minutes=deltatime+int(config.plugins.serienRec.maxDelayForAutocheck.value))))
			SRLogger.writeLog("Verbleibende Zeit bis zum nächsten Auto-Check: %s Stunden\n" % TimeHelpers.td2HHMMstr(datetime.timedelta(minutes=deltatime+int(config.plugins.serienRec.maxDelayForAutocheck.value))), True)

		if self.manuell:
			print "[SerienRecorder] checkRecTimer manuell."
			self.startCheck()
			self.manuell = False
			self.tvplaner_manuell = False
		else:
			try:
				from Plugins.Extensions.EPGRefresh.EPGRefresh import epgrefresh
				self.epgrefresh_instance = epgrefresh
				config.plugins.serienRec.autochecktype.addNotifier(self.setEPGRefreshCallback)
			except Exception as e:
				SRLogger.writeLog("EPGRefresh plugin nicht installiert! " + str(e), True)

	@staticmethod
	def getNextAutoCheckTimer(lt):
		acttime = (lt.tm_hour * 60 + lt.tm_min)
		deltime = (config.plugins.serienRec.deltime.value[0] * 60 + config.plugins.serienRec.deltime.value[1])
		if acttime < deltime:
			deltatime = deltime - acttime
		else:
			deltatime = abs(1440 - acttime + deltime)
		return deltatime

	def setEPGRefreshCallback(self, configentry = None):
		try:
			if self.epgrefresh_instance:
				if config.plugins.serienRec.autochecktype.value == "2":
					self.epgrefresh_instance.addFinishNotifier(self.startCheck)
				else:
					self.epgrefresh_instance.removeFinishNotifier(self.startCheck)
		except Exception as e:
			try:
				from Tools.HardwareInfoVu import HardwareInfoVu
				pass
			except:
				SRLogger.writeLog("Um die EPGRefresh Optionen nutzen zu können, muss mindestens die EPGRefresh Version 2.1.1 installiert sein. " + str(e), True)

	def getMarkerCover(self):
		self.database = SRDatabase(serienRecDataBaseFilePath)
		markers = self.database.getAllMarkers(False)
		for marker in markers:
			(ID, Serie, Info, Url, AufnahmeVerzeichnis, AlleStaffelnAb, alleSender, Vorlaufzeit, Nachlaufzeit, AnzahlAufnahmen, preferredChannel, useAlternativeChannel, AbEpisode, TimerForSpecials, ErlaubteSTB, ErlaubteStaffelCount) = marker
			getCover(None, Serie, ID, True)

	def startCheck(self):
		self.database = SRDatabase(serienRecDataBaseFilePath)
		global autoCheckFinished
		autoCheckFinished = False

		print "[SerienRecorder] settings:"
		print "[SerienRecorder] manuell:", self.manuell
		print "[SerienRecorder] tvplaner_manuell:", self.tvplaner_manuell
		print "[SerienRecorder] uhrzeit check:", config.plugins.serienRec.timeUpdate.value

		lt = time.localtime()
		self.uhrzeit = time.strftime("%d.%m.%Y - %H:%M:%S", lt)

		global refreshTimer
		global refreshTimerConnection

		SRLogger.checkFileAccess()

		SRLogger.writeLog("\n---------' %s '---------" % self.uhrzeit, True)

		if not self.manuell and not initDB():
			self.askForDSB()
			return

		if not self.database.hasMarkers() and not config.plugins.serienRec.tvplaner and not config.plugins.serienRec.tvplaner_create_marker:
			SRLogger.writeLog("\n---------' Starte Auto-Check um %s '---------" % self.uhrzeit, True)
			print "[SerienRecorder] check: Tabelle SerienMarker leer."
			SRLogger.writeLog("Es sind keine Serien-Marker vorhanden - Auto-Check kann nicht ausgeführt werden.", True)
			SRLogger.writeLog("---------' Auto-Check beendet '---------", True)
			self.askForDSB()
			return

		if not self.database.hasChannels():
			SRLogger.writeLog("\n---------' Starte Auto-Check um %s '---------" % self.uhrzeit, True)
			print "[SerienRecorder] check: Tabelle Channels leer."
			SRLogger.writeLog("Es wurden keine Sender zugeordnet - Auto-Check kann nicht ausgeführt werden.", True)
			SRLogger.writeLog("---------' Auto-Check beendet '---------", True)
			self.askForDSB()
			return

		if refreshTimer:
			refreshTimer.stop()
			refreshTimer = None

			if refreshTimerConnection:
				refreshTimerConnection = None

			print "[SerienRecorder] Auto-Check Timer stop."
			SRLogger.writeLog("Auto-Check stop.", True)

		if config.plugins.serienRec.autochecktype.value == "1" and config.plugins.serienRec.timeUpdate.value:
			deltatime = self.getNextAutoCheckTimer(lt)
			refreshTimer = eTimer()
			if isDreamOS():
				refreshTimerConnection = refreshTimer.timeout.connect(self.startCheck)
			else:
				refreshTimer.callback.append(self.startCheck)
			refreshTimer.start(((deltatime * 60) + random.randint(0, int(config.plugins.serienRec.maxDelayForAutocheck.value)*60)) * 1000, True)

			print "[SerienRecorder] Auto-Check Uhrzeit-Timer gestartet."
			print "[SerienRecorder] Verbleibende Zeit: %s Stunden" % (TimeHelpers.td2HHMMstr(datetime.timedelta(minutes=deltatime+int(config.plugins.serienRec.maxDelayForAutocheck.value))))
			SRLogger.writeLog("Auto-Check Uhrzeit-Timer gestartet.", True)
			SRLogger.writeLog("Verbleibende Zeit: %s Stunden" % TimeHelpers.td2HHMMstr(datetime.timedelta(minutes=deltatime+int(config.plugins.serienRec.maxDelayForAutocheck.value))), True)

		if config.plugins.serienRec.AutoBackup.value == "before":
			createBackup()

		SRLogger.reset()
		from SerienRecorderTVPlaner import resetTVPlanerHTMLBackup
		resetTVPlanerHTMLBackup()
		self.database.removeExpiredTimerConflicts()

		if self.tvplaner_manuell and config.plugins.serienRec.tvplaner.value:
			print "\n---------' Starte Check um %s (TV-Planer manuell) '---------" % self.uhrzeit
			SRLogger.writeLog("\n---------' Starte Check um %s (TV-Planer manuell) '---------\n" % self.uhrzeit, True)
		elif self.manuell:
			print "\n---------' Starte Check um %s (manuell) '---------" % self.uhrzeit
			SRLogger.writeLog("\n---------' Starte Check um %s (manuell) '---------\n" % self.uhrzeit, True)
		elif config.plugins.serienRec.tvplaner.value:
			print "\n---------' Starte Auto-Check um %s (TV-Planer auto) '---------" % self.uhrzeit
			SRLogger.writeLog("\n---------' Starte Auto-Check um %s (TV-Planer auto) '---------\n" % self.uhrzeit, True)
		else:
			print "\n---------' Starte Auto-Check um %s (auto)'---------" % self.uhrzeit
			SRLogger.writeLog("\n---------' Starte Auto-Check um %s (auto)'---------\n" % self.uhrzeit, True)
			if config.plugins.serienRec.showNotification.value in ("1", "3"):
				Notifications.AddPopup("SerienRecorder Suchlauf nach neuen Timern wurde gestartet.", MessageBox.TYPE_INFO, timeout=3, id="Suchlauf wurde gestartet")

		if config.plugins.serienRec.writeLogVersion.value:
			SRLogger.writeLog("STB Type: %s\nImage: %s" % (STBHelpers.getSTBType(), STBHelpers.getImageVersionString()), True)
			SRLogger.writeLog("SR Version: %s\nDatenbank Version: %s" % (config.plugins.serienRec.showversion.value, str(self.database.getVersion())), True)
			SRLogger.writeLog("Skin Auflösung: %s x %s" % (str(getDesktop(0).size().width()), str(getDesktop(0).size().height())), True)

		sMsg = "\nDEBUG Filter: "
		if config.plugins.serienRec.writeLogChannels.value:
			sMsg += "Senderliste "
		if config.plugins.serienRec.writeLogAllowedEpisodes.value:
			sMsg += "Episoden "
		if config.plugins.serienRec.writeLogAdded.value:
			sMsg += "Added "
		if config.plugins.serienRec.writeLogDisk.value:
			sMsg += "Disk "
		if config.plugins.serienRec.writeLogTimeRange.value:
			sMsg += "Tageszeit "
		if config.plugins.serienRec.writeLogTimeLimit.value:
			sMsg += "Zeitlimit "
		if config.plugins.serienRec.writeLogTimerDebug.value:
			sMsg += "Timer "
			SRLogger.writeLog(sMsg, True)

		self.markers = []
		self.messageList = []
		self.speedStartTime = time.clock()

		# teste Verbindung ins Internet
		if not testWebConnection():
			SRLogger.writeLog("\nKeine Verbindung ins Internet. Check wurde abgebrochen!!\n", True)

			# Statistik
			self.speedEndTime = time.clock()
			speedTime = (self.speedEndTime - self.speedStartTime)
			SRLogger.writeLog("---------' Auto-Check beendet ( Ausführungsdauer: %3.2f Sek.)'---------" % speedTime, True)
			print "[SerienRecorder] ---------' Auto-Check beendet ( Ausführungsdauer: %3.2f Sek.)'---------" % speedTime

			from SerienRecorderTVPlaner import backupTVPlanerHTML
			backupTVPlanerHTML()

			global autoCheckFinished
			autoCheckFinished = True

			if config.plugins.serienRec.AutoBackup.value == "after":
				createBackup()

			# in den deep-standby fahren.
			self.askForDSB()
			return

		# Versuche Verzeichnisse zu erreichen
		try:
			SRLogger.writeLog("\nPrüfe konfigurierte Aufnahmeverzeichnisse:", True)
			recordDirectories = self.database.getRecordDirectories(config.plugins.serienRec.savetopath.value)
			for directory in recordDirectories:
				SRLogger.writeLog("   %s" % directory, True)
				os.path.exists(directory)
		except:
			SRLogger.writeLog("Es konnten nicht alle Aufnahmeverzeichnisse gefunden werden", True)

		# suche nach neuen Serien, Covern und Planer-Cache
		from twisted.internet import reactor
		from SerienRecorderSeriesPlanner import serienRecSeriesPlanner
		seriesPlanner = serienRecSeriesPlanner(self.manuell)
		reactor.callFromThread(seriesPlanner.updatePlanerData())

		#if config.plugins.serienRec.downloadCover.value:
		#	reactor.callFromThread(self.getMarkerCover())

		self.startCheckTransmissions()

	def startCheckTransmissions(self):
		self.database = SRDatabase(serienRecDataBaseFilePath)
		self.tempDB = SRTempDatabase()
		self.tempDB.initialize()

		# read channels
		self.senderListe = {}
		for s in self.database.getChannels():
			self.senderListe[s[0].lower()] = s[:]

		webChannels = self.database.getActiveChannels()
		SRLogger.writeLog("\nAnzahl aktiver Websender: %d" % len(webChannels), True)
			
		# get reference times
		current_time = int(time.time())
		future_time = int(config.plugins.serienRec.checkfordays.value) * 86400
		future_time += int(current_time)
		search_start = time.strftime("%d.%m.%Y - %H:%M", time.localtime(int(current_time)))
		search_end = time.strftime("%d.%m.%Y - %H:%M", time.localtime(int(future_time)))
		search_rerun_end = time.strftime("%d.%m.%Y - %H:%M", time.localtime(future_time + (int(config.plugins.serienRec.TimeSpanForRegularTimer.value) - int(config.plugins.serienRec.checkfordays.value)) * 86400))
		SRLogger.writeLog("Berücksichtige Ausstrahlungstermine zwischen %s und %s" % (search_start, search_end), True)
		SRLogger.writeLog("Berücksichtige Wiederholungen zwischen %s und %s" % (search_start, search_rerun_end), True)
		
		# hier werden die wunschliste markers eingelesen
		self.emailData = None
		if config.plugins.serienRec.tvplaner.value and (not self.manuell or self.tvplaner_manuell):
			# When TV-Planer processing is enabled then regular autocheck
			# is only running for the transmissions received by email.
			try:
				from SerienRecorderTVPlaner import getEmailData
				emailParserThread = backgroundThread(getEmailData)
				emailParserThread.start()
				emailParserThread.join()
				self.emailData = emailParserThread.result
			except:
				SRLogger.writeLog("TV-Planer Verarbeitung fehlgeschlagen!", True)
				print "[SerienRecorder] TV-Planer exception!"
				self.emailData = None
		print "[SerienRecorder] lastFullCheckTime %s" % time.strftime("%d.%m.%Y - %H:%M", time.localtime(int(config.plugins.serienRec.tvplaner_last_full_check.value)))
		if self.emailData is None:
			self.markers = self.database.getMarkers(config.plugins.serienRec.BoxID.value, config.plugins.serienRec.NoOfRecords.value)
			config.plugins.serienRec.tvplaner_last_full_check.value = int(time.time())
			config.plugins.serienRec.tvplaner_last_full_check.save()
			configfile.save()
			if config.plugins.serienRec.tvplaner.value:
				fullCheck = "- keine TV-Planer Daten - voller Suchlauf'"
			else:
				fullCheck = "- voller Suchlauf'"
		elif config.plugins.serienRec.tvplaner_full_check.value and (int(config.plugins.serienRec.tvplaner_last_full_check.value) + (int(config.plugins.serienRec.checkfordays.value) - 1) * 86400) < int(time.time()):
			self.markers = self.database.getMarkers(config.plugins.serienRec.BoxID.value, config.plugins.serienRec.NoOfRecords.value)
			config.plugins.serienRec.tvplaner_last_full_check.value = int(time.time())
			config.plugins.serienRec.tvplaner_last_full_check.save()
			configfile.save()
			fullCheck = "- Zeit abgelaufen - voller Suchlauf'"
		else:
			self.markers = self.database.getMarkers(config.plugins.serienRec.BoxID.value, config.plugins.serienRec.NoOfRecords.value, self.emailData.keys())
			fullCheck = "- nur Serien der TV-Planer E-Mail'"
		self.count_url = 0
		self.countSerien = 0
		self.countActivatedSeries = 0
		self.noOfRecords = int(config.plugins.serienRec.NoOfRecords.value)

		# regular processing through serienrecorder server
		# TODO: save all transmissions in files to protect from temporary SerienServer fails
		#       data will be read by the file reader below and used for timer programming
		if len(self.markers) > 0:
			while True:
				#if config.plugins.serienRec.tvplaner.value and config.plugins.serienRec.tvplaner_skipSerienServer.value:
					# Skip serien server processing
				#	break

				global transmissionFailed
				transmissionFailed = False
				self.tempDB.cleanUp()
				if not (config.plugins.serienRec.tvplaner.value and config.plugins.serienRec.tvplaner_skipSerienServer.value):
					SRLogger.writeLog("\n---------' Verarbeite Daten vom Server %s ---------\n" % fullCheck, True)
					print "[SerienRecorder] Verarbeite Daten vom Server"

				# Create a job queue to keep the jobs processed by the threads
				# Create a result queue to keep the results of the job threads
				jobQueue = Queue.Queue()
				resultQueue = Queue.Queue()

				#SRLogger.writeLog("Active threads: %d" % threading.active_count(), True)
				# Create the threads
				for i in range(2):
					worker = downloadTransmissionsThread(jobQueue, resultQueue)
					worker.setDaemon(True)
					worker.start()

				for serienTitle,SerieUrl,SerieStaffel,SerieSender,AbEpisode,AnzahlAufnahmen,SerieEnabled,excludedWeekdays,skipSeriesServer,markerType in self.markers:
					if config.plugins.serienRec.tvplaner.value and (config.plugins.serienRec.tvplaner_skipSerienServer.value or (skipSeriesServer is not None and skipSeriesServer)):
						# Skip serien server processing
						SRLogger.writeLog("' %s ' - Für diesen Serien-Marker sollen nur Timer aus der E-Mail angelegt werden." % serienTitle, True)
						continue

					if markerType == 1:
						# temporary marker for movie recording
						print "[SerienRecorder] ' %s - TV-Planer Film wird ignoriert '" % serienTitle
						continue
					self.countSerien += 1
					if SerieEnabled:
						# Download only if series is enabled
						if 'Alle' in SerieSender:
							markerChannels = webChannels
						else:
							markerChannels = SerieSender

						self.countActivatedSeries += 1
						seriesID = SerieUrl

						jobQueue.put((seriesID, (int(config.plugins.serienRec.TimeSpanForRegularTimer.value)), markerChannels, serienTitle, SerieStaffel, AbEpisode, AnzahlAufnahmen, current_time, future_time, excludedWeekdays))

				jobQueue.join()
				while not resultQueue.empty():
					(transmissionFailed, transmissions, seriesID, serienTitle, SerieStaffel, AbEpisode, AnzahlAufnahmen, current_time, future_time, excludedWeekdays) = resultQueue.get()
					self.processTransmission(transmissions, seriesID, serienTitle, SerieStaffel, AbEpisode, AnzahlAufnahmen, current_time, future_time, excludedWeekdays)
					resultQueue.task_done()

				break
		# 
		# In order to provide an emergency recording service when serien server is down or
		# because Wunschliste isn't accessable, it is now possible to use the TV Wunschliste
		# TV-Planer Infomails.
		# 
		# With an account at www.wunschliste.de it is possible to mark series to appear at
		# "TV-Planer" screen. This screen shows the transmissions of up to a week in advance.
		# In "Einstellungen" it is possible to enable Infomails about TV-Planer. This Infomails
		# can now be used by SerienRecorder to create timers without any further access to
		# Wunschliste, and therefore avoids hitting Wunschliste with the enormous
		# internet traffic that was caused by the many boxes with SerienRecorder.
		#
		# Wunschliste Settings:
		# - put your favourite series on TV-Planer
		# - enable TV-Planer Infomails in "Einstellungen"
		# - set Vorlauf (i.e. 1 day)
		# - set Programmtag-Beginn (i.e. 5.00 Uhr)
		# - set MailFormat to HTML+Text (currently only HTML emails are recognized)
		#
		# When this has been finished the first TV-Planer email will be received next day.
		# 
		# SerienRecorder Settings:
		# - enable TVPlaner feature
		# - set email server, login, password and possibly modify the other parameters
		# - set the autocheck time to about 1 h after the time you receive the TV-planer emails
		#
		# Now every time the regular SerienRecorder autocheck runs, received 
		# TV-Planer emails will be used to program timers, even no marker 
		# has been created by SerienMarker before. The marker is created automatically, 
		# except for the correct url.  
		#
		if config.plugins.serienRec.tvplaner.value and self.emailData is not None:
			# check mailbox for TV-Planer EMail and create timer
			SRLogger.writeLog("\n---------' Verarbeite Daten aus TV-Planer E-Mail '---------\n", True)

			jobQueue = Queue.Queue()
			resultQueue = Queue.Queue()

			# Create the threads
			for i in range(2):
				worker = processEMailDataThread(self.emailData, jobQueue, resultQueue)
				worker.setDaemon(True)
				worker.start()

			for serienTitle,SerieUrl,SerieStaffel,SerieSender,AbEpisode,AnzahlAufnahmen,SerieEnabled,excludedWeekdays,skipSeriesServer,markerType in self.database.getMarkers(config.plugins.serienRec.BoxID.value, config.plugins.serienRec.NoOfRecords.value, self.emailData.keys()):
				print serienTitle
				if SerieEnabled:
					# Process only if series is enabled
					if 'Alle' in SerieSender:
						markerChannels = { x : x for x in webChannels }
					else:
						markerChannels = { x : x for x in SerieSender }

					jobQueue.put((markerChannels, SerieUrl, serienTitle, SerieStaffel, AbEpisode, AnzahlAufnahmen, current_time, future_time, excludedWeekdays))

			jobQueue.join()
			while not resultQueue.empty():
				(transmissions, seriesID, serienTitle, SerieStaffel, AbEpisode, AnzahlAufnahmen, current_time, future_time, excludedWeekdays) = resultQueue.get()
				self.processTransmission(transmissions, seriesID, serienTitle, SerieStaffel, AbEpisode, AnzahlAufnahmen, current_time, future_time, excludedWeekdays)
				resultQueue.task_done()

		self.createTimer()
		self.checkFinal()

	def createTimer(self, result=True):
		from SerienRecorderTimer import serienRecTimer
		timer = serienRecTimer()
		timer.setTempDB(self.tempDB)

		# versuche deaktivierte Timer zu erstellen
		timer.activate()

		# jetzt die Timer erstellen
		for x in range(self.noOfRecords):
			timer.search(x)

		# gleiche alte Timer mit EPG ab
		current_time = int(time.time())
		timer.adjustEPGtimes(current_time)
		SRLogger.writeLog("\n", True)

		# Datenbank aufräumen
		self.database.rebuild()
		self.tempDB.rebuild()

		global autoCheckFinished
		autoCheckFinished = True

		(countTimer, countTimerUpdate, countNotActiveTimer, countTimerFromWishlist, self.messageList) = timer.getCounts()

		# Statistik
		self.speedEndTime = time.clock()
		speedTime = (self.speedEndTime - self.speedStartTime)
		if config.plugins.serienRec.eventid.value:
			SRLogger.writeLog("%s/%s Serie(n) sind vorgemerkt davon wurde(n) %s Timer erstellt und %s Timer aktualisiert." % (str(self.countActivatedSeries), str(self.countSerien), str(countTimer), str(countTimerUpdate)), True)
			print "[SerienRecorder] %s/%s Serie(n) sind vorgemerkt davon wurde(n) %s Timer erstellt und %s Timer aktualisiert." % (str(self.countActivatedSeries), str(self.countSerien), str(countTimer), str(countTimerUpdate))
		else:
			SRLogger.writeLog("%s/%s Serie(n) sind vorgemerkt davon wurde(n) %s Timer erstellt." % (str(self.countActivatedSeries), str(self.countSerien), str(countTimer)), True)
			print "[SerienRecorder] %s/%s Serie(n) sind vorgemerkt davon wurde(n) %s Timer erstellt." % (str(self.countActivatedSeries), str(self.countSerien), str(countTimer))
		if countNotActiveTimer > 0:
			SRLogger.writeLog("%s Timer wurde(n) wegen Konflikten deaktiviert erstellt!" % str(countNotActiveTimer), True)
			print "[SerienRecorder] %s Timer wurde(n) wegen Konflikten deaktiviert erstellt!" % str(countNotActiveTimer)
		if countTimerFromWishlist > 0:
			SRLogger.writeLog("%s Timer vom Merkzettel wurde(n) erstellt!" % str(countTimerFromWishlist), True)
			print "[SerienRecorder] %s Timer vom Merkzettel wurde(n) erstellt!" % str(countTimerFromWishlist)
		SRLogger.writeLog("---------' Auto-Check beendet (Ausführungsdauer: %3.2f Sek.)'---------" % speedTime, True)
		print "[SerienRecorder] ---------' Auto-Check beendet (Ausführungsdauer: %3.2f Sek.)'---------" % speedTime
		if (config.plugins.serienRec.showNotification.value in ("2", "3")) and (not self.manuell):
			statisticMessage = "Serien vorgemerkt: %s/%s\nTimer erstellt: %s\nTimer aktualisiert: %s\nTimer mit Konflikten: %s\nTimer vom Merkzettel: %s" % (
			str(self.countActivatedSeries), str(self.countSerien), str(countTimer), str(countTimerUpdate),
			str(countNotActiveTimer), str(countTimerFromWishlist))
			newSeasonOrEpisodeMessage = ""
			if self.newSeriesOrEpisodesFound:
				newSeasonOrEpisodeMessage = "\n\nNeuer Serien- oder Staffelbeginn gefunden"

			Notifications.AddPopup("SerienRecorder Suchlauf für neue Timer wurde beendet.\n\n%s%s" % (
			statisticMessage, newSeasonOrEpisodeMessage), MessageBox.TYPE_INFO, timeout=10, id="Suchlauf wurde beendet")

		return result

	def checkFinal(self):
		print "[SerienRecorder] checkFinal"
		# final processing
		if config.plugins.serienRec.tvplaner.value and config.plugins.serienRec.tvplaner_movies.value:
			# remove all serien markers created for movies
			try:
				self.database.removeMovieMarkers()
				print "[SerienRecorder] ' TV-Planer FilmMarker gelöscht '"
			except:
				SRLogger.writeLog("' TV-Planer FilmMarker löschen fehlgeschlagen '", True)
				print "[SerienRecorder] ' TV-Planer FilmMarker löschen fehlgeschlagen '"
			global transmissionFailed
			if transmissionFailed: 
				# always do fullcheck after transmission error
				config.plugins.serienRec.tvplaner_last_full_check.value = int(0)
				config.plugins.serienRec.tvplaner_last_full_check.save()
				configfile.save()

		if config.plugins.serienRec.AutoBackup.value == "after":
			createBackup()

		from SerienRecorderTVPlaner import backupTVPlanerHTML
		backupTVPlanerHTML()

		# trigger read of log file
		global autoCheckFinished
		autoCheckFinished = True
		print "[SerienRecorder] checkFinal: autoCheckFinished"
		if config.plugins.serienRec.autochecktype.value == "1":
			lt = time.localtime()
			deltatime = self.getNextAutoCheckTimer(lt)
			SRLogger.writeLog("\nVerbleibende Zeit bis zum nächsten Auto-Check: %s Stunden\n" % TimeHelpers.td2HHMMstr(datetime.timedelta(minutes=deltatime+int(config.plugins.serienRec.maxDelayForAutocheck.value))), True)
			if config.plugins.serienRec.tvplaner_full_check.value:
				autoCheckDays = ((int(config.plugins.serienRec.tvplaner_last_full_check.value) + (int(config.plugins.serienRec.checkfordays.value) - 1) * 86400) - int(time.time())) / 86400
				if autoCheckDays < 0:
					autoCheckDays = 0
				SRLogger.writeLog("Verbleibende Zeit bis zum nächsten vollen Auto-Check: %d Tage" % autoCheckDays, True)

		self.tempDB = None
		self.database = None

		# in den deep-standby fahren.
		self.askForDSB()

	def processTransmission(self, data, serien_id, serien_name, staffeln, AbEpisode, AnzahlAufnahmen, current_time, future_time, excludedWeekdays=None):
		print "[SerienRecorder] processTransmissions: %r" % serien_name
		self.count_url += 1

		if data is None:
			SRLogger.writeLog("Fehler beim Abrufen und Verarbeiten der Ausstrahlungstermine [%s]" % serien_name, True)
			#print "[SerienRecorder] processTransmissions: no Data"
			return

		(fromTime, toTime) = self.database.getTimeSpan(serien_name, config.plugins.serienRec.globalFromTime.value, config.plugins.serienRec.globalToTime.value)
		if self.noOfRecords < AnzahlAufnahmen:
			self.noOfRecords = AnzahlAufnahmen

		TimeSpan_time = int(future_time)
		if config.plugins.serienRec.forceRecording.value:
			TimeSpan_time += (int(config.plugins.serienRec.TimeSpanForRegularTimer.value) - int(config.plugins.serienRec.checkfordays.value)) * 86400

		# loop over all transmissions
		self.tempDB.beginTransaction()
		for current_serien_name, sender, startzeit, endzeit, staffel, episode, title, status in data:
			start_unixtime = startzeit
			end_unixtime = endzeit

			# install missing covers
			(dirname, dirname_serie) = getDirname(self.database, serien_name, staffel)
			STBHelpers.createDirectory(current_serien_name, dirname, dirname_serie, True)

			# setze die vorlauf/nachlauf-zeit
			(margin_before, margin_after) = self.database.getMargins(serien_name, sender, config.plugins.serienRec.margin_before.value, config.plugins.serienRec.margin_after.value)
			start_unixtime = int(start_unixtime) - (int(margin_before) * 60)
			end_unixtime = int(end_unixtime) + (int(margin_after) * 60)

			# if there is no season or episode number it can be a special
			# but if we have more than one special and wunschliste.de does not
			# give us an episode number we are unable to differentiate between these specials
			if not staffel and not episode:
				staffel = "S"
				episode = "00"

			# initialize strings
			seasonEpisodeString = "S%sE%s" % (str(staffel).zfill(2), str(episode).zfill(2))
			label_serie = "%s - %s - %s" % (serien_name, seasonEpisodeString, title)

			if not config.plugins.serienRec.forceRecording.value:
				if (int(fromTime) > 0) or (int(toTime) < (23*60)+59):
					start_time = (time.localtime(int(start_unixtime)).tm_hour * 60) + time.localtime(int(start_unixtime)).tm_min
					end_time = (time.localtime(int(end_unixtime)).tm_hour * 60) + time.localtime(int(end_unixtime)).tm_min
					if not TimeHelpers.allowedTimeRange(fromTime, toTime, start_time, end_time):
						print "[SerienRecorder] processTransmissions time range ignore: %r" % serien_name
						timeRangeConfigured = "%s:%s - %s:%s" % (str(int(fromTime) / 60).zfill(2), str(int(fromTime) % 60).zfill(2), str(int(toTime) / 60).zfill(2), str(int(toTime) % 60).zfill(2))
						timeRangeTransmission = "%s:%s - %s:%s" % (str(int(start_time) / 60).zfill(2), str(int(start_time) % 60).zfill(2), str(int(end_time) / 60).zfill(2), str(int(end_time) % 60).zfill(2))
						SRLogger.writeLogFilter("timeRange", "' %s ' - Sendung (%s) nicht in Zeitspanne [%s]" % (label_serie, timeRangeTransmission, timeRangeConfigured))
						continue


			# Process channel relevant data

			##############################
			#
			# CHECK
			#
			# ueberprueft welche sender aktiviert und eingestellt sind.
			#
			(webChannel, stbChannel, stbRef, altstbChannel, altstbRef, status) = self.checkSender(sender)
			if stbChannel == "":
				SRLogger.writeLogFilter("channels", "' %s ' - STB-Sender nicht gefunden ' -> ' %s '" % (label_serie, webChannel))
				continue

			if int(status) == 0:
				SRLogger.writeLogFilter("channels", "' %s ' - STB-Sender deaktiviert -> ' %s '" % (label_serie, webChannel))
				continue

			##############################
			#
			# CHECK
			#
			# ueberprueft welche staffel(n) erlaubt sind
			#
			serieAllowed = False
			if -2 in staffeln:                          	# 'Manuell'
				serieAllowed = False
			elif (-1 in staffeln) and (0 in staffeln):		# 'Alle'
				serieAllowed = True
			elif str(staffel).isdigit():
				if int(staffel) == 0:
					if str(episode).isdigit():
						if int(episode) < int(AbEpisode):
							if config.plugins.serienRec.writeLogAllowedEpisodes.value:
								liste = staffeln[:]
								liste.sort()
								liste.reverse()
								if -1 in staffeln:
									liste.remove(-1)
									liste[0] = "ab %s" % liste[0]
								liste.reverse()
								liste.insert(0, "0 ab E%s" % str(AbEpisode).zfill(2))
								SRLogger.writeLogFilter("allowedEpisodes", "' %s ' - Episode nicht erlaubt -> ' %s ' -> ' %s '" % (label_serie, seasonEpisodeString, str(liste).replace("'", "").replace('"', "")))
							continue
						else:
							serieAllowed = True
				elif int(staffel) in staffeln:
					serieAllowed = True
				elif -1 in staffeln:		# 'folgende'
					if int(staffel) >= max(staffeln):
						serieAllowed = True
			elif self.database.getSpecialsAllowed(serien_name):
				serieAllowed = True

			vomMerkzettel = False
			if not serieAllowed:
				if self.database.hasBookmark(serien_name, staffel, episode):
					SRLogger.writeLog("' %s ' - Timer vom Merkzettel wird angelegt @ %s" % (label_serie, stbChannel), True)
					serieAllowed = True
					vomMerkzettel = True

			if not serieAllowed:
				if config.plugins.serienRec.writeLogAllowedEpisodes.value:
					liste = staffeln[:]
					liste.sort()
					liste.reverse()
					if -1 in staffeln:
						liste.remove(-1)
						liste[0] = "ab %s" % liste[0]
					liste.reverse()
					if str(episode).isdigit():
						if int(episode) < int(AbEpisode):
							liste.insert(0, "0 ab E%s" % str(AbEpisode).zfill(2))
					if -2 in staffeln:
						liste.remove(-2)
						liste.insert(0, "Manuell")
						SRLogger.writeLogFilter("allowedEpisodes", "' %s ' - Staffel nicht erlaubt -> ' %s ' -> ' %s '" % (label_serie, seasonEpisodeString, str(liste).replace("'", "").replace('"', "")))
				continue


			##############################
			#
			# try to get eventID (eit) from epgCache
			#
			eit, new_end_unixtime, new_start_unixtime = STBHelpers.getStartEndTimeFromEPG(start_unixtime, end_unixtime, margin_before, margin_after, serien_name, stbRef)
			alt_eit = 0
			alt_end_unixtime = end_unixtime
			alt_start_unixtime = start_unixtime
			if altstbRef:
				alt_eit, alt_end_unixtime, alt_start_unixtime = STBHelpers.getStartEndTimeFromEPG(start_unixtime, end_unixtime, margin_before, margin_after, serien_name, altstbRef)

			updateFromEPG = self.database.getUpdateFromEPG(serien_name)
			if updateFromEPG is False:
				new_start_unixtime = start_unixtime
				new_end_unixtime = end_unixtime
				alt_end_unixtime = end_unixtime
				alt_start_unixtime = start_unixtime

			(dirname, dirname_serie) = getDirname(self.database, serien_name, staffel)
			self.tempDB.addTransmission([(current_time, future_time, serien_name, staffel, episode, seasonEpisodeString, title, label_serie, webChannel, stbChannel, stbRef, new_start_unixtime, new_end_unixtime, eit, altstbChannel, altstbRef, alt_start_unixtime, alt_end_unixtime, alt_eit, dirname, AnzahlAufnahmen, fromTime, toTime, int(vomMerkzettel), excludedWeekdays, updateFromEPG)])
		self.tempDB.commitTransaction()


	def askForDSB(self):
		if not self.manuell:
			if config.plugins.serienRec.afterAutocheck.value != "0":
				if config.plugins.serienRec.DSBTimeout.value > 0 and not Screens.Standby.inStandby:
					print "[SerienRecorder] Try to display shutdown notification..."
					try:
						notificationText = "Soll der SerienRecorder die Box in den Ruhemodus (Standby) schalten?"
						if config.plugins.serienRec.afterAutocheck.value == "2":
							notificationText = "Soll der SerienRecorder die Box ausschalten (Deep-Standby)?"
						Notifications.AddNotificationWithCallback(self.gotoDeepStandby, MessageBox, text=notificationText, type=MessageBox.TYPE_YESNO, timeout=config.plugins.serienRec.DSBTimeout.value, default=True)
					except Exception as e:
						print "[SerienRecorder] Could not display shutdown notification - shutdown box without notification... (%s)" % str(e)
						self.gotoDeepStandby(True)
				else:
					self.gotoDeepStandby(True)

	def gotoDeepStandby(self, answer):
		if answer:
			if config.plugins.serienRec.afterAutocheck.value == "2":
				if not NavigationInstance.instance.RecordTimer.isRecording():
					for each in self.messageList:
						Notifications.RemovePopup(each[3])

					print "[SerienRecorder] gehe in Deep-Standby"
					SRLogger.writeLog("gehe in Deep-Standby")
					if Screens.Standby.inStandby:
						from RecordTimer import RecordTimerEntry
						RecordTimerEntry.TryQuitMainloop()
					else:
						Notifications.AddNotificationWithID("Shutdown", Screens.Standby.TryQuitMainloop, 1)
				else:
					print "[SerienRecorder] Eine laufende Aufnahme verhindert den Deep-Standby"
					SRLogger.writeLog("Eine laufende Aufnahme verhindert den Deep-Standby")
			else:
				print "[SerienRecorder] gehe in Standby"
				SRLogger.writeLog("gehe in Standby")
				Notifications.AddNotification(Screens.Standby.Standby)

	def checkSender(self, channel):
		if channel.lower() in self.senderListe:
			(webChannel, stbChannel, stbRef, altstbChannel, altstbRef, status) = self.senderListe[channel.lower()]
		else:
			webChannel = channel
			stbChannel = ""
			stbRef = ""
			altstbChannel = ""
			altstbRef = ""
			status = "0"
		return webChannel, stbChannel, stbRef, altstbChannel, altstbRef, status

	@staticmethod
	def dataError(error):
		print "[SerienRecorder] Es ist ein Fehler aufgetreten - die Daten konnten nicht abgerufen/verarbeitet werden: (%s)" % error
class serienRecMainScreen(serienRecBaseScreen, Screen, HelpableScreen):
	def __init__(self, session):
		serienRecBaseScreen.__init__(self, session)
		Screen.__init__(self, session)
		HelpableScreen.__init__(self)
		self.session = session
		self.picload = ePicLoad()
		self.picloader = None
		self.ErrorMsg = "unbekannt"
		self.skin = None
		self.chooseMenuList = None
		self.chooseMenuList_popup = None
		self.popup_list = []
		self.piconLoader = PiconLoader()
		self.database = None
		self.singleTimer_conn = None
		self.displayTimer_conn = None

		self["actions"] = HelpableActionMap(self, "SerienRecorderActions", {
			"ok"    : (self.keyOK, "Marker für die ausgewählte Serie hinzufügen"),
			"cancel": (self.keyCancel, "SerienRecorder beenden"),
			"left"  : (self.keyLeft, "zur vorherigen Seite blättern"),
			"right" : (self.keyRight, "zur nächsten Seite blättern"),
			"up"    : (self.keyUp, "eine Zeile nach oben"),
			"down"  : (self.keyDown, "eine Zeile nach unten"),
			"red"	: (self.keyRed, "Anzeige-Modus auswählen"),
			"green"	: (self.keyGreen, "Ansicht Sender-Zuordnung öffnen"),
			"yellow": (self.keyYellow, "Ansicht Serien-Marker öffnen"),
			"blue"	: (self.keyBlue, "Ansicht Timer-Liste öffnen"),
			"info" 	: (self.keyCheck, "Suchlauf für Timer starten"),
			"menu"	: (self.recSetup, "Menü für globale Einstellungen öffnen"),
			"nextBouquet" : (self.nextPage, "Serienplaner des nächsten Tages laden"),
			"prevBouquet" : (self.backPage, "Serienplaner des vorherigen Tages laden"),
			"startTeletext"  : (self.wunschliste, "Informationen zur ausgewählten Serie auf Wunschliste anzeigen"),
			"0"		: (self.readLogFile, "Log-File des letzten Suchlaufs anzeigen"),
			"1"		: (self.searchSeries, "Serie manuell suchen"),
			"2"		: (self.reloadSerienplaner, "Serienplaner neu laden"),
			"3"		: (self.showProposalDB, "Liste der Serien/Staffel-Starts anzeigen"),
			"4"		: (self.serieInfo, "Informationen zur ausgewählten Serie anzeigen"),
			"6"		: (self.showConflicts, "Liste der Timer-Konflikte anzeigen"),
			"7"		: (self.showWishlist, "Merkzettel (vorgemerkte Folgen) anzeigen"),
			"5"		: (self.imapTest, "IMAP Test"),
		}, -1)
		self.helpList[0][2].sort()

		self["helpActions"] = ActionMap(["SerienRecorderActions" ,], {
			"displayHelp"      : self.showHelp,
			"displayHelp_long" : self.showManual,
		}, 0)

		SerienRecorder.ReadConfigFile()

		if not os.path.exists(config.plugins.serienRec.piconPath.value):
			config.plugins.serienRec.showPicons.value = False

		self.setupSkin()

		if config.plugins.serienRec.updateInterval.value == 24:
			config.plugins.serienRec.timeUpdate.value = True
		elif config.plugins.serienRec.updateInterval.value == 0:
			config.plugins.serienRec.timeUpdate.value = False
		else:
			config.plugins.serienRec.timeUpdate.value = False

		global showMainScreen
		if config.plugins.serienRec.firstscreen.value == "0":
			showMainScreen = True
		else:
			showMainScreen = False

		self.pRegional = 0
		self.pPaytv = 1
		self.pPrime = 1
		self.page = 0
		self.modus = "list"
		self.loading = True
		self.daylist = [[]]
		self.displayTimer = None
		self.displayMode = 1
		self.serviceRefs = None

		self.onLayoutFinish.append(self.setSkinProperties)

		self.onFirstExecBegin.append(self.showSplashScreen)
		self.onFirstExecBegin.append(self.checkForUpdate)

		if config.plugins.serienRec.showStartupInfoText.value:
			if fileExists("%sStartupInfoText" % SerienRecorder.serienRecMainPath):
				self.onFirstExecBegin.append(self.showInfoText)
			else:
				self.onFirstExecBegin.append(self.startScreen)
		else:
			self.onFirstExecBegin.append(self.startScreen)
		self.onClose.append(self.__onClose)

	def imapTest(self):
		from SerienRecorderTVPlaner import imaptest
		imaptest(self.session)

	def showInfoText(self):
		from SerienRecorderStartupInfoScreen import ShowStartupInfo
		self.session.openWithCallback(self.startScreen, ShowStartupInfo)

	def showSplashScreen(self):
		from SerienRecorderSplashScreen import ShowSplashScreen
		self.session.openWithCallback(self.checkForUpdate, ShowSplashScreen, config.plugins.serienRec.showversion.value)

	def checkForUpdate(self):
		if config.plugins.serienRec.Autoupdate.value:
			from SerienRecorderUpdateScreen import checkGitHubUpdate
			checkGitHubUpdate(self.session).checkForUpdate()
		self.startScreen()

	def callHelpAction(self, *args):
		HelpableScreen.callHelpAction(self, *args)

	def setSkinProperties(self):
		super(self.__class__, self).setSkinProperties()

		self['text_red'].setText("Anzeige-Modus")
		self['text_green'].setText("Sender zuordnen")
		self['text_ok'].setText("Marker hinzufügen")
		self['text_yellow'].setText("Serien Marker")
		self['text_blue'].setText("Timer-Liste")
		self.num_bt_text[0][1] = "IMAP-Test"
		self.num_bt_text[1][0] = "Serie suchen"
		self.num_bt_text[2][0] = "Neu laden"
		self.num_bt_text[2][2] = "Timer suchen"

		super(self.__class__, self).startDisplayTimer()

	def setupSkin(self):
		self.skin = None
		InitSkin(self)

		self.chooseMenuList = MenuList([], enableWrapAround=True, content=eListboxPythonMultiContent)
		self.chooseMenuList.l.setFont(0, gFont('Regular', 20 + int(config.plugins.serienRec.listFontsize.value)))
		self.chooseMenuList.l.setItemHeight(int(50 * skinFactor))
		self['menu_list'] = self.chooseMenuList
		self['menu_list'].show()

		# popup
		self.chooseMenuList_popup = MenuList([], enableWrapAround=True, content=eListboxPythonMultiContent)
		self.chooseMenuList_popup.l.setFont(0, gFont('Regular', 20 + int(config.plugins.serienRec.listFontsize.value)))
		self.chooseMenuList_popup.l.setItemHeight(int(30 * skinFactor))
		self['popup_list'] = self.chooseMenuList_popup
		self['popup_list'].hide()

		self['title'].setText("Lade infos from Web...")

		if config.plugins.serienRec.showCover.value:
			self['cover'].show()

		if not config.plugins.serienRec.showAllButtons.value:
			self['bt_red'].show()
			self['bt_green'].show()
			self['bt_ok'].show()
			self['bt_yellow'].show()
			self['bt_blue'].show()
			self['bt_exit'].show()
			self['bt_text'].show()
			self['bt_epg'].show()
			self['bt_info'].show()
			self['bt_menu'].show()

			self['text_red'].show()
			self['text_green'].show()
			self['text_ok'].show()
			self['text_yellow'].show()
			self['text_blue'].show()
			self['text_0'].show()
			self['text_1'].show()
			self['text_2'].show()
			self['text_3'].show()
			self['text_4'].show()

	def updateMenuKeys(self):
		updateMenuKeys(self)

	def test(self):
		i = 0

	def reloadSerienplaner(self):
		# lt = datetime.datetime.now()
		# lt += datetime.timedelta(days=self.page)
		# key = time.strftime('%d.%m.%Y', lt.timetuple())
		# cache = serienRecMainScreen.loadPlanerData(config.plugins.serienRec.screenplaner.value)
		# if key in cache:
		# 	del cache[key]
		self.readPlanerData(False)

	def readLogFile(self):
		from SerienRecorderLogScreen import serienRecReadLog
		self.session.open(serienRecReadLog)

	def showProposalDB(self):
		from SerienRecorderSeasonBeginsScreen import serienRecShowSeasonBegins
		self.session.openWithCallback(self.readPlanerData, serienRecShowSeasonBegins)

	def searchSeries(self):
		if self.modus == "list":
			self.session.openWithCallback(self.wSearch, NTIVirtualKeyBoard, title = "Serien Titel eingeben:")

	def wSearch(self, serien_name):
		if serien_name:
			from SerienRecorderSearchResultScreen import serienRecSearchResultScreen
			self.session.openWithCallback(self.handleSeriesSearchEnd, serienRecSearchResultScreen, serien_name)

	def handleSeriesSearchEnd(self, serien_name=None):
		if serien_name:
			from SerienRecorderMarkerScreen import serienRecMarker
			self.session.openWithCallback(self.readPlanerData, serienRecMarker, serien_name)
		else:
			self.readPlanerData(False)

	def serieInfo(self):
		if self.loading:
			return

		check = self['menu_list'].getCurrent()
		if check is None:
			return

		(serien_name, serien_id) = self.getSeriesNameID()
		from SerienRecorderSeriesInfoScreen import serienRecShowInfo
		self.session.open(serienRecShowInfo, serien_name, serien_id)

	def wunschliste(self):
		(serien_name, serien_id) = self.getSeriesNameID()
		super(self.__class__, self).wunschliste(serien_id)

	def setHeadline(self):
		if int(config.plugins.serienRec.screenplaner.value) == 1:
			self['headline'].setText("Serien-Planer (Serien Tagesübersicht)")
			self['text_red'].setText("Top 30")
		elif int(config.plugins.serienRec.screenplaner.value) == 2:
			self['headline'].setText("Top 30 SerienRecorder Serien")
			self['text_red'].setText("Tagesübersicht")

		self['headline'].instance.setForegroundColor(parseColor("red"))

	def recSetup(self):
		from SerienRecorderSetupScreen import serienRecSetup
		self.session.openWithCallback(self.setupClose, serienRecSetup)

	def setupClose(self, result):
		super(self.__class__, self).setupClose(result)
		if result[1]:
			self.readPlanerData()

	def startScreen(self):
		print "[SerienRecorder] version %s is running..." % config.plugins.serienRec.showversion.value

		if not SerienRecorder.refreshTimer:
			if config.plugins.serienRec.timeUpdate.value:
				SerienRecorder.serienRecCheckForRecording(self.session, False, False)

		if not SerienRecorder.initDB():
			self.keyCancel()
			self.close()
			return

		self.database = SRDatabase(SerienRecorder.serienRecDataBaseFilePath)
		if not self.database.hasChannels():
			print "[SerienRecorder] Channellist is empty !"
			from SerienRecorderChannelScreen import serienRecMainChannelEdit
			self.session.openWithCallback(self.readPlanerData, serienRecMainChannelEdit)
		else:
			self.serviceRefs = self.database.getActiveServiceRefs()
			if not showMainScreen:
				from SerienRecorderMarkerScreen import serienRecMarker
				self.session.openWithCallback(self.readPlanerData, serienRecMarker)
			else:
				self.readPlanerData(False)

	def readPlanerData(self, answer=True):
		print "[SerienRecorder] readPlanerData"
		if not showMainScreen:
			self.keyCancel()
			self.close()
			return

		self.loading = True
		cache = serienRecSeriesPlanner.loadPlanerData(config.plugins.serienRec.screenplaner.value)

		if answer:
			cache.clear()

		self.setHeadline()
		self['title'].instance.setForegroundColor(parseColor("foreground"))

		lt = datetime.datetime.now()
		if config.plugins.serienRec.screenplaner.value == 1:
			lt += datetime.timedelta(days=self.page)
		key = time.strftime('%d.%m.%Y', lt.timetuple())
		if key in cache:
			try:
				self['title'].setText("Lade Infos vom Speicher...")
				if config.plugins.serienRec.screenplaner.value == 1:
					self.processPlanerData(cache[key], True)
				else:
					self.processTopThirty(cache[key], True)
			except:
				SRLogger.writeLog("Fehler beim Abrufen und Verarbeiten der Daten\n", True)
		else:
			self['title'].setText("Lade Infos vom Web...")
			webChannels = self.database.getActiveChannels()
			try:
				if config.plugins.serienRec.screenplaner.value == 1:
					planerData = SeriesServer().doGetPlanerData(int(self.page), webChannels)
					self.processPlanerData(planerData, False)
				else:
					topThirtyData = SeriesServer().doGetTopThirty()
					self.processTopThirty(topThirtyData, False)
			except:
				SRLogger.writeLog("Fehler beim Abrufen und Verarbeiten der Daten\n", True)

	def processPlanerData(self, data, useCache=False):
		if not data or len(data) == 0:
			self['title'].setText("Fehler beim Abrufen der SerienPlaner-Daten")
			return
		if useCache:
			(headDate, self.daylist) = data
		else:
			self.daylist = [[]]
			headDate = [data["date"]]


			markers = self.database.getAllMarkerStatusForBoxID(config.plugins.serienRec.BoxID.value)
			timers = self.database.getTimer(self.page)

			for event in data["events"]:
				aufnahme = False
				serieAdded = 0
				start_h = event["time"][:+2]
				start_m = event["time"][+3:]
				start_time = TimeHelpers.getUnixTimeWithDayOffset(start_h, start_m, self.page)

				serien_name = event["name"].encode("utf-8")
				serien_name_lower = serien_name.lower()
				serien_id = int(event["id"])
				sender = event["channel"]
				title = event["title"].encode("utf-8")
				staffel = event["season"]
				episode = event["episode"]
				self.ErrorMsg = "%s - S%sE%s - %s (%s)" % \
				(serien_name, str(staffel).zfill(2), str(episode).zfill(2), title, sender)

				serienTimers = [timer for timer in timers if timer[0] == serien_name_lower]
				serienTimersOnChannel = [serienTimer for serienTimer in serienTimers if
				                         serienTimer[2] == sender.lower()]
				for serienTimerOnChannel in serienTimersOnChannel:
					if (int(serienTimerOnChannel[1]) >= (int(start_time) - 300)) and (
							int(serienTimerOnChannel[1]) < (int(start_time) + 300)):
						aufnahme = True

				# 0 = no marker, 1 = active marker, 2 = deactive marker
				if serien_id in markers:
					serieAdded = 1 if markers[serien_id] else 2

				staffel = str(staffel).zfill(2)
				episode = str(episode).zfill(2)

				##############################
				#
				# CHECK
				#
				# ueberprueft anhand des Seriennamen, Season, Episode ob die serie bereits auf der HDD existiert
				#
				seasonEpisodeString = "S%sE%s" % (str(staffel).zfill(2), str(episode).zfill(2))

				bereits_vorhanden = False
				if config.plugins.serienRec.sucheAufnahme.value:
					(dirname, dirname_serie) = getDirname(self.database, serien_name, staffel)
					if str(episode).isdigit():
						if int(episode) == 0:
							bereits_vorhanden = STBHelpers.countEpisodeOnHDD(dirname, seasonEpisodeString, serien_name,
							                                                 False, title) > 0 and True or False
						else:
							bereits_vorhanden = STBHelpers.countEpisodeOnHDD(dirname, seasonEpisodeString, serien_name,
							                                                 False) > 0 and True or False
					else:
						bereits_vorhanden = STBHelpers.countEpisodeOnHDD(dirname, seasonEpisodeString, serien_name,
						                                                 False) > 0 and True or False

				title = "%s - %s" % (seasonEpisodeString, title)
				regional = False
				paytv = False
				neu = event["new"]
				prime = False
				transmissionTime = event["time"]
				url = ''
				self.daylist[0].append((
				                       regional, paytv, neu, prime, transmissionTime, url, serien_name, sender, staffel,
				                       episode, title, aufnahme, serieAdded, bereits_vorhanden, serien_id))

			print "[SerienRecorder] Es wurden %s Serie(n) gefunden" % len(self.daylist[0])

			if headDate:
				d = headDate[0].split(',')
				d.reverse()
				key = d[0].strip()
				cache = serienRecSeriesPlanner.loadPlanerData(1)
				cache.update({key: (headDate, self.daylist)})
				if config.plugins.serienRec.planerCacheEnabled.value:
					serienRecSeriesPlanner.writePlanerData(1, cache)

		self.loading = False

		if len(self.daylist[0]) != 0:
			if headDate:
				self['title'].setText(
					"Es wurden für - %s - %s Serie(n) gefunden." % (headDate[0], len(self.daylist[0])))
				self['title'].instance.setForegroundColor(parseColor("foreground"))
			else:
				self['title'].setText("Es wurden für heute %s Serie(n) gefunden." % len(self.daylist[0]))
				self['title'].instance.setForegroundColor(parseColor("foreground"))
			self.chooseMenuList.setList(map(self.buildPlanerList, self.daylist[0]))
			self.ErrorMsg = "'getCover()'"
			self.getCover()
		else:
			if int(self.page) < 1 and not int(self.page) == 0:
				self.page -= 1
			self['title'].setText("Es wurden für heute %s Serie(n) gefunden." % len(self.daylist[0]))
			self['title'].instance.setForegroundColor(parseColor("foreground"))
			print "[SerienRecorder] Wunschliste Serien-Planer -> LISTE IST LEER !!!!"
			self.chooseMenuList.setList(map(self.buildPlanerList, self.daylist[0]))

	def processTopThirty(self, data, useCache=False):
		if not data or len(data) == 0:
			self['title'].setText("Fehler beim Abrufen der SerienPlaner-Daten")
			return
		if useCache:
			(headDate, self.daylist) = data
		else:
			self.daylist = [[]]
			headDate = [data["date"]]

			markers = self.database.getAllMarkerStatusForBoxID(config.plugins.serienRec.BoxID.value)

			rank = 0
			for serie in data["series"]:
				serien_name = serie["name"].encode("utf-8")
				serien_id = int(serie["id"])
				average = serie["average"]

				# 0 = no marker, 1 = active marker, 2 = deactive marker
				serieAdded = 0
				if serien_id in markers:
					serieAdded = 1 if markers[serien_id] else 2

				rank += 1
				self.daylist[0].append((serien_name, average, serien_id, serieAdded, rank))

			if headDate:
				d = headDate[0].split(',')
				d.reverse()
				key = d[0].strip()
				cache = serienRecSeriesPlanner.loadPlanerData(2)
				cache.update({key: (headDate, self.daylist)})
				if config.plugins.serienRec.planerCacheEnabled.value:
					serienRecSeriesPlanner.writePlanerData(2, cache)

		self.loading = False
		self['title'].setText("")
		self.chooseMenuList.setList(map(self.buildTopThirtyList, self.daylist[0]))
		self.ErrorMsg = "'getCover()'"
		self.getCover()

	def buildPlanerList(self, entry):
		(regional, paytv, neu, prime, transmissionTime, url, serien_name, sender, staffel, episode, title, aufnahme,
		 serieAdded, bereits_vorhanden, serien_id) = entry

		imageNone = "%simages/black.png" % SerienRecorder.serienRecMainPath
		imageNeu = "%simages/neu.png" % SerienRecorder.serienRecMainPath
		imageTimer = "%simages/timer.png" % SerienRecorder.serienRecMainPath
		imageHDD = "%simages/hdd_icon.png" % SerienRecorder.serienRecMainPath

		if serieAdded == 1:
			seriesColor = parseColor('green').argb()
		elif serieAdded == 2:
			seriesColor = parseColor('red').argb()
		else:
			seriesColor = None
		if aufnahme:
			seriesColor = parseColor('blue').argb()

		titleColor = timeColor = parseColor('foreground').argb()

		if int(neu) == 0:
			imageNeu = imageNone

		if bereits_vorhanden:
			imageHDDTimer = imageHDD
		elif aufnahme:
			imageHDDTimer = imageTimer
		else:
			imageHDDTimer = imageNone

		if config.plugins.serienRec.showPicons.value != "0":
			picon = loadPNG(imageNone)
			if sender and self.serviceRefs.get(sender):
				# Get picon by reference or name
				piconPath = self.piconLoader.getPicon(self.serviceRefs.get(sender)[0] if config.plugins.serienRec.showPicons.value == "1" else self.serviceRefs.get(sender)[1])
				if piconPath:
					self.picloader = PicLoader(80 * skinFactor, 40 * skinFactor)
					picon = self.picloader.load(piconPath)
					self.picloader.destroy()

			return [entry,
			        (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 5, 5 * skinFactor, 80 * skinFactor,
			         40 * skinFactor, picon),
			        (
			        eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 330 * skinFactor, 7 * skinFactor, 30 * skinFactor,
			        22 * skinFactor, loadPNG(imageNeu)),
			        (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 330 * skinFactor, 30 * skinFactor,
			         30 * skinFactor, 22 * skinFactor, loadPNG(imageHDDTimer)),
			        (eListboxPythonMultiContent.TYPE_TEXT, 100 * skinFactor, 3, 200 * skinFactor, 26 * skinFactor, 0,
			         RT_HALIGN_LEFT | RT_VALIGN_CENTER, sender),
			        (eListboxPythonMultiContent.TYPE_TEXT, 100 * skinFactor, 29 * skinFactor, 150 * skinFactor,
			         18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, transmissionTime, timeColor, timeColor),
			        (eListboxPythonMultiContent.TYPE_TEXT, 365 * skinFactor, 3, 500 * skinFactor, 26 * skinFactor, 0,
			         RT_HALIGN_LEFT | RT_VALIGN_CENTER, serien_name, seriesColor, seriesColor),
			        (eListboxPythonMultiContent.TYPE_TEXT, 365 * skinFactor, 29 * skinFactor, 500 * skinFactor,
			         18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, title, titleColor, titleColor)
			        ]
		else:
			return [entry,
			        (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 5, 7, 30 * skinFactor, 22 * skinFactor,
			         loadPNG(imageNeu)),
			        (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 5, 30 * skinFactor, 30 * skinFactor,
			         22 * skinFactor, loadPNG(imageHDDTimer)),
			        (eListboxPythonMultiContent.TYPE_TEXT, 40 * skinFactor, 3, 280 * skinFactor, 26 * skinFactor, 0,
			         RT_HALIGN_LEFT | RT_VALIGN_CENTER, sender),
			        (eListboxPythonMultiContent.TYPE_TEXT, 40 * skinFactor, 29 * skinFactor, 150 * skinFactor,
			         18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, transmissionTime, timeColor, timeColor),
			        (eListboxPythonMultiContent.TYPE_TEXT, 340 * skinFactor, 3, 520 * skinFactor, 26 * skinFactor, 0,
			         RT_HALIGN_LEFT | RT_VALIGN_CENTER, serien_name, seriesColor, seriesColor),
			        (eListboxPythonMultiContent.TYPE_TEXT, 340 * skinFactor, 29 * skinFactor, 520 * skinFactor,
			         18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, title, titleColor, titleColor)
			        ]

	@staticmethod
	def buildTopThirtyList(entry):
		(serien_name, average, serien_id, serieAdded, rank) = entry

		if serieAdded == 1:
			seriesColor = parseColor('green').argb()
		elif serieAdded == 2:
			seriesColor = parseColor('red').argb()
		else:
			seriesColor = None

		title = "%d Abrufe/Tag" % average
		titleColor = parseColor('foreground').argb()

		rank = "%d." % rank

		return [entry,
		        (eListboxPythonMultiContent.TYPE_TEXT, 5 * skinFactor, 3, 40 * skinFactor, 26 * skinFactor, 0,
		         RT_HALIGN_RIGHT | RT_VALIGN_CENTER, rank, titleColor, titleColor),
		        (eListboxPythonMultiContent.TYPE_TEXT, 70 * skinFactor, 3, 520 * skinFactor, 26 * skinFactor, 0,
		         RT_HALIGN_LEFT | RT_VALIGN_CENTER, serien_name, seriesColor, seriesColor),
		        (eListboxPythonMultiContent.TYPE_TEXT, 70 * skinFactor, 29 * skinFactor, 520 * skinFactor,
		         18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, title, titleColor, titleColor)
		        ]

	def keyOK(self):
		if self.modus == "list":
			if self.loading:
				return

			check = self['menu_list'].getCurrent()
			if check is None:
				return

			(serien_name, serien_id) = self.getSeriesNameID()
			if config.plugins.serienRec.activateNewOnThisSTBOnly.value:
				boxID = None
			else:
				boxID = config.plugins.serienRec.BoxID.value

			if self.database.addMarker(str(serien_id), serien_name, '', boxID, 0):
				SRLogger.writeLog("\nSerien Marker für ' %s ' wurde angelegt" % serien_name, True)
				self['title'].setText("Serie '- %s -' zum Serien Marker hinzugefügt." % serien_name)
				self['title'].instance.setForegroundColor(parseColor("green"))
				if config.plugins.serienRec.tvplaner_full_check.value:
					config.plugins.serienRec.tvplaner_last_full_check.value = int(0)
					config.plugins.serienRec.tvplaner_last_full_check.save()
					SerienRecorder.configfile.save()
				if config.plugins.serienRec.openMarkerScreen.value:
					from SerienRecorderMarkerScreen import serienRecMarker
					self.session.open(serienRecMarker, serien_name)
			else:
				self['title'].setText("Serie '- %s -' existiert bereits im Serien Marker." % serien_name)
				self['title'].instance.setForegroundColor(parseColor("red"))

	def getCover(self):
		if self.loading:
			return

		check = self['menu_list'].getCurrent()
		if check is None:
			return

		(serien_name, serien_id) = self.getSeriesNameID()
		self.ErrorMsg = "'getCover()'"
		SerienRecorder.getCover(self, serien_name, serien_id)

	def keyRed(self):
		if self.modus == "list":
			if config.plugins.serienRec.screenplaner.value == 1:
				config.plugins.serienRec.screenplaner.value = 2
			else:
				config.plugins.serienRec.screenplaner.value = 1
			config.plugins.serienRec.screenplaner.save()
			SerienRecorder.configfile.save()
			self.readPlanerData(False)

	def getSeriesNameID(self):
		if config.plugins.serienRec.screenplaner.value == 1:
			serien_name = self['menu_list'].getCurrent()[0][6]
			serien_id = self['menu_list'].getCurrent()[0][14]
		else:
			serien_name = self['menu_list'].getCurrent()[0][0]
			serien_id = self['menu_list'].getCurrent()[0][2]

		return serien_name, serien_id

	def keyGreen(self):
		from SerienRecorderChannelScreen import serienRecMainChannelEdit
		self.session.openWithCallback(self.readPlanerData, serienRecMainChannelEdit)

	def keyYellow(self):
		from SerienRecorderMarkerScreen import serienRecMarker
		self.session.openWithCallback(self.readPlanerData, serienRecMarker)

	def keyBlue(self):
		from SerienRecorderTimerListScreen import serienRecTimerListScreen
		self.session.openWithCallback(self.readPlanerData, serienRecTimerListScreen)

	def keyCheck(self):
		if config.plugins.serienRec.tvplaner.value:
			self.session.openWithCallback(self.executeAutoCheck, MessageBox, "Bei 'ja' wird der Suchlauf für TV-Planer Timer gestartet, bei 'nein' wird ein voller Suchlauf durchgeführt.", MessageBox.TYPE_YESNO)
		else:
			self.executeAutoCheck(False)

	def executeAutoCheck(self, withTVPlaner):
		from SerienRecorderAutoCheckScreen import serienRecRunAutoCheckScreen
		self.session.openWithCallback(self.readPlanerData, serienRecRunAutoCheckScreen, withTVPlaner)


	def keyLeft(self):
		if self.modus == "list":
			self['menu_list'].pageUp()
			self.getCover()

	def keyRight(self):
		if self.modus == "list":
			self['menu_list'].pageDown()
			self.getCover()

	def keyDown(self):
		if self.modus == "list":
			self['menu_list'].down()
			self.getCover()

	def keyUp(self):
		if self.modus == "list":
			self['menu_list'].up()
			self.getCover()

	def nextPage(self):
		if config.plugins.serienRec.screenplaner.value == 1 and self.page < 4:
			self.page += 1
			self.chooseMenuList.setList(map(self.buildPlanerList, []))
			self.readPlanerData(False)

	def backPage(self):
		if config.plugins.serienRec.screenplaner.value == 1 and not self.page < 1:
			self.page -= 1
		self.chooseMenuList.setList(map(self.buildPlanerList, []))
		self.readPlanerData(False)

	def __onClose(self):
		self.stopDisplayTimer()

	def keyCancel(self):
		if self.modus == "list":
			self.stopDisplayTimer()
			self.close()
class serienRecMainScreen(serienRecBaseScreen, Screen, HelpableScreen):
    def __init__(self, session):
        serienRecBaseScreen.__init__(self, session)
        Screen.__init__(self, session)
        HelpableScreen.__init__(self)
        self.session = session
        self.picload = ePicLoad()
        self.picloader = None
        self.ErrorMsg = "unbekannt"
        self.skin = None
        self.chooseMenuList = None
        self.chooseMenuList_popup = None
        self.popup_list = []
        self.piconLoader = PiconLoader()
        self.database = None
        self.singleTimer_conn = None
        self.displayTimer_conn = None

        self["actions"] = HelpableActionMap(
            self, "SerienRecorderActions", {
                "ok":
                (self.keyOK, "Marker für die ausgewählte Serie hinzufügen"),
                "cancel": (self.keyCancel, "SerienRecorder beenden"),
                "left": (self.keyLeft, "zur vorherigen Seite blättern"),
                "right": (self.keyRight, "zur nächsten Seite blättern"),
                "up": (self.keyUp, "eine Zeile nach oben"),
                "down": (self.keyDown, "eine Zeile nach unten"),
                "red": (self.keyRed, "Anzeige-Modus auswählen"),
                "green": (self.keyGreen, "Ansicht Sender-Zuordnung öffnen"),
                "yellow": (self.keyYellow, "Ansicht Serien-Marker öffnen"),
                "blue": (self.keyBlue, "Ansicht Timer-Liste öffnen"),
                "info": (self.keyCheck, "Suchlauf für Timer starten"),
                "menu":
                (self.recSetup, "Menü für globale Einstellungen öffnen"),
                "nextBouquet":
                (self.nextPage, "Serienplaner des nächsten Tages laden"),
                "prevBouquet":
                (self.backPage, "Serienplaner des vorherigen Tages laden"),
                "startTeletext":
                (self.wunschliste,
                 "Informationen zur ausgewählten Serie auf Wunschliste anzeigen"
                 ),
                "0":
                (self.readLogFile, "Log-File des letzten Suchlaufs anzeigen"),
                "1": (self.searchSeries, "Serie manuell suchen"),
                "2": (self.changeTVDBID, "TVDB-ID ändern"),
                "3": (self.showProposalDB,
                      "Liste der Serien/Staffel-Starts anzeigen"),
                "4": (self.serieInfo,
                      "Informationen zur ausgewählten Serie anzeigen"),
                "5": (self.imapTest, "IMAP Test"),
                "6":
                (self.showConflicts, "Liste der Timer-Konflikte anzeigen"),
                "7": (self.showWishlist,
                      "Merkzettel (vorgemerkte Folgen) anzeigen"),
                "8": (self.reloadSerienplaner, "Serienplaner neu laden"),
            }, -1)
        self.helpList[0][2].sort()

        self["helpActions"] = ActionMap([
            "SerienRecorderActions",
        ], {
            "displayHelp": self.showHelp,
            "displayHelp_long": self.showManual,
        }, 0)

        SerienRecorder.ReadConfigFile()

        if not os.path.exists(config.plugins.serienRec.piconPath.value):
            config.plugins.serienRec.showPicons.value = False

        self.setupSkin()

        if config.plugins.serienRec.updateInterval.value == 24:
            config.plugins.serienRec.timeUpdate.value = True
        elif config.plugins.serienRec.updateInterval.value == 0:
            config.plugins.serienRec.timeUpdate.value = False
        else:
            config.plugins.serienRec.timeUpdate.value = False

        global showMainScreen
        if config.plugins.serienRec.firstscreen.value == "0":
            showMainScreen = True
        else:
            showMainScreen = False

        self.pRegional = 0
        self.pPaytv = 1
        self.pPrime = 1
        self.page = 0
        self.modus = "list"
        self.loading = True
        self.daylist = [[]]
        self.displayTimer = None
        self.displayMode = 1
        self.serviceRefs = None

        self.onLayoutFinish.append(self.setSkinProperties)
        self.onClose.append(self.__onClose)

        self.onFirstExecBegin.append(self.showSplashScreen)
        self.onFirstExecBegin.append(self.checkForUpdate)

        if config.plugins.serienRec.showStartupInfoText.value:
            if fileExists("%sStartupInfoText" %
                          SerienRecorder.serienRecMainPath):
                self.onFirstExecBegin.append(self.showInfoText)
            else:
                self.onFirstExecBegin.append(self.startScreen)
        else:
            self.onFirstExecBegin.append(self.startScreen)

    def imapTest(self):
        from SerienRecorderTVPlaner import imaptest
        imaptest(self.session)

    def showInfoText(self):
        from SerienRecorderStartupInfoScreen import ShowStartupInfo
        self.session.openWithCallback(self.startScreen, ShowStartupInfo)

    def showSplashScreen(self):
        from SerienRecorderSplashScreen import ShowSplashScreen
        self.session.openWithCallback(
            self.checkForUpdate, ShowSplashScreen,
            config.plugins.serienRec.showversion.value)

    def checkForUpdate(self):
        if config.plugins.serienRec.Autoupdate.value:
            from SerienRecorderUpdateScreen import checkGitHubUpdate
            checkGitHubUpdate(self.session).checkForUpdate()

        self.startScreen()

    def callHelpAction(self, *args):
        HelpableScreen.callHelpAction(self, *args)

    def setSkinProperties(self):
        super(self.__class__, self).setSkinProperties()

        self['text_red'].setText("Anzeige-Modus")
        self['text_green'].setText("Sender zuordnen")
        self['text_ok'].setText("Marker hinzufügen")
        self['text_yellow'].setText("Serien Marker")
        self['text_blue'].setText("Timer-Liste")
        self.num_bt_text[0][1] = "IMAP-Test"
        self.num_bt_text[1][0] = "Serie suchen"
        self.num_bt_text[2][0] = "TVDB-ID ändern"
        self.num_bt_text[2][2] = "Timer suchen"
        self.num_bt_text[3][1] = "Neu laden"

        super(self.__class__, self).startDisplayTimer()

    def setupSkin(self):
        self.skin = None
        InitSkin(self)

        self.chooseMenuList = MenuList([],
                                       enableWrapAround=True,
                                       content=eListboxPythonMultiContent)
        self.chooseMenuList.l.setFont(
            0,
            gFont('Regular',
                  20 + int(config.plugins.serienRec.listFontsize.value)))
        self.chooseMenuList.l.setItemHeight(int(50 * skinFactor))
        self['menu_list'] = self.chooseMenuList
        self['menu_list'].show()

        # popup
        self.chooseMenuList_popup = MenuList(
            [], enableWrapAround=True, content=eListboxPythonMultiContent)
        self.chooseMenuList_popup.l.setFont(
            0,
            gFont('Regular',
                  20 + int(config.plugins.serienRec.listFontsize.value)))
        self.chooseMenuList_popup.l.setItemHeight(int(30 * skinFactor))
        self['popup_list'] = self.chooseMenuList_popup
        self['popup_list'].hide()

        self['title'].setText("Lade infos from Web...")

        if config.plugins.serienRec.showCover.value:
            self['cover'].show()

        if not config.plugins.serienRec.showAllButtons.value:
            self['bt_red'].show()
            self['bt_green'].show()
            self['bt_ok'].show()
            self['bt_yellow'].show()
            self['bt_blue'].show()
            self['bt_exit'].show()
            self['bt_text'].show()
            self['bt_epg'].show()
            self['bt_info'].show()
            self['bt_menu'].show()

            self['text_red'].show()
            self['text_green'].show()
            self['text_ok'].show()
            self['text_yellow'].show()
            self['text_blue'].show()
            self['text_0'].show()
            self['text_1'].show()
            self['text_2'].show()
            self['text_3'].show()
            self['text_4'].show()

    def updateMenuKeys(self):
        updateMenuKeys(self)

    def test(self):
        i = 0

    def changeTVDBID(self):
        from SerienRecorderScreenHelpers import EditTVDBID
        (serien_name, serien_id) = self.getSeriesNameID()
        editTVDBID = EditTVDBID(self, self.session, serien_name, serien_id)
        editTVDBID.changeTVDBID()

    def reloadSerienplaner(self):
        # lt = datetime.datetime.now()
        # lt += datetime.timedelta(days=self.page)
        # key = time.strftime('%d.%m.%Y', lt.timetuple())
        # cache = serienRecMainScreen.loadPlanerData(config.plugins.serienRec.screenplaner.value)
        # if key in cache:
        # 	del cache[key]
        self.readPlanerData(True)

    def readLogFile(self):
        from SerienRecorderLogScreen import serienRecReadLog
        self.session.open(serienRecReadLog)

    def showProposalDB(self):
        from SerienRecorderSeasonBeginsScreen import serienRecShowSeasonBegins
        self.session.openWithCallback(self.readPlanerData,
                                      serienRecShowSeasonBegins)

    def searchSeries(self):
        if self.modus == "list":
            self.session.openWithCallback(self.wSearch,
                                          NTIVirtualKeyBoard,
                                          title="Serien Titel eingeben:")

    def wSearch(self, serien_name):
        if serien_name:
            from SerienRecorderSearchResultScreen import serienRecSearchResultScreen
            self.session.openWithCallback(self.handleSeriesSearchEnd,
                                          serienRecSearchResultScreen,
                                          serien_name)

    def handleSeriesSearchEnd(self, serien_name=None):
        if serien_name:
            from SerienRecorderMarkerScreen import serienRecMarker
            self.session.openWithCallback(self.readPlanerData, serienRecMarker,
                                          serien_name)
        else:
            self.readPlanerData(False)

    def serieInfo(self):
        if self.loading:
            return

        check = self['menu_list'].getCurrent()
        if check is None:
            return

        (serien_name, serien_id) = self.getSeriesNameID()
        from SerienRecorderSeriesInfoScreen import serienRecShowInfo
        self.session.open(serienRecShowInfo, serien_name, serien_id)

    def wunschliste(self):
        (serien_name, serien_id) = self.getSeriesNameID()
        super(self.__class__, self).wunschliste(serien_id)

    def setHeadline(self):
        if int(config.plugins.serienRec.screenplaner.value) == 1:
            self['headline'].setText("Serien-Planer (Serien Tagesübersicht)")
            self['text_red'].setText("Top 30")
        elif int(config.plugins.serienRec.screenplaner.value) == 2:
            self['headline'].setText("Top 30 SerienRecorder Serien")
            self['text_red'].setText("Tagesübersicht")

        self['headline'].instance.setForegroundColor(parseColor("red"))

    def recSetup(self):
        from SerienRecorderSetupScreen import serienRecSetup
        self.session.openWithCallback(self.setupClose, serienRecSetup)

    def setupClose(self, result):
        super(self.__class__, self).setupClose(result)
        if result[1]:
            self.readPlanerData()

    def startScreen(self):
        print "[SerienRecorder] version %s is running..." % config.plugins.serienRec.showversion.value

        if not SerienRecorder.refreshTimer:
            if config.plugins.serienRec.timeUpdate.value:
                SerienRecorder.serienRecCheckForRecording(
                    self.session, False, False)

        if not SerienRecorder.initDB():
            print "[SerienRecorder] initDB failed"
            super(self.__class__, self).close()

        self.database = SRDatabase(SerienRecorder.serienRecDataBaseFilePath)
        if not self.database.hasChannels():
            print "[SerienRecorder] Channellist is empty !"
            from SerienRecorderChannelScreen import serienRecMainChannelEdit
            self.session.openWithCallback(self.readPlanerData,
                                          serienRecMainChannelEdit)
        else:
            self.serviceRefs = self.database.getActiveServiceRefs()
            remoteChannelListLastUpdated = SeriesServer.getChannelListLastUpdate(
            )
            channelListUpToDate = True
            if remoteChannelListLastUpdated:
                localChannelListLastUpdated = self.database.getChannelListLastUpdate(
                )
                if 0 < localChannelListLastUpdated < remoteChannelListLastUpdated:
                    SRLogger.writeLog(
                        "Auf dem Serien-Server wurde die Senderliste aktualisiert - bitte führen Sie auch eine Aktualisierung in der Senderzuordnung aus.",
                        True)
                    channelListUpToDate = False

            if channelListUpToDate:
                self.switchStartScreen()
            else:
                self.session.openWithCallback(
                    self.handleChannelListUpdate, MessageBox,
                    "Die Senderliste wurde auf dem Server aktualisiert.\nSie muss auch im SerienRecorder aktualisiert werden.\nWechseln Sie zur Senderzuordnung und aktualisieren Sie die Senderliste mit der grünen Taste.\n\nZur Senderzuordnung wechseln?",
                    MessageBox.TYPE_YESNO)

    def handleChannelListUpdate(self, showChannelEdit=False):
        if showChannelEdit:
            from SerienRecorderChannelScreen import serienRecMainChannelEdit
            self.session.openWithCallback(self.switchStartScreen,
                                          serienRecMainChannelEdit)
        else:
            self.switchStartScreen()

    def switchStartScreen(self, unused=None):
        if not showMainScreen:
            from SerienRecorderMarkerScreen import serienRecMarker
            self.session.openWithCallback(self.readPlanerData, serienRecMarker)
        else:
            self.readPlanerData(False)

    def readPlanerData(self, answer=True):
        print "[SerienRecorder] readPlanerData"
        if not showMainScreen:
            self.keyCancel()
            self.close()
            return

        self.loading = True
        cache = serienRecSeriesPlanner.loadPlanerData(
            config.plugins.serienRec.screenplaner.value)

        if answer:
            cache.clear()

        self.setHeadline()
        self['title'].instance.setForegroundColor(parseColor("foreground"))

        lt = datetime.datetime.now()
        if config.plugins.serienRec.screenplaner.value == 1:
            lt += datetime.timedelta(days=self.page)
        key = time.strftime('%d.%m.%Y', lt.timetuple())
        if key in cache:
            try:
                self['title'].setText("Lade Infos vom Speicher...")
                if config.plugins.serienRec.screenplaner.value == 1:
                    self.processPlanerData(cache[key], True)
                else:
                    self.processTopThirty(cache[key], True)
            except:
                SRLogger.writeLog(
                    "Fehler beim Abrufen und Verarbeiten der Daten\n", True)
        else:
            self['title'].setText("Lade Infos vom Web...")
            webChannels = self.database.getActiveChannels()
            try:
                if config.plugins.serienRec.screenplaner.value == 1:
                    planerData = SeriesServer().doGetPlanerData(
                        int(self.page), webChannels)
                    self.processPlanerData(planerData, False)
                else:
                    topThirtyData = SeriesServer().doGetTopThirty()
                    self.processTopThirty(topThirtyData, False)
            except:
                SRLogger.writeLog(
                    "Fehler beim Abrufen und Verarbeiten der Daten\n", True)

    def processPlanerData(self, data, useCache=False):
        if not data or len(data) == 0:
            self['title'].setText("Fehler beim Abrufen der SerienPlaner-Daten")
            return
        if useCache:
            (headDate, self.daylist) = data
        else:
            self.daylist = [[]]
            headDate = [data["date"]]

            markers = self.database.getAllMarkerStatusForBoxID(
                config.plugins.serienRec.BoxID.value)
            timers = self.database.getTimer(self.page)

            for event in data["events"]:
                aufnahme = False
                serieAdded = 0
                start_h = event["time"][:+2]
                start_m = event["time"][+3:]
                start_time = TimeHelpers.getUnixTimeWithDayOffset(
                    start_h, start_m, self.page)

                serien_name = event["name"].encode("utf-8")
                serien_name_lower = serien_name.lower()
                serien_id = int(event["id"])
                sender = event["channel"]
                title = event["title"].encode("utf-8")
                staffel = event["season"]
                episode = event["episode"]
                self.ErrorMsg = "%s - S%sE%s - %s (%s)" % \
                (serien_name, str(staffel).zfill(2), str(episode).zfill(2), title, sender)

                serienTimers = [
                    timer for timer in timers if timer[0] == serien_name_lower
                ]
                serienTimersOnChannel = [
                    serienTimer for serienTimer in serienTimers
                    if serienTimer[2] == sender.lower()
                ]
                for serienTimerOnChannel in serienTimersOnChannel:
                    if (int(serienTimerOnChannel[1]) >=
                        (int(start_time) - 300)) and (int(
                            serienTimerOnChannel[1]) <
                                                      (int(start_time) + 300)):
                        aufnahme = True

                # 0 = no marker, 1 = active marker, 2 = deactive marker
                if serien_id in markers:
                    serieAdded = 1 if markers[serien_id] else 2

                staffel = str(staffel).zfill(2)
                episode = str(episode).zfill(2)

                ##############################
                #
                # CHECK
                #
                # ueberprueft anhand des Seriennamen, Season, Episode ob die serie bereits auf der HDD existiert
                #
                seasonEpisodeString = "S%sE%s" % (str(staffel).zfill(2),
                                                  str(episode).zfill(2))

                bereits_vorhanden = False
                if config.plugins.serienRec.sucheAufnahme.value:
                    (dirname,
                     dirname_serie) = getDirname(self.database, serien_name,
                                                 staffel)
                    if str(episode).isdigit():
                        if int(episode) == 0:
                            bereits_vorhanden = STBHelpers.countEpisodeOnHDD(
                                dirname, seasonEpisodeString, serien_name,
                                False, title) > 0 and True or False
                        else:
                            bereits_vorhanden = STBHelpers.countEpisodeOnHDD(
                                dirname, seasonEpisodeString, serien_name,
                                False) > 0 and True or False
                    else:
                        bereits_vorhanden = STBHelpers.countEpisodeOnHDD(
                            dirname, seasonEpisodeString, serien_name,
                            False) > 0 and True or False

                title = "%s - %s" % (seasonEpisodeString, title)
                regional = False
                paytv = False
                neu = event["new"]
                prime = False
                transmissionTime = event["time"]
                url = ''
                self.daylist[0].append(
                    (regional, paytv, neu, prime, transmissionTime, url,
                     serien_name, sender, staffel, episode, title, aufnahme,
                     serieAdded, bereits_vorhanden, serien_id))

            print "[SerienRecorder] Es wurden %s Serie(n) gefunden" % len(
                self.daylist[0])

            if headDate:
                d = headDate[0].split(',')
                d.reverse()
                key = d[0].strip()
                cache = serienRecSeriesPlanner.loadPlanerData(1)
                cache.update({key: (headDate, self.daylist)})
                if config.plugins.serienRec.planerCacheEnabled.value:
                    serienRecSeriesPlanner.writePlanerData(1, cache)

        self.loading = False

        if len(self.daylist[0]) != 0:
            if headDate:
                self['title'].setText(
                    "Es wurden für - %s - %s Serie(n) gefunden." %
                    (headDate[0], len(self.daylist[0])))
                self['title'].instance.setForegroundColor(
                    parseColor("foreground"))
            else:
                self['title'].setText(
                    "Es wurden für heute %s Serie(n) gefunden." %
                    len(self.daylist[0]))
                self['title'].instance.setForegroundColor(
                    parseColor("foreground"))
            self.chooseMenuList.setList(
                map(self.buildPlanerList, self.daylist[0]))
            self.ErrorMsg = "'getCover()'"
            self.getCover()
        else:
            if int(self.page) < 1 and not int(self.page) == 0:
                self.page -= 1
            self['title'].setText("Es wurden für heute %s Serie(n) gefunden." %
                                  len(self.daylist[0]))
            self['title'].instance.setForegroundColor(parseColor("foreground"))
            print "[SerienRecorder] Wunschliste Serien-Planer -> LISTE IST LEER !!!!"
            self.chooseMenuList.setList(
                map(self.buildPlanerList, self.daylist[0]))

    def processTopThirty(self, data, useCache=False):
        if not data or len(data) == 0:
            self['title'].setText("Fehler beim Abrufen der SerienPlaner-Daten")
            return
        if useCache:
            (headDate, self.daylist) = data
        else:
            self.daylist = [[]]
            headDate = [data["date"]]

            markers = self.database.getAllMarkerStatusForBoxID(
                config.plugins.serienRec.BoxID.value)

            rank = 0
            for serie in data["series"]:
                serien_name = serie["name"].encode("utf-8")
                serien_id = int(serie["id"])
                average = serie["average"]

                # 0 = no marker, 1 = active marker, 2 = deactive marker
                serieAdded = 0
                if serien_id in markers:
                    serieAdded = 1 if markers[serien_id] else 2

                rank += 1
                self.daylist[0].append(
                    (serien_name, average, serien_id, serieAdded, rank))

            if headDate:
                d = headDate[0].split(',')
                d.reverse()
                key = d[0].strip()
                cache = serienRecSeriesPlanner.loadPlanerData(2)
                cache.update({key: (headDate, self.daylist)})
                if config.plugins.serienRec.planerCacheEnabled.value:
                    serienRecSeriesPlanner.writePlanerData(2, cache)

        self.loading = False
        self['title'].setText("")
        self.chooseMenuList.setList(
            map(self.buildTopThirtyList, self.daylist[0]))
        self.ErrorMsg = "'getCover()'"
        self.getCover()

    def buildPlanerList(self, entry):
        (regional, paytv, neu, prime, transmissionTime, url, serien_name,
         sender, staffel, episode, title, aufnahme, serieAdded,
         bereits_vorhanden, serien_id) = entry

        imageNone = "%simages/black.png" % SerienRecorder.serienRecMainPath
        imageNeu = "%simages/neu.png" % SerienRecorder.serienRecMainPath
        imageTimer = "%simages/timer.png" % SerienRecorder.serienRecMainPath
        imageHDD = "%simages/hdd_icon.png" % SerienRecorder.serienRecMainPath

        if serieAdded == 1:
            seriesColor = parseColor('green').argb()
        elif serieAdded == 2:
            seriesColor = parseColor('red').argb()
        else:
            seriesColor = None
        if aufnahme:
            seriesColor = parseColor('blue').argb()

        titleColor = timeColor = parseColor('foreground').argb()

        if int(neu) == 0:
            imageNeu = imageNone

        if bereits_vorhanden:
            imageHDDTimer = imageHDD
        elif aufnahme:
            imageHDDTimer = imageTimer
        else:
            imageHDDTimer = imageNone

        if config.plugins.serienRec.showPicons.value != "0":
            picon = loadPNG(imageNone)
            if sender and self.serviceRefs.get(sender):
                # Get picon by reference or name
                piconPath = self.piconLoader.getPicon(
                    self.serviceRefs.get(sender)[0] if config.plugins.
                    serienRec.showPicons.value ==
                    "1" else self.serviceRefs.get(sender)[1])
                if piconPath:
                    self.picloader = PicLoader(80 * skinFactor,
                                               40 * skinFactor)
                    picon = self.picloader.load(piconPath)
                    self.picloader.destroy()

            return [
                entry,
                (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 5,
                 5 * skinFactor, 80 * skinFactor, 40 * skinFactor, picon),
                (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST,
                 330 * skinFactor, 7 * skinFactor, 30 * skinFactor,
                 22 * skinFactor, loadPNG(imageNeu)),
                (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST,
                 330 * skinFactor, 30 * skinFactor, 30 * skinFactor,
                 22 * skinFactor, loadPNG(imageHDDTimer)),
                (eListboxPythonMultiContent.TYPE_TEXT, 100 * skinFactor, 3,
                 200 * skinFactor, 26 * skinFactor, 0,
                 RT_HALIGN_LEFT | RT_VALIGN_CENTER, sender),
                (eListboxPythonMultiContent.TYPE_TEXT, 100 * skinFactor,
                 29 * skinFactor, 150 * skinFactor, 18 * skinFactor, 0,
                 RT_HALIGN_LEFT | RT_VALIGN_CENTER, transmissionTime,
                 timeColor, timeColor),
                (eListboxPythonMultiContent.TYPE_TEXT, 365 * skinFactor, 3,
                 500 * skinFactor, 26 * skinFactor, 0,
                 RT_HALIGN_LEFT | RT_VALIGN_CENTER, serien_name, seriesColor,
                 seriesColor),
                (eListboxPythonMultiContent.TYPE_TEXT, 365 * skinFactor,
                 29 * skinFactor, 500 * skinFactor, 18 * skinFactor, 0,
                 RT_HALIGN_LEFT | RT_VALIGN_CENTER, title, titleColor,
                 titleColor)
            ]
        else:
            return [
                entry,
                (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 5, 7,
                 30 * skinFactor, 22 * skinFactor, loadPNG(imageNeu)),
                (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 5,
                 30 * skinFactor, 30 * skinFactor, 22 * skinFactor,
                 loadPNG(imageHDDTimer)),
                (eListboxPythonMultiContent.TYPE_TEXT, 40 * skinFactor, 3,
                 280 * skinFactor, 26 * skinFactor, 0,
                 RT_HALIGN_LEFT | RT_VALIGN_CENTER, sender),
                (eListboxPythonMultiContent.TYPE_TEXT, 40 * skinFactor,
                 29 * skinFactor, 150 * skinFactor, 18 * skinFactor, 0,
                 RT_HALIGN_LEFT | RT_VALIGN_CENTER, transmissionTime,
                 timeColor, timeColor),
                (eListboxPythonMultiContent.TYPE_TEXT, 340 * skinFactor, 3,
                 520 * skinFactor, 26 * skinFactor, 0,
                 RT_HALIGN_LEFT | RT_VALIGN_CENTER, serien_name, seriesColor,
                 seriesColor),
                (eListboxPythonMultiContent.TYPE_TEXT, 340 * skinFactor,
                 29 * skinFactor, 520 * skinFactor, 18 * skinFactor, 0,
                 RT_HALIGN_LEFT | RT_VALIGN_CENTER, title, titleColor,
                 titleColor)
            ]

    @staticmethod
    def buildTopThirtyList(entry):
        (serien_name, average, serien_id, serieAdded, rank) = entry

        if serieAdded == 1:
            seriesColor = parseColor('green').argb()
        elif serieAdded == 2:
            seriesColor = parseColor('red').argb()
        else:
            seriesColor = None

        title = "%d Abrufe/Tag" % average
        titleColor = parseColor('foreground').argb()

        rank = "%d." % rank

        return [
            entry,
            (eListboxPythonMultiContent.TYPE_TEXT, 5 * skinFactor, 3,
             40 * skinFactor, 26 * skinFactor, 0,
             RT_HALIGN_RIGHT | RT_VALIGN_CENTER, rank, titleColor, titleColor),
            (eListboxPythonMultiContent.TYPE_TEXT, 70 * skinFactor, 3,
             520 * skinFactor, 26 * skinFactor, 0,
             RT_HALIGN_LEFT | RT_VALIGN_CENTER, serien_name, seriesColor,
             seriesColor),
            (eListboxPythonMultiContent.TYPE_TEXT, 70 * skinFactor,
             29 * skinFactor, 520 * skinFactor, 18 * skinFactor, 0,
             RT_HALIGN_LEFT | RT_VALIGN_CENTER, title, titleColor, titleColor)
        ]

    def keyOK(self):
        if self.modus == "list":
            if self.loading:
                return

            check = self['menu_list'].getCurrent()
            if check is None:
                return

            (serien_name, serien_id) = self.getSeriesNameID()
            if config.plugins.serienRec.activateNewOnThisSTBOnly.value:
                boxID = None
            else:
                boxID = config.plugins.serienRec.BoxID.value

            if self.database.addMarker(str(serien_id), serien_name, '', boxID,
                                       0):
                SRLogger.writeLog(
                    "\nSerien Marker für ' %s ' wurde angelegt" % serien_name,
                    True)
                self['title'].setText(
                    "Serie '- %s -' zum Serien Marker hinzugefügt." %
                    serien_name)
                self['title'].instance.setForegroundColor(parseColor("green"))
                if config.plugins.serienRec.tvplaner_full_check.value:
                    config.plugins.serienRec.tvplaner_last_full_check.value = int(
                        0)
                    config.plugins.serienRec.tvplaner_last_full_check.save()
                    SerienRecorder.configfile.save()
                if config.plugins.serienRec.openMarkerScreen.value:
                    from SerienRecorderMarkerScreen import serienRecMarker
                    self.session.open(serienRecMarker, serien_name)
            else:
                self['title'].setText(
                    "Serie '- %s -' existiert bereits im Serien Marker." %
                    serien_name)
                self['title'].instance.setForegroundColor(parseColor("red"))

    def getCover(self):
        if self.loading:
            return

        check = self['menu_list'].getCurrent()
        if check is None:
            return

        (serien_name, serien_id) = self.getSeriesNameID()
        self.ErrorMsg = "'getCover()'"
        SerienRecorder.getCover(self, serien_name, serien_id)

    def keyRed(self):
        if self.modus == "list":
            if config.plugins.serienRec.screenplaner.value == 1:
                config.plugins.serienRec.screenplaner.value = 2
            else:
                config.plugins.serienRec.screenplaner.value = 1
            config.plugins.serienRec.screenplaner.save()
            SerienRecorder.configfile.save()
            self.readPlanerData(False)

    def getSeriesNameID(self):
        if config.plugins.serienRec.screenplaner.value == 1:
            serien_name = self['menu_list'].getCurrent()[0][6]
            serien_id = self['menu_list'].getCurrent()[0][14]
        else:
            serien_name = self['menu_list'].getCurrent()[0][0]
            serien_id = self['menu_list'].getCurrent()[0][2]

        return serien_name, serien_id

    def keyGreen(self):
        from SerienRecorderChannelScreen import serienRecMainChannelEdit
        self.session.openWithCallback(self.readPlanerData,
                                      serienRecMainChannelEdit)

    def keyYellow(self):
        from SerienRecorderMarkerScreen import serienRecMarker
        self.session.openWithCallback(self.readPlanerData, serienRecMarker)

    def keyBlue(self):
        from SerienRecorderTimerListScreen import serienRecTimerListScreen
        self.session.openWithCallback(self.readPlanerData,
                                      serienRecTimerListScreen)

    def keyCheck(self):
        if config.plugins.serienRec.tvplaner.value:
            self.session.openWithCallback(
                self.executeAutoCheck, MessageBox,
                "Bei 'ja' wird der Suchlauf für TV-Planer Timer gestartet, bei 'nein' wird ein voller Suchlauf durchgeführt.",
                MessageBox.TYPE_YESNO)
        else:
            self.executeAutoCheck(False)

    def executeAutoCheck(self, withTVPlaner):
        from SerienRecorderAutoCheckScreen import serienRecRunAutoCheckScreen
        self.session.openWithCallback(self.readPlanerData,
                                      serienRecRunAutoCheckScreen,
                                      withTVPlaner)

    def keyLeft(self):
        if self.modus == "list":
            self['menu_list'].pageUp()
            self.getCover()

    def keyRight(self):
        if self.modus == "list":
            self['menu_list'].pageDown()
            self.getCover()

    def keyDown(self):
        if self.modus == "list":
            self['menu_list'].down()
            self.getCover()

    def keyUp(self):
        if self.modus == "list":
            self['menu_list'].up()
            self.getCover()

    def nextPage(self):
        if config.plugins.serienRec.screenplaner.value == 1 and self.page < 4:
            self.page += 1
            self.chooseMenuList.setList(map(self.buildPlanerList, []))
            self.readPlanerData(False)

    def backPage(self):
        if config.plugins.serienRec.screenplaner.value == 1 and not self.page < 1:
            self.page -= 1
        self.chooseMenuList.setList(map(self.buildPlanerList, []))
        self.readPlanerData(False)

    def __onClose(self):
        self.stopDisplayTimer()

    def keyCancel(self):
        if self.modus == "list":
            self.stopDisplayTimer()
            self.close()