示例#1
0
 def setPlayingTime(self, startTime, duration):
     utils.log("setPlayingTime")
     try:
         endTime = startTime + duration
         if startTime + endTime == 0:
             raise Exception()
         if self.clockMode == 0:
             st = datetime.datetime.fromtimestamp(float(startTime)).strftime("%I:%M %p").upper()
             et = datetime.datetime.fromtimestamp(float(endTime)).strftime("%I:%M %p").upper()
         else:
             st = datetime.datetime.fromtimestamp(float(startTime)).strftime("%H:%M")
             et = datetime.datetime.fromtimestamp(float(endTime)).strftime("%H:%M")
         utils.setProperty("Time",'%s - %s' % (st, et))
     except Exception as e: utils.clearProperty('Time')
示例#2
0
 def closeUEPG(self):
     del self.player
     self.removeControls(self.toRemove)
     for thread in threading.enumerate():
         if thread.name != "MainThread":
             try:
                 utils.log('canceling threads...')
                 thread.cancel()
                 thread.join()
             except Exception as e: utils.log('closeUEPG, failed to close thread ' + str(e), xbmc.LOGERROR)             
     utils.setProperty('uEPGRunning','False')
     #reopen originating plugin to avoid reloading uEPG on exit.
     xbmc.executebuiltin('XBMC.AlarmClock(%s,ActivateWindow(Videos,plugin://%s),0.5,true)'%('',self.channelLST.pluginPath))
     self.close
示例#3
0
    def onInit(self):
        utils.log('onInit')
        utils.setProperty('uEPGRunning','True')
        self.closeCount   = 0
        curtime           = time.time()
        self.lastActTime  = time.time()
        self.windowID     = self.getWindowID()
        self.windowIDS    = ["ActivateWindow(fullscreenvideo)","ActivateWindow(%s)"%self.windowID]
        self.windowToggle = itertools.cycle(self.windowIDS).next

        if self.onInitReturn == False:
            utils.log('onInit, onInitReturn = False')
            self.guideLimit     = 14400
            self.rowCount       = self.chkRows(self.rowCount)
            self.epgButtonwidth = float((utils.getProperty("uEPG.buttonWidth"))         or "5400.0")
            self.timeCount      = int((utils.getProperty("uEPG.timeCount"))             or "3")
            self.textColor      = hex(int((utils.getProperty("uEPG.textColor")          or "0xFFFFFFFF"),16))[2:]
            self.disabledColor  = hex(int((utils.getProperty("uEPG.disabledColor")      or "0xFFFFFFFF"),16))[2:]
            self.focusedColor   = hex(int((utils.getProperty("uEPG.focusedColor")       or "0xFFFFFFFF"),16))[2:]
            self.shadowColor    = hex(int((utils.getProperty("uEPG.shadowColor")        or "0xFF000000"),16))[2:]
            self.pastColor      = hex(int((utils.getProperty("uEPG.pastColor")          or "0xFF0f85a5"),16))[2:]
            self.timeColor      = hex(int((utils.getProperty("uEPG.timeColor")          or "0xFF0f85a5"),16))[2:]
            self.futureColor    = hex(int((utils.getProperty("uEPG.futureColor")        or "0xFF0f85a5"),16))[2:]
            self.singleLineFade = (utils.getProperty("uEPG.singleLineFade")             or "false") == "true"
            self.textFont       = (utils.getProperty("uEPG.timeCount")                  or "font12")
            self.timeFormat     = (urllib.unquote(utils.getProperty("uEPG.timeFormat")) or "%A, %B %d")
            self.clockMode      = int(utils.REAL_SETTINGS.getSetting("ClockMode"))
        
            self.channelButtons = [None] * self.rowCount
            for i in range(self.rowCount): self.channelButtons[i] = []
            try:
                self.removeControl(self.fadePast)
                self.removeControl(self.currentTimeBar)
            except: pass
                
            self.focusChannel   = self.getControl(33009)
            self.currentHighLT  = self.getControl(33010)
            self.currentTime    = self.getControl(33007)
            timetx, timety      = self.currentTime.getPosition()
            timetw              = self.currentTime.getWidth()
            timeth              = self.currentTime.getHeight()
            
            self.currentLine    = self.getControl(33013)
            timex, timey        = self.currentLine.getPosition()
            timew               = self.currentLine.getWidth()
            timeh               = self.currentLine.getHeight()
            self.timeButtonBar  = os.path.join(self.channelLST.mediaFolder,utils.TIME_BAR)
            self.currentTimeBar = xbmcgui.ControlImage(timex, timey, timew, timeh, self.timeButtonBar, colorDiffuse=self.timeColor) 
            self.addControl(self.currentTimeBar)
            
            self.pastLine       = self.getControl(33011)
            timex, timey        = self.pastLine.getPosition()
            timew               = self.pastLine.getWidth()
            timeh               = self.pastLine.getHeight()
            self.pastTime       = os.path.join(self.channelLST.mediaFolder,utils.PAST_FADE)
            self.fadePast       = xbmcgui.ControlImage(timex, timey, timew, timeh, self.pastTime, colorDiffuse=self.pastColor)
            self.addControl(self.fadePast)
            
            self.futureLine     = self.getControl(33012)
            timex, timey        = self.futureLine.getPosition()
            timew               = self.futureLine.getWidth()
            timeh               = self.futureLine.getHeight()
            self.futureTime     = os.path.join(self.channelLST.mediaFolder,utils.FUTURE_FADE)
            self.fadeFuture     = xbmcgui.ControlImage(timex, timey, timew, timeh, self.futureTime, colorDiffuse=self.futureColor)
            self.addControl(self.fadeFuture)

            self.TimeXYW = {}
            for i in range(self.timeCount):
                self.TimeXYW['Time%dX'%(i + 1)] = self.getControl(33101 + i).getPosition()[0]
                self.TimeXYW['Time%dY'%(i + 1)] = self.getControl(33101 + i).getPosition()[1]
                self.TimeXYW['Time%dW'%(i + 1)] = int(round(self.getControl(33101 + i).getWidth()//2))
        
            self.TimeRange = {}
            for i in range(self.timeCount):
                self.TimeRange['Time%dRange'%(i + 1)] = range(self.TimeXYW['Time%dX'%(i + 1)] - self.TimeXYW['Time%dW'%(i + 1)],self.TimeXYW['Time%dX'%(i + 1)] + self.TimeXYW['Time%dW'%(i + 1)])

        if self.setChannelButtons(curtime, self.fixChannel(self.currentChannel)) == False:
            utils.log('Unable to add channel buttons')
            utils.notificationDialog("%s Error, Contact %s for support"%(self.channelLST.pluginName, self.channelLST.pluginAuthor))
            self.closeUEPG()
 
        self.setChannelButtons(curtime, self.fixChannel(self.currentChannel))
        basex, basey = self.getControl(33611 + self.focusRow).getPosition()
        basew = self.getControl(33611 + self.focusRow).getWidth()
        
        for i in range(len(self.channelButtons[self.focusRow])):
            left, top = self.channelButtons[self.focusRow][i].getPosition()
            width = self.channelButtons[self.focusRow][i].getWidth()
            left  = left - basex
            starttime = self.shownTime + (left / (basew / self.epgButtonwidth))
            endtime   = starttime + (width / (basew / self.epgButtonwidth))

            if curtime >= starttime and curtime <= endtime:
                utils.log('curtime focusIndex = %s'%i)
                self.focusIndex = i
                self.setFocus(self.channelButtons[self.focusRow][i])
                self.focusTime    = int(curtime)
                self.focusEndTime = endtime
                break
                
        if self.focusIndex == -1:
            self.focusIndex = 0
            self.setFocus(self.channelButtons[self.focusRow][self.focusIndex])
            left, top = self.channelButtons[self.focusRow][self.focusIndex].getPosition()
            width = self.channelButtons[self.focusRow][self.focusIndex].getWidth()
            left  = left - basex
            starttime = self.shownTime + (left / (basew / self.epgButtonwidth))
            endtime   = starttime + (width / (basew / self.epgButtonwidth))
            self.focusTime    = int(starttime + 30)
            self.focusEndTime = endtime
        
        self.setProperButton(0)
        self.setShowInfo()
        self.onInitReturn = True
        utils.log('onInit return')
示例#4
0
def initChannels(params, data, dataType):
    utils.log('initChannels, params = ' + str(params))
    with busy_dialog():
        hasChannels = False
        channelLST = ChannelList()
        channelLST.incHDHR = (
            params.get('include_hdhr', '')
            or utils.REAL_SETTINGS.getSetting('Enable_HDHR')) == 'true'
        channelLST.skinPath = (utils.unquote(params.get('skin_path', ''))
                               or channelLST.chkSkinPath())
        channelLST.mediaFolder = os.path.join(channelLST.skinPath, 'resources',
                                              'skins', 'default', 'media')
        channelLST.refreshPath = (utils.unquote(params.get('refresh_path', ''))
                                  or utils.ADDON_ID)
        channelLST.refreshIntvl = int(
            params.get('refresh_interval', '') or '0')
        channelLST.skinFolder = os.path.join(
            channelLST.skinPath,
            'resources',
            'skins',
            'default',
            '1080i',
        ) if xbmcvfs.exists(
            os.path.join(channelLST.skinPath, 'resources', 'skins', 'default',
                         '1080i', '%s.guide.xml' %
                         utils.ADDON_ID)) else os.path.join(
                             channelLST.skinPath, 'resources', 'skins',
                             'default', '720p')
        utils.setProperty('uEPG.rowCount',
                          (params.get('row_count', '') or '9'))
        channelLST.pluginName, channelLST.pluginAuthor, channelLST.pluginIcon, channelLST.pluginFanart, channelLST.pluginPath = utils.getPluginMeta(
            channelLST.refreshPath)

        utils.log('dataType = ' + str(dataType))
        utils.log('skinPath = ' + str(channelLST.skinPath))
        utils.log('skinFolder = ' + str(channelLST.skinFolder))
        utils.log('rowCount = ' + utils.getProperty('uEPG.rowCount'))
        utils.log('refreshPath = ' + str(channelLST.refreshPath))
        utils.log('refreshIntvl = ' + str(channelLST.refreshIntvl))
        utils.setProperty('PluginName', channelLST.pluginName)
        utils.setProperty('PluginIcon', channelLST.pluginIcon)
        utils.setProperty('PluginFanart', channelLST.pluginFanart)
        utils.setProperty('PluginAuthor', channelLST.pluginAuthor)
        utils.setProperty('pluginPath', channelLST.pluginPath)

        #show optional load screen
        # if channelLST.uEPGRunning == False and utils.getProperty('uEPGSplash') != 'True' and xbmcvfs.exists(os.path.join(channelLST.skinFolder,'%s.splash.xml'%utils.ADDON_ID)) == True:
        # mySplash   = epg.Splash('%s.splash.xml'%utils.ADDON_ID,channelLST.skinPath,'default')
        # mySplash.show()
        # xbmc.sleep(100)

        if utils.HDHR().hasHDHR():
            if utils.REAL_SETTINGS.getSetting(
                    'FirstTime_HDHR') == "true" and not channelLST.incHDHR:
                utils.REAL_SETTINGS.setSetting('FirstTime_HDHR', 'false')
                if utils.yesnoDialog(
                    (utils.LANGUAGE(30012) % (channelLST.pluginName)),
                        custom='Later'):
                    utils.REAL_SETTINGS.setSetting('Enable_HDHR', 'true')
                    channelLST.incHDHR = True
        utils.log('incHDHR = ' + str(channelLST.incHDHR))

    if dataType == 'wrap': hasChannels = channelLST.prepareJson(data)
    elif dataType == 'json':
        hasChannels = channelLST.prepareJson(
            utils.loadJson(utils.unquote(data)))
    elif dataType == 'property':
        hasChannels = channelLST.prepareJson(
            utils.loadJson(utils.unquote(utils.getProperty(data))))
    elif dataType == 'listitem':
        hasChannels = channelLST.prepareVFS(utils.unquote(data))

    if hasChannels == True:
        if utils.REAL_SETTINGS.getSetting('FirstTime_Run') == "true":
            utils.REAL_SETTINGS.setSetting('FirstTime_Run', 'false')
            utils.textViewer(
                utils.LANGUAGE(30008),
                '%s / %s' % (utils.ADDON_NAME, channelLST.pluginName))

        # if utils.getProperty('uEPGSplash') == 'True':
        # mySplash.close()
        # del mySplash
        # xbmc.sleep(100)

        if channelLST.refreshIntvl > 0 and channelLST.refreshPath is not None:
            channelLST.startRefreshTimer()
        if channelLST.uEPGRunning == False and utils.getProperty(
                'uEPGGuide') != 'True':
            channelLST.myEPG = epg.uEPG('%s.guide.xml' % utils.ADDON_ID,
                                        channelLST.skinPath, 'default')
            channelLST.myEPG.channelLST = channelLST
            channelLST.myEPG.doModal()
            del channelLST.myEPG
            xbmc.sleep(100)
    else:
        utils.log("invalid uEPG information", xbmc.LOGERROR)
        # utils.notificationDialog(utils.LANGUAGE(30002)%(channelLST.pluginName,channelLST.pluginAuthor),icon=channelLST.pluginIcon)
        # utils.REAL_SETTINGS.openSettings()
    del utils.KODI_MONITOR
示例#5
0
            utils.loadJson(utils.unquote(params.get('refresh_interval', '0')))
            or '0')
        channelLST.skinFolder = os.path.join(
            channelLST.skinPath,
            'resources',
            'skins',
            'default',
            '1080i',
        ) if xbmcvfs.exists(
            os.path.join(channelLST.skinPath, 'resources', 'skins', 'default',
                         '1080i', '%s.guide.xml' %
                         utils.ADDON_ID)) else os.path.join(
                             channelLST.skinPath, 'resources', 'skins',
                             'default', '720p')
        utils.setProperty(
            'uEPG.rowCount',
            utils.loadJson(utils.unquote(params.get('row_count', '9')) or '9'))
        channelLST.pluginName, channelLST.pluginAuthor, channelLST.pluginIcon, channelLST.pluginFanart, channelLST.pluginPath = utils.getPluginMeta(
            channelLST.refreshPath)

        utils.log('dataType = ' + str(dataType))
        utils.log('skinPath = ' + str(channelLST.skinPath))
        utils.log('skinFolder = ' + str(channelLST.skinFolder))
        utils.log('refreshPath = ' + str(channelLST.refreshPath))
        utils.log('refreshIntvl = ' + str(channelLST.refreshIntvl))
        utils.setProperty('PluginName', channelLST.pluginName)
        utils.setProperty('PluginIcon', channelLST.pluginIcon)
        utils.setProperty('PluginFanart', channelLST.pluginFanart)
        utils.setProperty('PluginAuthor', channelLST.pluginAuthor)

        #show optional load screen
示例#6
0
    def setChannelButtons(self, starttime, curchannel, singlerow=-1):
        starttime = utils.roundToHalfHour(int(starttime))
        utils.log('setChannelButtons, starttime = ' + str(starttime) +
                  ', curchannel = ' + str(curchannel))
        self.centerChannel = self.fixChannel(curchannel)
        self.shownTime = starttime
        self.setTimeLabels(starttime)

        myadds = []
        basecur = curchannel
        basew = self.getControl(33611).getWidth()
        basex, basey = self.getControl(33611).getPosition()
        timetw = self.currentTime.getWidth()
        timeth = self.currentTime.getHeight()
        timetx, timety = self.currentTime.getPosition()
        timew = self.currentLine.getWidth()
        timeh = self.currentLine.getHeight()
        timex, timey = self.currentLine.getPosition()
        utils.log('setChannelButtons, settime')
        self.toRemove.append(self.fadePast)
        self.toRemove.append(self.fadeFuture)
        self.toRemove.append(self.currentTimeBar)

        for i in range(self.rowCount):
            if singlerow == -1 or singlerow == i:
                self.setButtons(starttime, basecur, i)
                myadds.extend(self.channelButtons[i])
            basecur = self.fixChannel(basecur + 1)
        basecur = curchannel
        utils.log('setChannelButtons, row init')

        for i in range(self.rowCount):
            self.getControl(33511 + i).setLabel(
                self.channelLST.channels[basecur - 1].name)
            basecur = self.fixChannel(basecur + 1)

        self.currentHighLT.setVisible(False)
        for i in range(self.rowCount):
            chnumber = self.channelLST.channels[curchannel - 1].number
            if self.channelLST.channels[curchannel - 1].isHDHR:
                label = "[COLOR=%s][B]%s[/COLOR] |[/B]" % ('green',
                                                           str(chnumber))
            else:
                label = '[B]%s |[/B]' % (str(chnumber))
            self.getControl(33111 + i).setLabel(label)
            self.getControl(33411 + i).setImage(
                self.channelLST.channels[curchannel - 1].logo)
            utils.setProperty('FavColor', {
                True: self.favColor,
                False: self.favDefault
            }[self.channelLST.channels[curchannel - 1].isFavorite])

            if curchannel == self.currentChannel:
                utils.log('setChannelButtons, current playing channel row')
                if xbmc.Player().isPlayingVideo():
                    self.currentHighLT.setVisible(True)
                chx, chy = self.getControl(33611 + i).getPosition()
                chpx, chpy = self.currentHighLT.getPosition()
                self.currentHighLT.setPosition(chpx, chy)
            curchannel = self.fixChannel(curchannel + 1)

        curtime = time.time()
        if curtime >= starttime and curtime < starttime + self.epgButtonwidth:
            dif = int((starttime + self.epgButtonwidth - curtime))
            self.currentTime.setPosition(
                int((basex + basew - (timew / 2)) -
                    (dif * (basew / self.epgButtonwidth))) - (timetw / 2),
                timety)
            self.currentTimeBar.setPosition(
                int((basex + basew - (timew / 2)) -
                    (dif * (basew / self.epgButtonwidth))), timey)
        else:
            if curtime < starttime:
                self.currentTime.setPosition(-1800, timety)
                self.currentTimeBar.setPosition(basex, timey)
            else:
                self.currentTime.setPosition(-1800, timety)
                self.currentTimeBar.setPosition(basex + basew - timew, timey)

        now = datetime.datetime.now()
        if self.clockMode == 0: timeex = now.strftime("%I:%M%p").lower()
        else: timeex = now.strftime("%H:%M")
        self.currentTime.setLabel(timeex)

        TimeTX, TimeTY = self.currentTime.getPosition()
        TimeBX, TimeBY = self.currentTimeBar.getPosition()
        PFadeX, PFadeY = self.fadePast.getPosition()
        LTimeX = (TimeBX + (timew / 2))
        self.fadePast.setWidth(LTimeX - PFadeX)
        FFadeX, FFadeY = self.fadeFuture.getPosition()
        self.fadeFuture.setPosition(LTimeX, PFadeY)
        self.fadeFuture.setWidth(((basew - basex) - (timew / 2)) + TimeBX)
        TimeBW = int(self.currentTime.getWidth())
        TimeButton = range(LTimeX - int(round(TimeBW // 2)),
                           LTimeX + int(round(TimeBW // 2)))
        if LTimeX < self.TimeXYW['Time1X']:
            self.fadePast.setVisible(False)
            self.fadeFuture.setVisible(False)
            self.currentTimeBar.setVisible(False)
            self.currentLine.setVisible(False)
        else:
            self.fadePast.setVisible(True)
            self.currentTimeBar.setVisible(True)
            self.currentLine.setVisible(True)

        if LTimeX > self.TimeXYW['Time%dX' % (self.timeCount)]:
            self.currentTimeBar.setVisible(False)
            self.fadeFuture.setVisible(False)
        else:
            self.currentTimeBar.setVisible(True)
            self.fadeFuture.setVisible(True)

        myadds.append(self.fadePast)
        myadds.append(self.fadeFuture)
        myadds.append(self.currentTimeBar)

        if TimeTX == -1800:
            for i in range(self.timeCount):
                self.getControl(33101 + i).setVisible(True)
        else:
            for i in range(self.timeCount):
                self.getControl(33101 + i).setVisible(True)
                for pos in self.TimeRange['Time%dRange' % (i + 1)]:
                    if pos in TimeButton:
                        self.getControl(33101 + i).setVisible(False)
                        break
        try:
            self.removeControls(self.toRemove)
        except:
            for cntrl in self.toRemove:
                try:
                    self.removeControl(cntrl)
                except:
                    pass
        try:
            self.addControls(myadds)
        except:
            utils.log('setChannelButtons, addControls busy')
        self.toRemove = []
        utils.log('setChannelButtons return')
示例#7
0
def parse(filename: str) -> dict:
    # open the xkml file
    raw_xkml_lines = open(filename).readlines()

    # manipulate the file
    xkml_lines = []
    for line in raw_xkml_lines:
        # remove blank lines and comment lines
        if line.strip() != '' and not line.strip().startswith('#'):
            # and merge multiline (escaped with \ at the end of a line)
            if len(xkml_lines) > 1 and xkml_lines[-1].endswith('\\'):
                xkml_lines[-1] = xkml_lines[-1][:-1] + line.strip()
            else:
                xkml_lines.append(line.rstrip())

    # detect indentation spaces
    spaces = 4
    for line in xkml_lines:
        spaces = countLeadingSpaces(line)
        if spaces > 0:
            break

    # parse lines into nested dict
    root = {}
    trace = []  # as a stack
    indent = -1
    DIALOGS_MODE = False
    dialog_line_index = 0

    imports = {}

    for line in xkml_lines:
        # count indent level
        line_idt = countLeadingSpaces(line) // spaces
        if line_idt < indent:
            DIALOGS_MODE = False
            dialog_line_index = 0

        # extract kv pairs
        # the value of key-only lines
        # (to be nested with the next line)
        # is temporarily set to ''
        kv = line.split(':')
        k = kv[0].strip()

        # special cases for k
        NEXT_TIME_GO_INTO_DIALOGS_MODE = False
        # k is 'dialogs'
        if k == 'dialogs':
            # enter dialogs mode
            NEXT_TIME_GO_INTO_DIALOGS_MODE = True

        if not DIALOGS_MODE:
            # k is an int
            if k.isnumeric():
                k = int(k)
            v = ''

            # k is split with a designated delimiter
            v_delim = ''
            if k in KEYS_WITH_SPECIAL_VALUE_DELIMITERS:
                v_delim = KEYS_WITH_SPECIAL_VALUE_DELIMITERS[k]

            # k needs to be transformed
            if k in SPECIAL_KEY_TRANSFORMS:
                k = SPECIAL_KEY_TRANSFORMS[k]

            # the rest is v
            for substr in kv[1:]:
                v += substr + ':'

            v = v[:-1].strip()

            # v is a reference to an import
            if type(v) == str and v.startswith('$'):
                import_trace = v[1:].split('.')
                xkp_filename = root['import'][import_trace[0]]
                if xkp_filename not in imports:
                    # here it comes, recursive function
                    imports[xkp_filename] = parse(xkp_filename)
                v = getValueOrFallback(imports[xkp_filename], import_trace[1:],
                                       {})

            # v is a string in int/float format
            v = numberifyIfIsNumber(v)

            # v is interpreted as a tuple of ints
            if v_delim != '':
                v_split = v.split(v_delim)
                v_split_int = []
                for substr in v_split:
                    if substr != '':
                        v_split_int.append(int(substr.strip()))
                v = tuple(v_split_int)

        else:
            # dialogs mode
            k = dialog_line_index
            v = line.strip()
            dialog_line_index += 1

        # interpret escape chars in v, which is universal
        if type(v) == str:
            v = v.replace('\\n', '\n')

        # from change of indent level, determine trace
        if line_idt > indent:
            # indent advanced
            trace.append(k)
        elif line_idt == indent:
            # indent unchanged
            trace.pop()
            trace.append(k)
        elif line_idt < indent:
            # indent backed
            for _ in range(indent - line_idt + 1):
                trace.pop()
            trace.append(k)
        root = setProperty(root, trace, v)

        # update indent
        indent = line_idt

        if NEXT_TIME_GO_INTO_DIALOGS_MODE:
            DIALOGS_MODE = True
            NEXT_TIME_GO_INTO_DIALOGS_MODE = False
    return root