def keyOK(self): if self.loading: return check = self['menu_list'].getCurrent() if check is None: print "[SerienRecorder] keine infos gefunden" return Serie = self['menu_list'].getCurrent()[0][0] Year = self['menu_list'].getCurrent()[0][1] Id = self['menu_list'].getCurrent()[0][2] print Serie, Year, Id if Id == "": return if Id == "-1": self.chooseMenuList.setList([]) self.searchSerie(int(Year)) return self.serien_name = "" database = SRDatabase(SerienRecorder.serienRecDataBaseFilePath) if config.plugins.serienRec.activateNewOnThisSTBOnly.value: boxID = None else: boxID = config.plugins.serienRec.BoxID.value if database.addMarker(str(Id), Serie, Year, boxID, 0): from SerienRecorderLogWriter import SRLogger SRLogger.writeLog("\nSerien Marker für ' %s ' wurde angelegt" % Serie, True) self['title'].setText("Serie '- %s -' zum Serien Marker hinzugefügt." % Serie) self['title'].instance.setForegroundColor(parseColor("green")) if config.plugins.serienRec.openMarkerScreen.value: self.close(Serie) else: self['title'].setText("Serie '- %s -' existiert bereits im Serien Marker." % Serie) self['title'].instance.setForegroundColor(parseColor("red"))
def getEmailData(): # extract all html parts def get_html(email_message_instance): maintype = email_message_instance.get_content_maintype() if maintype == 'multipart': for part in email_message_instance.get_payload(): if part.get_content_type() == 'text/html': return part.get_payload() SRLogger.writeLog("\n---------' Lade TV-Planer E-Mail '---------\n", True) # get emails if len(config.plugins.serienRec.imap_server.value) == 0: SRLogger.writeLog("TV-Planer: imap_server nicht gesetzt", True) return None if len(config.plugins.serienRec.imap_login_hidden.value) == 0: SRLogger.writeLog("TV-Planer: imap_login nicht gesetzt", True) return None if len(config.plugins.serienRec.imap_password_hidden.value) == 0: SRLogger.writeLog("TV-Planer: imap_password nicht gesetzt", True) return None if len(config.plugins.serienRec.imap_mailbox.value) == 0: SRLogger.writeLog("TV-Planer: imap_mailbox nicht gesetzt", True) return None if len(config.plugins.serienRec.imap_mail_subject.value) == 0: SRLogger.writeLog("TV-Planer: imap_mail_subject nicht gesetzt", True) return None if 1 > config.plugins.serienRec.imap_mail_age.value > 100: config.plugins.serienRec.imap_mail_age.value = 1 try: if config.plugins.serienRec.imap_server_ssl.value: mail = imaplib.IMAP4_SSL(config.plugins.serienRec.imap_server.value, config.plugins.serienRec.imap_server_port.value) else: mail = imaplib.IMAP4(config.plugins.serienRec.imap_server.value, config.plugins.serienRec.imap_server_port.value) except imaplib.IMAP4.abort: SRLogger.writeLog("TV-Planer: Verbindung zum Server fehlgeschlagen", True) return None except imaplib.IMAP4.error: SRLogger.writeLog("TV-Planer: Verbindung zum Server fehlgeschlagen", True) return None try: mail.login(decrypt(getmac("eth0"), config.plugins.serienRec.imap_login_hidden.value), decrypt(getmac("eth0"), config.plugins.serienRec.imap_password_hidden.value)) print "[serienrecorder]: imap login ok" except imaplib.IMAP4.error: SRLogger.writeLog("TV-Planer: Anmeldung auf Server fehlgeschlagen", True) print "[serienrecorder]: imap login failed" return None try: mail.select(config.plugins.serienRec.imap_mailbox.value) except imaplib.IMAP4.error: SRLogger.writeLog("TV-Planer: Mailbox %r nicht gefunden" % config.plugins.serienRec.imap_mailbox.value, True) return None searchstr = TimeHelpers.getMailSearchString() try: result, data = mail.uid('search', None, searchstr) if result != 'OK': SRLogger.writeLog("TV-Planer: Fehler bei der Suche nach TV-Planer E-Mails", True) SRLogger.writeLog("TV-Planer: %s" % data, True) return None except imaplib.IMAP4.error: SRLogger.writeLog("TV-Planer: Keine TV-Planer Nachricht in den letzten %s Tagen" % str(config.plugins.serienRec.imap_mail_age.value), True) SRLogger.writeLog("TV-Planer: %s" % searchstr, True) return None if len(data[0]) == 0: SRLogger.writeLog("TV-Planer: Keine TV-Planer Nachricht in den letzten %s Tagen" % str(config.plugins.serienRec.imap_mail_age.value), True) SRLogger.writeLog("TV-Planer: %s" % searchstr, True) return None # get the latest email latest_email_uid = data[0].split()[-1] # fetch the email body (RFC822) for the given UID try: result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') except: SRLogger.writeLog("TV-Planer: Laden der E-Mail fehlgeschlagen", True) return None mail.logout() # extract email message including headers and alternate payloads email_message = email.message_from_string(data[0][1]) if len(email_message) == 0: SRLogger.writeLog("TV-Planer: leere E-Mail", True) return None # get html of wunschliste html = get_html(email_message) if html is None or len(html) == 0: SRLogger.writeLog("TV-Planer: leeres HTML", True) return None if config.plugins.serienRec.tvplaner.value and config.plugins.serienRec.tvplaner_backupHTML.value: try: htmlFilePath = SERIENRECORDER_TVPLANER_HTML_FILENAME % config.plugins.serienRec.LogFilePath.value writeTVPlanerHTML = open(htmlFilePath, "w") writeTVPlanerHTML.write(html) writeTVPlanerHTML.close() except: SRLogger.writeLog("TV-Planer: HTML konnte nicht für die Fehlersuche gespeichert werden.", True) # make one line and convert characters html = html.replace('=\r\n', '').replace('=\n', '').replace('=\r', '').replace('\n', '').replace('\r', '') html = html.replace('=3D', '=') try: def getTextContentByTitle(node, titleValue, default): titleNodes = node.childNodes.getElementsByAttr('title', titleValue) if titleNodes: return titleNodes[0].textContent.encode('utf-8') else: return default def getEpisodeTitle(node): childNodes = node.childNodes.getElementsByTagName('a') if childNodes: return childNodes[0].textContent.encode('utf-8') else: # Movies does not a link to the episode => only country, year childNodes = node.childNodes.getElementsByTagName('span') if childNodes: return childNodes[0].textContent.encode('utf-8') else: return '' import AdvancedHTMLParser parser = AdvancedHTMLParser.AdvancedHTMLParser() html = parser.unescape(html).encode('utf-8') parser.parseStr(html) # Get tables from HTML tables = parser.getElementsByTagName('table') # Initialize regular expressions date_regexp = re.compile('.*TV-Planer.*?den ([0-3][0-9]\.[0-1][0-9]\.20[0-9][0-9])\s.(?:\(ab (.*?) Uhr\))?') url_title_regexp = re.compile('.*<a href="([^\?]+)(?:\?.*)?".*><strong.*>(.*)</strong>') endtime_regexp = re.compile('.*bis:\s(.*)\sUhr.*') # Get date and time of TV-Planer header = tables[1].getAllChildNodes().getElementsByTagName('div')[0].textContent.encode('utf-8') planerDateTime = date_regexp.findall(header)[0] print planerDateTime # Get transmissions transmissions = [] transmissionTable = tables[1].getAllChildNodes().getElementsByTagName('table')[0] transmissionRows = transmissionTable.childNodes for transmissionRow in transmissionRows: transmission = [] if not transmissionRow.hasAttribute('style'): transmissionColumns = transmissionRow.childNodes # Each transmission row has three columns # [0]: Start time starttime = transmissionColumns[0].textContent.encode('utf-8') if starttime != 'Anzeige': transmission.append(starttime.replace(' Uhr', '')) # [1]: URL, Title, Season, Episode, Info transmissionColumn = transmissionColumns[1] # Season, Episode, Title, Episode info, End time episodeInfo = ['0', '00', '', '', '0.00'] if transmissionColumn.firstChild: # First child is always URL + Title url_title = url_title_regexp.findall(transmissionColumn.firstChild.toHTML().encode('utf-8'))[0] transmission.extend(url_title) if transmissionColumn.lastChild: # Last element => End time (it has to be filled with a time because later on the time will be splitted) endtime = endtime_regexp.findall(transmissionColumn.lastChild.toHTML().encode('utf-8')) if endtime: episodeInfo[4] = endtime[0] divPartIndex = 0 for transmissionPart in transmissionColumn.childNodes: if transmissionPart is transmissionColumn.lastChild: # Skip part if it the "last" part continue if transmissionPart.tagName == 'div' and divPartIndex == 0: # First div element => Season / Episode / Title / e.g. NEU episodeInfo[0] = getTextContentByTitle(transmissionPart, 'Staffel', '0') episodeInfo[1] = getTextContentByTitle(transmissionPart, 'Episode', '00') episodeInfo[2] = getEpisodeTitle(transmissionPart) divPartIndex += 1 elif transmissionPart.tagName == 'div' and divPartIndex == 1: # Second div element => Episode info episodeInfo[3] = transmissionPart.textContent.encode('utf-8') transmission.extend(episodeInfo) # [2] Channel transmission.append(transmissionColumns[2].textContent.encode('utf-8')) print transmission transmissions.append(transmission) except: SRLogger.writeLog("TV-Planer: HTML Parsing abgebrochen", True) return None # prepare transmissions # [ ( seriesName, channel, start, end, season, episode, title, '0' ) ] # calculate start time and end time of list in E-Mail missingTime = False if len(planerDateTime) != 2: SRLogger.writeLog("TV-Planer: falsches Datumsformat", True) return None (day, month, year) = planerDateTime[0].split('.') if not planerDateTime[1]: if transmissions: # Get time of first transmission (hour, minute) = transmissions[0][0].split(':') else: missingTime = True (hour, minute) = ('00', '00') else: (hour, minute) = planerDateTime[1].split(':') liststarttime_unix = TimeHelpers.getRealUnixTime(minute, hour, day, month, year) # generate dictionary with final transmissions SRLogger.writeLog("Ab dem %s %s Uhr wurden die folgenden Sendungen gefunden:\n" % (planerDateTime[0], planerDateTime[1])) print "[SerienRecorder] Ab dem %s %s Uhr wurden die folgenden Sendungen gefunden:" % (planerDateTime[0], planerDateTime[1]) if missingTime: SRLogger.writeLog("In der Kopfzeile der TV-Planer E-Mail konnte keine Uhrzeit gefunden werden, bitte kontrollieren Sie die angelegten Timer!\n") transmissiondict = dict() for starttime, url, seriesname, season, episode, titel, description, endtime, channel in transmissions: try: if url.startswith('https://www.wunschliste.de/spielfilm'): if not config.plugins.serienRec.tvplaner_movies.value: SRLogger.writeLog("' %s - Filmaufzeichnung ist deaktiviert '" % seriesname, True) print "' %s - Filmaufzeichnung ist deaktiviert '" % seriesname continue transmissiontype = '[ Film ]' elif url.startswith('https://www.wunschliste.de/serie'): if not config.plugins.serienRec.tvplaner_series.value: SRLogger.writeLog("' %s - Serienaufzeichnung ist deaktiviert '" % seriesname, True) print "' %s - Serienaufzeichnung ist deaktiviert '" % seriesname continue transmissiontype = '[ Serie ]' else: SRLogger.writeLog("' %s - Ungültige URL %r '" % (seriesname, url), True) print "' %s - Serienaufzeichnung ist deaktiviert '" % seriesname continue # series transmission = [ seriesname ] # channel channel = channel.replace(' (Pay-TV)','').replace(' (Schweiz)','').replace(' (GB)','').replace(' (Österreich)','').replace(' (USA)','').replace(' (RP)','').replace(' (F)','').strip() transmission += [ channel ] # start time (hour, minute) = starttime.split(':') transmissionstart_unix = TimeHelpers.getRealUnixTime(minute, hour, day, month, year) if transmissionstart_unix < liststarttime_unix: transmissionstart_unix = TimeHelpers.getRealUnixTimeWithDayOffset(minute, hour, day, month, year, 1) transmission += [ transmissionstart_unix ] # end time (hour, minute) = endtime.split('.') transmissionend_unix = TimeHelpers.getRealUnixTime(minute, hour, day, month, year) if transmissionend_unix < transmissionstart_unix: transmissionend_unix = TimeHelpers.getRealUnixTimeWithDayOffset(minute, hour, day, month, year, 1) transmission += [ transmissionend_unix ] # season if season == '': season = '0' transmission += [ season ] # episode if episode == '': episode = '00' transmission += [ episode ] # title transmission += [ quopri.decodestring(titel) ] # last transmission += [ '0' ] # url transmission += [ url ] # store in dictionary transmissiondict[seriesname] = [ seriesname: [ transmission 0 ], [ transmission 1], .... ] if seriesname in transmissiondict: transmissiondict[seriesname] += [ transmission ] else: transmissiondict[seriesname] = [ transmission ] SRLogger.writeLog("' %s - S%sE%s - %s - %s - %s - %s - %s '" % (transmission[0], str(transmission[4]).zfill(2), str(transmission[5]).zfill(2), transmission[6], transmission[1], time.strftime("%d.%m.%Y %H:%M", time.localtime(int(transmissionstart_unix))), time.strftime("%d.%m.%Y %H:%M", time.localtime(int(transmissionend_unix))), transmissiontype), True) print "[SerienRecorder] ' %s - S%sE%s - %s - %s - %s - %s - %s'" % (transmission[0], str(transmission[4]).zfill(2), str(transmission[5]).zfill(2), transmission[6], transmission[1], time.strftime("%d.%m.%Y %H:%M", time.localtime(int(transmissionstart_unix))), time.strftime("%d.%m.%Y %H:%M", time.localtime(int(transmissionend_unix))), transmissiontype) except Exception as e: SRLogger.writeLog("TV-Planer Verarbeitung fehlgeschlagen! [%s]" % str(e), True) if config.plugins.serienRec.tvplaner_create_marker.value: database = SRDatabase(SerienRecorder.serienRecDataBaseFilePath) for seriesname in transmissiondict.keys(): # marker isn't in database, create new marker # url stored in marker isn't the final one, it is corrected later url = transmissiondict[seriesname][0][-1] marker_type = "Serien Marker" try: boxID = None if url.startswith('https://www.wunschliste.de/serie'): seriesID = SeriesServer().getIDByFSID(url[str.rindex(url, '/') + 1:]) if seriesID > 0: url = str(seriesID) else: url = None if config.plugins.serienRec.tvplaner_series_activeSTB.value: boxID = config.plugins.serienRec.BoxID.value elif url.startswith('https://www.wunschliste.de/spielfilm'): marker_type = "Temporärer Serien Marker" if config.plugins.serienRec.tvplaner_movies_activeSTB.value: boxID = config.plugins.serienRec.BoxID.value else: url = None if url and not database.markerExists(url): if database.addMarker(url, seriesname, "", boxID, 1 if url.startswith('https://www.wunschliste.de/spielfilm') else 0): SRLogger.writeLog("\n%s für ' %s ' wurde angelegt" % (marker_type, seriesname), True) print "[SerienRecorder] ' %s - %s erzeugt '" % (seriesname, marker_type) except Exception as e: SRLogger.writeLog("\n%s für ' %s ' konnte wegen eines Fehlers nicht angelegt werden [%s]" % (marker_type, seriesname, str(e)), True) print "[SerienRecorder] ' %s - %s konnte wegen eines Fehlers nicht angelegt werden [%s]'" % (seriesname, marker_type, str(e)) else: SRLogger.writeLog("Es werden keine Serien-Marker aus der TV-Planer E-Mail erstellt.", True) return transmissiondict
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 serienRecShowSeasonBegins(serienRecBaseScreen, Screen, HelpableScreen): def __init__(self, session): serienRecBaseScreen.__init__(self, session) Screen.__init__(self, session) HelpableScreen.__init__(self) self.modus = "menu_list" self.session = session self.picload = ePicLoad() self.ErrorMsg = "unbekannt" self.piconLoader = PiconLoader() self.picloader = None self.filter = False self.database = SRDatabase(SerienRecorder.serienRecDataBaseFilePath) self.changesMade = False self["actions"] = HelpableActionMap(self, "SerienRecorderActions", { "ok": (self.keyOK, "Marker für die ausgewählte Serie hinzufügen"), "cancel": (self.keyCancel, "zurück zur vorherigen Ansicht"), "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"), "menu": (self.recSetup, "Menü für globale Einstellungen öffnen"), "yellow": (self.keyYellow, "Zeige nur Serien-Starts"), "startTeletext": (self.wunschliste, "Informationen zur ausgewählten Serie auf Wunschliste anzeigen"), "0" : (self.readLogFile, "Log-File des letzten Suchlaufs 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"), }, -1) self.helpList[0][2].sort() self["helpActions"] = ActionMap(["SerienRecorderActions" ,], { "displayHelp" : self.showHelp, "displayHelp_long" : self.showManual, }, 0) self.setupSkin() self.timer_default = eTimer() if isDreamOS(): self.timer_default_conn = self.timer_default.timeout.connect(self.readProposal) else: self.timer_default.callback.append(self.readProposal) self.proposalList = [] self.transmissions = {} self.serviceRefs = self.database.getActiveServiceRefs() self.onLayoutFinish.append(self.setSkinProperties) self.onLayoutFinish.append(self.__onLayoutFinish) self.onClose.append(self.__onClose) def callHelpAction(self, *args): HelpableScreen.callHelpAction(self, *args) def setSkinProperties(self): super(self.__class__, self).setSkinProperties() self['text_ok'].setText("Marker hinzufügen") self['text_yellow'].setText("Zeige Serienstarts") self.num_bt_text[3][0] = buttonText_na super(self.__class__, self).startDisplayTimer() def setupSkin(self): super(self.__class__, self).setupSkin() self[self.modus].show() if config.plugins.serienRec.showCover.value: self['cover'].show() if not config.plugins.serienRec.showAllButtons.value: self['bt_ok'].show() self['bt_yellow'].show() self['bt_exit'].show() self['bt_text'].show() self['bt_info'].show() self['bt_menu'].show() self['text_ok'].show() self['text_yellow'].show() self['text_0'].show() self['text_1'].show() self['text_2'].show() self['text_3'].show() self['text_4'].show() self['text_6'].show() self['text_7'].show() self['text_8'].show() self['text_9'].show() def updateMenuKeys(self): updateMenuKeys(self) def __onLayoutFinish(self): self['title'].setText("Lade neue Serien/Staffeln...") self.timer_default.start(0) def readProposal(self): self.timer_default.stop() webChannels = self.database.getActiveChannels() self.proposalList = [] transmissionResults = downloadSeasonBegins(webChannels) transmissionResults.start() transmissionResults.join() if not transmissionResults.getData(): print "[SerienRecorder]: Abfrage beim SerienServer doGetSeasonBegins() fehlgeschlagen" else: self.transmissions = transmissionResults.getData() self.buildProposalList() def buildProposalList(self): markers = self.database.getAllMarkerStatusForBoxID(config.plugins.serienRec.BoxID.value) self.proposalList = [] if self.filter: self['text_yellow'].setText("Serien-/Staffelstarts") else: self['text_yellow'].setText("Zeige Serienstarts") for event in self.transmissions['events']: if self.filter and str(event['season']).isdigit() and int(event['season']) > 1: continue seriesName = event['name'].encode('utf-8') seriesID = int(event['id']) # marker flags: 0 = no marker, 1 = active marker, 2 = inactive marker markerFlag = 0 if seriesID in markers: markerFlag = 1 if markers[seriesID] else 2 self.proposalList.append([seriesName, event['season'], event['channel'].encode('utf-8'), event['start'], event['id'], markerFlag]) if self.filter: self['title'].setText("%d neue Serien gefunden:" % len(self.proposalList)) else: self['title'].setText("%d neue Serien/Staffeln gefunden:" % len(self.proposalList)) self.chooseMenuList.setList(map(self.buildList, self.proposalList)) if self['menu_list'].getCurrent(): serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def buildList(self, entry): (Serie, Staffel, Sender, UTCTime, ID, MarkerFlag) = entry icon = imageNone = "%simages/black.png" % SerienRecorder.serienRecMainPath imageNeu = "%simages/neu.png" % SerienRecorder.serienRecMainPath if MarkerFlag == 1: setFarbe = parseColor('green').argb() elif MarkerFlag == 2: setFarbe = parseColor('red').argb() else: setFarbe = parseColor('foreground').argb() if str(Staffel).isdigit() and int(Staffel) == 1: icon = imageNeu foregroundColor = parseColor('foreground').argb() Staffel = "Staffel %s" % str(Staffel) WochenTag = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"] xtime = time.strftime(WochenTag[time.localtime(int(UTCTime)).tm_wday]+ ", %d.%m.%Y", time.localtime(int(UTCTime))) if config.plugins.serienRec.showPicons.value != "0": picon = loadPNG(imageNone) if Sender and self.serviceRefs.get(Sender): # Get picon by reference or by 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, 10, 5, 80 * skinFactor, 40 * skinFactor, picon), (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 340 * skinFactor, 15 * skinFactor, 30 * skinFactor, 30 * skinFactor, loadPNG(icon)), (eListboxPythonMultiContent.TYPE_TEXT, 110 * skinFactor, 3, 200 * skinFactor, 26 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Sender, foregroundColor, foregroundColor), (eListboxPythonMultiContent.TYPE_TEXT, 110 * skinFactor, 29 * skinFactor, 200 * skinFactor, 18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, xtime), (eListboxPythonMultiContent.TYPE_TEXT, 375 * skinFactor, 3, 500 * skinFactor, 26 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Serie, setFarbe, setFarbe), (eListboxPythonMultiContent.TYPE_TEXT, 375 * skinFactor, 29 * skinFactor, 500 * skinFactor, 18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Staffel) ] else: return [entry, (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 15, 15 * skinFactor, 30 * skinFactor, 30 * skinFactor, loadPNG(icon)), (eListboxPythonMultiContent.TYPE_TEXT, 50 * skinFactor, 3, 200 * skinFactor, 26 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Sender, foregroundColor, foregroundColor), (eListboxPythonMultiContent.TYPE_TEXT, 50 * skinFactor, 29 * skinFactor, 200 * skinFactor, 18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, xtime), (eListboxPythonMultiContent.TYPE_TEXT, 300 * skinFactor, 3, 500 * skinFactor, 26 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Serie, setFarbe, setFarbe), (eListboxPythonMultiContent.TYPE_TEXT, 300 * skinFactor, 29 * skinFactor, 500 * skinFactor, 18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Staffel) ] def serieInfo(self): check = self[self.modus].getCurrent() if check is None: return serien_id = self[self.modus].getCurrent()[0][4] if serien_id > 0: serien_name = self[self.modus].getCurrent()[0][0] from SerienRecorderSeriesInfoScreen import serienRecShowInfo self.session.open(serienRecShowInfo, serien_name, serien_id) def wunschliste(self): serien_id = self[self.modus].getCurrent()[0][4] super(self.__class__, self).wunschliste(serien_id) def setupClose(self, result): super(self.__class__, self).setupClose(result) def keyOK(self): check = self[self.modus].getCurrent() if check is None: print "[SerienRecorder] Proposal-DB leer." return else: (Serie, Staffel, Sender, UTCTime, ID, MarkerFlag) = self[self.modus].getCurrent()[0] (existingID, AbStaffel, AlleSender) = self.database.getMarkerSeasonAndChannelSettings(Serie) if existingID > 0: # Add season and channel of selected series to marker self.database.updateMarkerSeasonAndChannelSettings(existingID, AbStaffel, Staffel, AlleSender, Sender) # Activate marker self.database.setMarkerStatus(Serie, config.plugins.serienRec.BoxID.value, True) else: if config.plugins.serienRec.activateNewOnThisSTBOnly.value: boxID = config.plugins.serienRec.BoxID.value else: boxID = None self.database.addMarker(str(ID), Serie, "", boxID, 0) if config.plugins.serienRec.openMarkerScreen.value: from SerienRecorderMarkerScreen import serienRecMarker self.session.open(serienRecMarker, Serie) self.changesMade = True self.buildProposalList() self.chooseMenuList.setList(map(self.buildList, self.proposalList)) def keyYellow(self): if self.filter: self.filter = False else: self.filter = True self.buildProposalList() def keyLeft(self): self[self.modus].pageUp() serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def keyRight(self): self[self.modus].pageDown() serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def keyDown(self): self[self.modus].down() serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def keyUp(self): self[self.modus].up() serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def __onClose(self): self.stopDisplayTimer()
class serienRecShowSeasonBegins(serienRecBaseScreen, Screen, HelpableScreen): def __init__(self, session): serienRecBaseScreen.__init__(self, session) Screen.__init__(self, session) HelpableScreen.__init__(self) self.modus = "menu_list" self.session = session self.picload = ePicLoad() self.ErrorMsg = "unbekannt" self.piconLoader = PiconLoader() self.picloader = None self.filter = False self.database = SRDatabase(SerienRecorder.serienRecDataBaseFilePath) self.changesMade = False self["actions"] = HelpableActionMap( self, "SerienRecorderActions", { "ok": (self.keyOK, "Marker für die ausgewählte Serie hinzufügen"), "cancel": (self.keyCancel, "zurück zur vorherigen Ansicht"), "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"), "menu": (self.recSetup, "Menü für globale Einstellungen öffnen"), "yellow": (self.keyYellow, "Zeige nur Serien-Starts"), "startTeletext": (self.wunschliste, "Informationen zur ausgewählten Serie auf Wunschliste anzeigen" ), "0": (self.readLogFile, "Log-File des letzten Suchlaufs anzeigen"), "2": (self.changeTVDBID, "TVDB-ID ändern"), "4": (self.serieInfo, "Informationen zur ausgewählten Serie anzeigen"), "6": (self.showConflicts, "Liste der Timer-Konflikte anzeigen"), "7": (self.showWishlist, "Merkzettel (vorgemerkte Folgen) anzeigen"), }, -1) self.helpList[0][2].sort() self["helpActions"] = ActionMap([ "SerienRecorderActions", ], { "displayHelp": self.showHelp, "displayHelp_long": self.showManual, }, 0) self.setupSkin() self.timer_default = eTimer() if isDreamOS(): self.timer_default_conn = self.timer_default.timeout.connect( self.readProposal) else: self.timer_default.callback.append(self.readProposal) self.proposalList = [] self.transmissions = {} self.serviceRefs = self.database.getActiveServiceRefs() self.onLayoutFinish.append(self.setSkinProperties) self.onLayoutFinish.append(self.__onLayoutFinish) self.onClose.append(self.__onClose) def callHelpAction(self, *args): HelpableScreen.callHelpAction(self, *args) def setSkinProperties(self): super(self.__class__, self).setSkinProperties() self['text_ok'].setText("Marker hinzufügen") self['text_yellow'].setText("Zeige Serienstarts") self.num_bt_text[2][0] = "TVDB-ID ändern" self.num_bt_text[3][0] = buttonText_na super(self.__class__, self).startDisplayTimer() def setupSkin(self): super(self.__class__, self).setupSkin() self[self.modus].show() if config.plugins.serienRec.showCover.value: self['cover'].show() if not config.plugins.serienRec.showAllButtons.value: self['bt_ok'].show() self['bt_yellow'].show() self['bt_exit'].show() self['bt_text'].show() self['bt_info'].show() self['bt_menu'].show() self['text_ok'].show() self['text_yellow'].show() self['text_0'].show() self['text_1'].show() self['text_2'].show() self['text_3'].show() self['text_4'].show() self['text_6'].show() self['text_7'].show() self['text_8'].show() self['text_9'].show() def updateMenuKeys(self): updateMenuKeys(self) def __onLayoutFinish(self): self['title'].setText("Lade neue Serien/Staffeln...") self.timer_default.start(0) def changeTVDBID(self): from SerienRecorderScreenHelpers import EditTVDBID serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] editTVDBID = EditTVDBID(self, self.session, serien_name, serien_id) editTVDBID.changeTVDBID() def readProposal(self): self.timer_default.stop() webChannels = self.database.getActiveChannels() self.proposalList = [] transmissionResults = downloadSeasonBegins(webChannels) transmissionResults.start() transmissionResults.join() if not transmissionResults.getData(): print "[SerienRecorder]: Abfrage beim SerienServer doGetSeasonBegins() fehlgeschlagen" else: self.transmissions = transmissionResults.getData() self.buildProposalList() def buildProposalList(self): markers = self.database.getAllMarkerStatusForBoxID( config.plugins.serienRec.BoxID.value) self.proposalList = [] if self.filter: self['text_yellow'].setText("Serien-/Staffelstarts") else: self['text_yellow'].setText("Zeige Serienstarts") for event in self.transmissions['events']: if self.filter and str( event['season']).isdigit() and int(event['season']) > 1: continue seriesName = event['name'].encode('utf-8') seriesID = int(event['id']) # marker flags: 0 = no marker, 1 = active marker, 2 = inactive marker markerFlag = 0 if seriesID in markers: markerFlag = 1 if markers[seriesID] else 2 self.proposalList.append([ seriesName, event['season'], event['channel'].encode('utf-8'), event['start'], event['id'], markerFlag ]) if self.filter: self['title'].setText("%d neue Serien gefunden:" % len(self.proposalList)) else: self['title'].setText("%d neue Serien/Staffeln gefunden:" % len(self.proposalList)) self.chooseMenuList.setList(map(self.buildList, self.proposalList)) if self['menu_list'].getCurrent(): serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def buildList(self, entry): (Serie, Staffel, Sender, UTCTime, ID, MarkerFlag) = entry icon = imageNone = "%simages/black.png" % SerienRecorder.serienRecMainPath imageNeu = "%simages/neu.png" % SerienRecorder.serienRecMainPath if MarkerFlag == 1: setFarbe = parseColor('green').argb() elif MarkerFlag == 2: setFarbe = parseColor('red').argb() else: setFarbe = parseColor('foreground').argb() if str(Staffel).isdigit() and int(Staffel) == 1: icon = imageNeu foregroundColor = parseColor('foreground').argb() Staffel = "Staffel %s" % str(Staffel) WochenTag = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"] xtime = time.strftime( WochenTag[time.localtime(int(UTCTime)).tm_wday] + ", %d.%m.%Y", time.localtime(int(UTCTime))) if config.plugins.serienRec.showPicons.value != "0": picon = loadPNG(imageNone) if Sender and self.serviceRefs.get(Sender): # Get picon by reference or by 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, 10, 5, 80 * skinFactor, 40 * skinFactor, picon), (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 340 * skinFactor, 15 * skinFactor, 30 * skinFactor, 30 * skinFactor, loadPNG(icon)), (eListboxPythonMultiContent.TYPE_TEXT, 110 * skinFactor, 3, 230 * skinFactor, 26 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Sender, foregroundColor, foregroundColor), (eListboxPythonMultiContent.TYPE_TEXT, 110 * skinFactor, 29 * skinFactor, 200 * skinFactor, 18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, xtime), (eListboxPythonMultiContent.TYPE_TEXT, 375 * skinFactor, 3, 500 * skinFactor, 26 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Serie, setFarbe, setFarbe), (eListboxPythonMultiContent.TYPE_TEXT, 375 * skinFactor, 29 * skinFactor, 500 * skinFactor, 18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Staffel) ] else: return [ entry, (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 15, 15 * skinFactor, 30 * skinFactor, 30 * skinFactor, loadPNG(icon)), (eListboxPythonMultiContent.TYPE_TEXT, 50 * skinFactor, 3, 230 * skinFactor, 26 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Sender, foregroundColor, foregroundColor), (eListboxPythonMultiContent.TYPE_TEXT, 50 * skinFactor, 29 * skinFactor, 200 * skinFactor, 18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, xtime), (eListboxPythonMultiContent.TYPE_TEXT, 300 * skinFactor, 3, 500 * skinFactor, 26 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Serie, setFarbe, setFarbe), (eListboxPythonMultiContent.TYPE_TEXT, 300 * skinFactor, 29 * skinFactor, 500 * skinFactor, 18 * skinFactor, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER, Staffel) ] def serieInfo(self): check = self[self.modus].getCurrent() if check is None: return serien_id = self[self.modus].getCurrent()[0][4] if serien_id > 0: serien_name = self[self.modus].getCurrent()[0][0] from SerienRecorderSeriesInfoScreen import serienRecShowInfo self.session.open(serienRecShowInfo, serien_name, serien_id) def wunschliste(self): serien_id = self[self.modus].getCurrent()[0][4] super(self.__class__, self).wunschliste(serien_id) def setupClose(self, result): super(self.__class__, self).setupClose(result) def keyOK(self): check = self[self.modus].getCurrent() if check is None: print "[SerienRecorder] Proposal-DB leer." return else: (Serie, Staffel, Sender, UTCTime, ID, MarkerFlag) = self[self.modus].getCurrent()[0] (existingID, AbStaffel, AlleSender ) = self.database.getMarkerSeasonAndChannelSettings(Serie) if existingID > 0: # Add season and channel of selected series to marker self.database.updateMarkerSeasonAndChannelSettings( existingID, AbStaffel, Staffel, AlleSender, Sender) # Activate marker self.database.setMarkerStatus( Serie, config.plugins.serienRec.BoxID.value, True) else: if config.plugins.serienRec.activateNewOnThisSTBOnly.value: boxID = config.plugins.serienRec.BoxID.value else: boxID = None self.database.addMarker(str(ID), Serie, "", boxID, 0) if config.plugins.serienRec.openMarkerScreen.value: from SerienRecorderMarkerScreen import serienRecMarker self.session.open(serienRecMarker, Serie) self.changesMade = True self.buildProposalList() self.chooseMenuList.setList(map(self.buildList, self.proposalList)) def keyYellow(self): if self.filter: self.filter = False else: self.filter = True self.buildProposalList() def keyLeft(self): self[self.modus].pageUp() serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def keyRight(self): self[self.modus].pageDown() serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def keyDown(self): self[self.modus].down() serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def keyUp(self): self[self.modus].up() serien_name = self[self.modus].getCurrent()[0][0] serien_id = self[self.modus].getCurrent()[0][4] SerienRecorder.getCover(self, serien_name, serien_id) def __onClose(self): self.stopDisplayTimer()
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()
def getEmailData(): # extract all html parts def get_html(email_message_instance): maintype = email_message_instance.get_content_maintype() if maintype == 'multipart': for part in email_message_instance.get_payload(): if part.get_content_type() == 'text/html': return part.get_payload() SRLogger.writeLog("\n---------' Lade TV-Planer E-Mail '---------\n", True) # get emails if len(config.plugins.serienRec.imap_server.value) == 0: SRLogger.writeLog("TV-Planer: imap_server nicht gesetzt", True) return None if len(config.plugins.serienRec.imap_login_hidden.value) == 0: SRLogger.writeLog("TV-Planer: imap_login nicht gesetzt", True) return None if len(config.plugins.serienRec.imap_password_hidden.value) == 0: SRLogger.writeLog("TV-Planer: imap_password nicht gesetzt", True) return None if len(config.plugins.serienRec.imap_mailbox.value) == 0: SRLogger.writeLog("TV-Planer: imap_mailbox nicht gesetzt", True) return None if len(config.plugins.serienRec.imap_mail_subject.value) == 0: SRLogger.writeLog("TV-Planer: imap_mail_subject nicht gesetzt", True) return None if 1 > config.plugins.serienRec.imap_mail_age.value > 100: config.plugins.serienRec.imap_mail_age.value = 1 try: if config.plugins.serienRec.imap_server_ssl.value: mail = imaplib.IMAP4_SSL(config.plugins.serienRec.imap_server.value, config.plugins.serienRec.imap_server_port.value) else: mail = imaplib.IMAP4(config.plugins.serienRec.imap_server.value, config.plugins.serienRec.imap_server_port.value) except imaplib.IMAP4.abort: SRLogger.writeLog("TV-Planer: Verbindung zum Server fehlgeschlagen", True) return None except imaplib.IMAP4.error: SRLogger.writeLog("TV-Planer: Verbindung zum Server fehlgeschlagen", True) return None try: mail.login(decrypt(getmac("eth0"), config.plugins.serienRec.imap_login_hidden.value), decrypt(getmac("eth0"), config.plugins.serienRec.imap_password_hidden.value)) print "[serienrecorder]: imap login ok" except imaplib.IMAP4.error: SRLogger.writeLog("TV-Planer: Anmeldung auf Server fehlgeschlagen", True) print "[serienrecorder]: imap login failed" return None try: mail.select(config.plugins.serienRec.imap_mailbox.value) except imaplib.IMAP4.error: SRLogger.writeLog("TV-Planer: Mailbox %r nicht gefunden" % config.plugins.serienRec.imap_mailbox.value, True) return None searchstr = TimeHelpers.getMailSearchString() try: result, data = mail.uid('search', None, searchstr) if result != 'OK': SRLogger.writeLog("TV-Planer: Fehler bei der Suche nach TV-Planer E-Mails", True) SRLogger.writeLog("TV-Planer: %s" % data, True) return None except imaplib.IMAP4.error: SRLogger.writeLog("TV-Planer: Keine TV-Planer Nachricht in den letzten %s Tagen" % str(config.plugins.serienRec.imap_mail_age.value), True) SRLogger.writeLog("TV-Planer: %s" % searchstr, True) return None if len(data[0]) == 0: SRLogger.writeLog("TV-Planer: Keine TV-Planer Nachricht in den letzten %s Tagen" % str(config.plugins.serienRec.imap_mail_age.value), True) SRLogger.writeLog("TV-Planer: %s" % searchstr, True) return None # get the latest email latest_email_uid = data[0].split()[-1] # fetch the email body (RFC822) for the given UID try: result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') except: SRLogger.writeLog("TV-Planer: Laden der E-Mail fehlgeschlagen", True) return None mail.logout() # extract email message including headers and alternate payloads email_message = email.message_from_string(data[0][1]) if len(email_message) == 0: SRLogger.writeLog("TV-Planer: leere E-Mail", True) return None # get html of wunschliste html = get_html(email_message) if html is None or len(html) == 0: SRLogger.writeLog("TV-Planer: leeres HTML", True) return None # make one line and convert characters html = html.replace('=\r\n', '').replace('=\n', '').replace('=\r', '').replace('\n', '').replace('\r', '') html = html.replace('=3D', '=') try: def getTextContentByTitle(node, titleValue, default): titleNodes = node.childNodes.getElementsByAttr('title', titleValue) if titleNodes: return titleNodes[0].textContent.encode('utf-8') else: return default def getEpisodeTitle(node): childNodes = node.childNodes.getElementsByTagName('a') if childNodes: return childNodes[0].textContent.encode('utf-8') else: # Movies does not a link to the episode => only country, year childNodes = node.childNodes.getElementsByTagName('span') if childNodes: return childNodes[0].textContent.encode('utf-8') else: return '' import AdvancedHTMLParser parser = AdvancedHTMLParser.AdvancedHTMLParser() html = parser.unescape(html).encode('utf-8') parser.parseStr(html) # Get tables from HTML tables = parser.getElementsByTagName('table') # Initialize regular expressions date_regexp = re.compile('.*TV-Planer.*?den ([0-3][0-9]\.[0-1][0-9]\.20[0-9][0-9])\s.(?:\(ab (.*?) Uhr\))?') url_title_regexp = re.compile('.*<a href="([^\?]+)(?:\?.*)?".*><strong.*>(.*)</strong>') endtime_regexp = re.compile('.*bis:\s(.*)\sUhr.*') # Get date and time of TV-Planer header = tables[1].getAllChildNodes().getElementsByTagName('div')[0].textContent.encode('utf-8') planerDateTime = date_regexp.findall(header)[0] print planerDateTime # Get transmissions transmissions = [] transmissionTable = tables[1].getAllChildNodes().getElementsByTagName('table')[0] transmissionRows = transmissionTable.childNodes for transmissionRow in transmissionRows: transmission = [] if not transmissionRow.hasAttribute('style'): transmissionColumns = transmissionRow.childNodes # Each transmission row has three columns # [0]: Start time starttime = transmissionColumns[0].textContent.encode('utf-8') if starttime != 'Anzeige': transmission.append(starttime.replace(' Uhr', '')) # [1]: URL, Title, Season, Episode, Info transmissionColumn = transmissionColumns[1] # Season, Episode, Title, Episode info, End time episodeInfo = ['0', '00', '', '', '0.00'] if transmissionColumn.firstChild: # First child is always URL + Title url_title = url_title_regexp.findall(transmissionColumn.firstChild.toHTML().encode('utf-8'))[0] transmission.extend(url_title) if transmissionColumn.lastChild: # Last element => End time (it has to be filled with a time because later on the time will be splitted) endtime = endtime_regexp.findall(transmissionColumn.lastChild.toHTML().encode('utf-8')) if endtime: episodeInfo[4] = endtime[0] divPartIndex = 0 for transmissionPart in transmissionColumn.childNodes: if transmissionPart is transmissionColumn.lastChild: # Skip part if it the "last" part continue if transmissionPart.tagName == 'div' and divPartIndex == 0: # First div element => Season / Episode / Title / e.g. NEU episodeInfo[0] = getTextContentByTitle(transmissionPart, 'Staffel', '0') episodeInfo[1] = getTextContentByTitle(transmissionPart, 'Episode', '00') episodeInfo[2] = getEpisodeTitle(transmissionPart) divPartIndex += 1 elif transmissionPart.tagName == 'div' and divPartIndex == 1: # Second div element => Episode info episodeInfo[3] = transmissionPart.textContent.encode('utf-8') transmission.extend(episodeInfo) # [2] Channel transmission.append(transmissionColumns[2].textContent.encode('utf-8')) print transmission transmissions.append(transmission) except: SRLogger.writeLog("TV-Planer: HTML Parsing abgebrochen", True) return None # prepare transmissions # [ ( seriesName, channel, start, end, season, episode, title, '0' ) ] # calculate start time and end time of list in E-Mail missingTime = False if len(planerDateTime) != 2: SRLogger.writeLog("TV-Planer: falsches Datumsformat", True) return None (day, month, year) = planerDateTime[0].split('.') if not planerDateTime[1]: if transmissions: # Get time of first transmission (hour, minute) = transmissions[0][0].split(':') else: missingTime = True (hour, minute) = ('00', '00') else: (hour, minute) = planerDateTime[1].split(':') liststarttime_unix = TimeHelpers.getRealUnixTime(minute, hour, day, month, year) # generate dictionary with final transmissions SRLogger.writeLog("Ab dem %s %s Uhr wurden die folgenden Sendungen gefunden:\n" % (planerDateTime[0], planerDateTime[1])) print "[SerienRecorder] Ab dem %s %s Uhr wurden die folgenden Sendungen gefunden:" % (planerDateTime[0], planerDateTime[1]) if missingTime: SRLogger.writeLog("In der Kopfzeile der TV-Planer E-Mail konnte keine Uhrzeit gefunden werden, bitte kontrollieren Sie die angelegten Timer!\n") transmissiondict = dict() for starttime, url, seriesname, season, episode, titel, description, endtime, channel in transmissions: try: if url.startswith('https://www.wunschliste.de/spielfilm'): if not config.plugins.serienRec.tvplaner_movies.value: SRLogger.writeLog("' %s - Filmaufzeichnung ist deaktiviert '" % seriesname, True) print "' %s - Filmaufzeichnung ist deaktiviert '" % seriesname continue transmissiontype = '[ Film ]' elif url.startswith('https://www.wunschliste.de/serie'): if not config.plugins.serienRec.tvplaner_series.value: SRLogger.writeLog("' %s - Serienaufzeichnung ist deaktiviert '" % seriesname, True) print "' %s - Serienaufzeichnung ist deaktiviert '" % seriesname continue transmissiontype = '[ Serie ]' else: SRLogger.writeLog("' %s - Ungültige URL %r '" % (seriesname, url), True) print "' %s - Serienaufzeichnung ist deaktiviert '" % seriesname continue # series transmission = [ seriesname ] # channel channel = channel.replace(' (Pay-TV)','').replace(' (Schweiz)','').replace(' (GB)','').replace(' (Österreich)','').replace(' (USA)','').replace(' (RP)','').replace(' (F)','').strip() transmission += [ channel ] # start time (hour, minute) = starttime.split(':') transmissionstart_unix = TimeHelpers.getRealUnixTime(minute, hour, day, month, year) if transmissionstart_unix < liststarttime_unix: transmissionstart_unix = TimeHelpers.getRealUnixTimeWithDayOffset(minute, hour, day, month, year, 1) transmission += [ transmissionstart_unix ] # end time (hour, minute) = endtime.split('.') transmissionend_unix = TimeHelpers.getRealUnixTime(minute, hour, day, month, year) if transmissionend_unix < transmissionstart_unix: transmissionend_unix = TimeHelpers.getRealUnixTimeWithDayOffset(minute, hour, day, month, year, 1) transmission += [ transmissionend_unix ] # season if season == '': season = '0' transmission += [ season ] # episode if episode == '': episode = '00' transmission += [ episode ] # title transmission += [ quopri.decodestring(titel) ] # last transmission += [ '0' ] # url transmission += [ url ] # store in dictionary transmissiondict[seriesname] = [ seriesname: [ transmission 0 ], [ transmission 1], .... ] if seriesname in transmissiondict: transmissiondict[seriesname] += [ transmission ] else: transmissiondict[seriesname] = [ transmission ] SRLogger.writeLog("' %s - S%sE%s - %s - %s - %s - %s - %s '" % (transmission[0], str(transmission[4]).zfill(2), str(transmission[5]).zfill(2), transmission[6], transmission[1], time.strftime("%d.%m.%Y %H:%M", time.localtime(int(transmissionstart_unix))), time.strftime("%d.%m.%Y %H:%M", time.localtime(int(transmissionend_unix))), transmissiontype), True) print "[SerienRecorder] ' %s - S%sE%s - %s - %s - %s - %s - %s'" % (transmission[0], str(transmission[4]).zfill(2), str(transmission[5]).zfill(2), transmission[6], transmission[1], time.strftime("%d.%m.%Y %H:%M", time.localtime(int(transmissionstart_unix))), time.strftime("%d.%m.%Y %H:%M", time.localtime(int(transmissionend_unix))), transmissiontype) except Exception as e: SRLogger.writeLog("TV-Planer Verarbeitung fehlgeschlagen! [%s]" % str(e), True) if config.plugins.serienRec.tvplaner_create_marker.value: database = SRDatabase(SerienRecorder.serienRecDataBaseFilePath) for seriesname in transmissiondict.keys(): # marker isn't in database, create new marker # url stored in marker isn't the final one, it is corrected later url = transmissiondict[seriesname][0][-1] marker_type = "Serien Marker" try: boxID = None if url.startswith('https://www.wunschliste.de/serie'): seriesID = SeriesServer().getIDByFSID(url[str.rindex(url, '/') + 1:]) if seriesID > 0: url = str(seriesID) else: url = None if config.plugins.serienRec.tvplaner_series_activeSTB.value: boxID = config.plugins.serienRec.BoxID.value elif url.startswith('https://www.wunschliste.de/spielfilm'): marker_type = "Temporärer Serien Marker" if config.plugins.serienRec.tvplaner_movies_activeSTB.value: boxID = config.plugins.serienRec.BoxID.value else: url = None if url and not database.markerExists(url): if database.addMarker(url, seriesname, "", boxID, 1 if url.startswith('https://www.wunschliste.de/spielfilm') else 0): SRLogger.writeLog("\n%s für ' %s ' wurde angelegt" % (marker_type, seriesname), True) print "[SerienRecorder] ' %s - %s erzeugt '" % (seriesname, marker_type) except Exception as e: SRLogger.writeLog("\n%s für ' %s ' konnte wegen eines Fehlers nicht angelegt werden [%s]" % (marker_type, seriesname, str(e)), True) print "[SerienRecorder] ' %s - %s konnte wegen eines Fehlers nicht angelegt werden [%s]'" % (seriesname, marker_type, str(e)) else: SRLogger.writeLog("Es werden keine Serien-Marker aus der TV-Planer E-Mail erstellt.", True) return transmissiondict