예제 #1
0
        def parseHeader(data, pos):
            e = struct.unpack(">HHBBBBBBH", data[pos:pos + 12])
            self.eit["event_id"] = e[0]
            y, mo, d = parseMJD(e[1])  # Y, M, D
            h, mi, s = unBCD(e[2]), unBCD(e[3]), unBCD(e[4])  # HH, MM, SS
            try:
                dt = datetime.datetime(y, mo, d, h, mi, s)
                logger.debug("dt: %s", str(dt))
                start_seconds = int(time.mktime(dt.timetuple()))
                self.eit[
                    "start"] = start_seconds - time.timezone + time.localtime(
                        start_seconds).tm_isdst * 3600  # daylight savings time
            except Exception as e:
                logger.error("exception: %s", e)
                self.eit["start"] = 0

            self.eit["length"] = unBCD(e[5]) * 3600 + unBCD(e[6]) * 60 + unBCD(
                e[7])

            #free_CA_mode = e[8] & 0x1000
            #descriptors_loop_length = e[8] & 0x0fff

            running_status = (e[8] & 0xe000) >> 13
            if running_status in [1, 2]:
                self.eit['when'] = "NEXT"
            elif running_status in [3, 4]:
                self.eit['when'] = "NOW"
예제 #2
0
def writeFile(path, data):
    try:
        f = open(path, "w")
        f.write(data)
        f.close()
    except Exception as e:
        logger.error("path: %s, exception: %s", path, e)
예제 #3
0
 def keySaveNew(self):
     logger.debug("...")
     save_value = True
     for i, conf in enumerate(self.config_list):
         #logger.debug("i: %s, conf[0]: %s", i, conf[0])
         if conf[0] != self.section:
             if conf[1].isChanged():
                 #logger.debug("i: %s, conf[0]: %s isChanged", i, conf[0])
                 if conf[2]:
                     # execute value changed function
                     #logger.debug("execute value changed function")
                     if not conf[2](conf[1]):
                         logger.error("value function error: %s", conf[0])
                         save_value = False
                 # Check parent entries
                 for parent in conf[5]:
                     #logger.debug("parent: %s, conf[5]: %s", str(parent), str(conf[5]))
                     if self.config_list[i + parent][2]:
                         # execute parent value changed function
                         #logger.debug("execute parent value changed function")
                         if not self.config_list[i + parent][2](
                                 self.config_list[i + parent][1]):
                             logger.error("parent value function error: %s",
                                          self.config_list[i + parent][2])
                 if save_value:
                     logger.debug("saving: %s", conf[0])
                     conf[1].save()
     configfile.save()
     if not save_value:
         self.createConfig()
     else:
         if self.needs_restart:
             self.restartGUI()
         else:
             self.close(True)
예제 #4
0
    def setSubtitleState(self, enabled):
        logger.info("enabled: %s", enabled)
        try:
            if not self.config_plugins_plugin.autosubs.value or not enabled:
                return

            subs = self.getCurrentServiceSubtitle() if isinstance(
                self, InfoBarSubtitleSupport) else None
            n = (subs.getNumberOfSubtitleTracks() if subs else 0)
            if n == 0:
                return

            self.sub_format_dict = {}
            self.gstsub_format_dict = {}
            for index, (short, _text, rank) in sorted(SUB_FORMATS.items(),
                                                      key=lambda x: x[1][2]):
                if rank > 0:
                    self.sub_format_dict[index] = short
            for index, (short, _text, rank) in sorted(GST_SUB_FORMATS.items(),
                                                      key=lambda x: x[1][2]):
                if rank > 0:
                    self.gstsub_format_dict[index] = short
            lt = []
            alist = []
            for index in range(n):
                info = subs.getSubtitleTrackInfo(index)
                languages = info.getLanguage().split('/')
                logger.debug("lang %s", languages)
                iType = info.getType()
                logger.debug("type %s", iType)
                if iType == iSubtitleType_ENUMS.GST:
                    iType = info.getGstSubtype()
# 				codec = self.gstsub_format_dict[iType] if iType in self.gstsub_format_dict else '?'
# 			else:
# 				codec = self.sub_format_dict[iType] if iType in self.sub_format_dict else '?'
# 			logger.debug("codec %s", codec)
                lt.append((index, (iType == 1 and "DVB" or iType == 2 and "TTX"
                                   or "???"), languages))
            if lt:
                logger.debug("%s", str(lt))
                for e in lt:
                    alist.append(
                        (e[0], e[1], e[2][0] in langC and langC[e[2][0]][0]
                         or e[2][0]))
                    if alist:
                        logger.debug("%s", str(alist))
                        for sublang in [
                                self.config_plugins_plugin.sublang1.value,
                                self.config_plugins_plugin.sublang2.value,
                                self.config_plugins_plugin.sublang3.value
                        ]:
                            if self.trySubEnable(alist, sublang):
                                break
        except Exception as e:
            logger.error("exception: %s", e)
예제 #5
0
 def load(self):
     self._mounts = {}
     self._numActive = 0
     if os.path.exists(XML_FSTAB):
         try:
             tree = cet_parse(XML_FSTAB).getroot()
             self._parse(tree, ["nfs", "cifs"], [
                 AutoMount.DEFAULT_OPTIONS_NFS,
                 AutoMount.DEFAULT_OPTIONS_CIFS
             ])
         except Exception as msg:
             logger.error("error msg: %s", msg)
     logger.info("mounts.keys(): %s", self._mounts.keys())
예제 #6
0
def convertToUtf8(text, codepage="cp1252", first=True):
	if text and codepage is not None:
		try:
			if codepage != 'utf-8':
				text = text.decode(codepage).encode("utf-8")
			else:
				text.decode('utf-8')
		except (UnicodeDecodeError, AttributeError) as e:
			if first:
				text = convertToUtf8(text, "iso-8859-1", False)
			else:
				logger.error("text: %s, codepage: %s, first: %s, exception: %s", text, codepage, first, e)
	return text.strip()
	def setAudioTrack(self):
		try:
			logger.debug("audio")
			if not self.config_plugins_plugin.autoaudio.value:
				return
			service = self.session.nav.getCurrentService()
			tracks = service and self.getServiceInterface("audioTracks")
			nTracks = tracks.getNumberOfTracks() if tracks else 0
			if not nTracks:
				return
			index = 0
			trackList = []
			for i in range(nTracks):
				audioInfo = tracks.getTrackInfo(i)
				lang = audioInfo.getLanguage()
				logger.debug("lang %s", lang)
				desc = audioInfo.getDescription()
				logger.debug("desc %s", desc)
# 			audio_type = audioInfo.getType()
				track = index, lang, desc, type
				index += 1
				trackList += [track]
			seltrack = tracks.getCurrentTrack()
			# we need default selected language from image
			# to set the audio track if "self.config_plugins_plugin.autoaudio.value" are not set
			syslang = language.getLanguage()[:2]
			if self.config_plugins_plugin.autoaudio.value:
				audiolang = [self.config_plugins_plugin.audlang1.value, self.config_plugins_plugin.audlang2.value, self.config_plugins_plugin.audlang3.value]
			else:
				audiolang = syslang
			useAc3 = self.config_plugins_plugin.autoaudio_ac3.value
			if useAc3:
				matchedAc3 = self.tryAudioTrack(tracks, audiolang, trackList, seltrack, useAc3)
				if matchedAc3:
					return
				matchedMpeg = self.tryAudioTrack(tracks, audiolang, trackList, seltrack, False)
				if matchedMpeg:
					return
				tracks.selectTrack(0)  # fallback to track 1(0)
			else:
				matchedMpeg = self.tryAudioTrack(tracks, audiolang, trackList, seltrack, False)
				if matchedMpeg:
					return
				matchedAc3 = self.tryAudioTrack(tracks, audiolang, trackList, seltrack, useAc3)
				if matchedAc3:
					return
				tracks.selectTrack(0)  # fallback to track 1(0)
			logger.debug("audio1")
		except Exception as e:
			logger.error("exception: %s", e)
예제 #8
0
 def downloadPreview(self):
     logger.info("...")
     self["preview"].hide()
     if self['list'].getCurrent():
         logger.debug("current: %s", str(self["list"].getCurrent()))
         url = self['list'].getCurrent()[2]
         logger.debug("url: %s", url)
         picon_path = os.path.join("/tmp",
                                   self['list'].getCurrent()[3] + ".png")
         if not os.path.exists(picon_path):
             try:
                 downloadPage(url, picon_path).addCallback(
                     self.showPreview,
                     picon_path).addErrback(self.downloadError, url)
             except Exception as e:
                 logger.error("url: %s, e: %s", url, e)
         else:
             self.showPreview(None, picon_path)
예제 #9
0
 def downloadError(self, result, url):
     logger.info("...")
     logger.error("url: %s, result: %s", url, result)
     self.session.open(MessageBox, _("Picon server access failed"),
                       MessageBox.TYPE_ERROR)
     self.createList(False)