def __parseCommands(self, item, src, convCommands):
        common.log('_parseCommands called')
        # helping function
        def parseCommand(txt):
            command = {"command": txt, "params": ""}
            if txt.find("(") > -1:
                command["command"] = txt[0:txt.find("(")]
                command["params"] = txt[len(command["command"]) + 1:-1]
            return command
        
        for convCommand in convCommands:
            pComm = parseCommand(convCommand)
            command = pComm["command"]
            params = pComm["params"]

            if params.find('@REFERER@'):
                referer = item['referer']
                if not referer:
                    referer = ''
                params = params.replace('@REFERER@', referer)

            if command == 'convDate':
                src = cc.convDate(params, src)

            elif command == 'convTimestamp':
                src = cc.convTimestamp(params, src)
                
            elif command == 'convDateUtil':
                src = cc.convDateUtil(params, src)

            elif command == 'select':
                src = cc.select(params, src)
                if not src:
                    continue

            elif command == 'unicode_escape':
                src = src.decode('unicode-escape')

            elif command == 'replaceFromDict':
                dictName = str(params.strip('\''))
                path = os.path.join(common.Paths.dictsDir, dictName + '.txt')
                if not (os.path.exists(path)):
                    common.log('Dictionary file not found: ' + path)
                    continue
                src = cc.replaceFromDict(path, src)

            elif command == 'time':
                src = time.time()

            elif command == 'timediff':
                src = dt.timediff(src,params.strip('\''))

            elif command == 'offset':
                src = cc.offset(params, src)

            elif command == 'getSource':
                src = cc.getSource(params, src)

            elif command == 'quote':
                try:
                    src = urllib.quote(params.strip("'").replace('%s', src),'')
                except:
                    cleanParams = params.strip("'")
                    cleanParams = cleanParams.replace("%s",src)
                    src = urllib.quote(cleanParams.encode('utf-8'),'')

            elif command == 'unquote':
                src = urllib.unquote(params.strip("'").replace('%s', src))

            elif command == 'parseText':
                src = cc.parseText(item, params, src)

            elif command == 'getInfo':
                src = cc.getInfo(item, params, src)
            
            elif command == 'getXML':
                src = cc.getInfo(item, params, src, xml=True)
                
            elif command == 'getMobile':
                src = cc.getInfo(item, params, src, mobile=True)

            elif command == 'decodeBase64':
                src = cc.decodeBase64(src)
            
            elif command == 'encodeBase64':
                src = cc.encodeBase64(src)

            elif command == 'decodeRawUnicode':
                src = cc.decodeRawUnicode(src)
                
            elif command == 'resolve':
                src = cc.resolve(src)
            
            elif command == 'decodeXppod':
                src = cc.decodeXppod(src)
            
            elif command == 'decodeXppodHLS':
                if 'stkey' in item.infos:
                    src = src.replace(item.infos['stkey'],'')
                src = cc.decodeXppod_hls(src)

            elif command == 'replace':
                src = cc.replace(params, src)

            elif command == 'replaceRegex':
                src = cc.replaceRegex(params, src)

            elif command == 'ifEmpty':
                src = cc.ifEmpty(item, params, src)

            elif command == 'isEqual':
                src = cc.isEqual(item, params, src)

            elif command == 'ifFileExists':
                src = cc.ifFileExists(item, params, src)

            elif command == 'ifExists':
                src = cc.ifExists(item, params, src)

            elif command == 'encryptJimey':
                src = crypt.encryptJimey(params.strip("'").replace('%s', src))

            elif command == 'gAesDec':
                src = crypt.gAesDec(src,item.infos[params])
                
            elif command == 'cjsAesDec':
                src = crypt.cjsAesDec(src,item.infos[params])
                
            elif command == 'm3u8AesDec':
                src = crypt.m3u8AesDec(src,item.infos[params])

            elif command == 'drenchDec':
                src = crypt.drenchDec(src,item.infos[params])
                
            elif command == 'onetv':
                src = crypt.onetv(src)

            elif command == 'getCookies':
                src = cc.getCookies(params, src)

            elif command == 'destreamer':
                src = crypt.destreamer(params.strip("'").replace('%s', src))

            elif command == 'unixTimestamp':
                src = dt.getUnixTimestamp()
                
            elif command == 'rowbalance':
                src = rb.get(src)
                
            elif command == 'simpleToken':
                src = cc.simpleToken(src)

            elif command == 'urlMerge':
                src = cc.urlMerge(params, src)

            elif command == 'translate':
                try:
                    src = common.translate(int(src))
                except:
                    pass

            elif command == 'camelcase':
                src = string.capwords(string.capwords(src, '-'))
                
            elif command == 'lowercase':
                src = string.lower(src)
                
            elif command == 'reverse':
                src = src[::-1]
                
            elif command == 'demystify':
                src = crypt.doDemystify(src)

            elif command == 'random':
                paramArr = params.split(',')
                minimum = int(paramArr[0])
                maximum = int(paramArr[1])
                src = str(random.randrange(minimum,maximum))

            elif command == 'debug':
                common.log('Debug from cfg file: ' + src)
                
            elif command == 'startLivestreamerProxy':
                libPath = os.path.join(common.Paths.rootDir, 'lib')
                serverPath = os.path.join(libPath, 'livestreamerXBMCLocalProxy.py')
                try:
                    import requests
                    requests.get('http://127.0.0.1:19000/version')
                    proxyIsRunning = True
                except:
                    proxyIsRunning = False
                if not proxyIsRunning:
                    xbmc.executebuiltin('RunScript(' + serverPath + ')')
                
            elif command == 'divide':
                paramArr = params.split(',')
                a = paramArr[0].strip().strip("'").replace('%s', src)
                a = resolveVariable(a, item)
                b = paramArr[1].strip().strip("'").replace('%s', src)
                b = resolveVariable(b, item)
                
                if not a or not b:
                    continue
                
                a = int(a)
                b = int(b)
                try:
                    src = str(a/b)
                except:
                    pass
                
        return src
Exemple #2
0
    def __parseCommands(self, item, src, convCommands):
        common.log('_parseCommands called ')

        # helping function
        def parseCommand(txt):
            command = {"command": txt, "params": ""}
            if txt.find("(") > -1:
                command["command"] = txt[0:txt.find("(")]
                command["params"] = txt[len(command["command"]) + 1:-1]
            return command

        for convCommand in convCommands:
            pComm = parseCommand(convCommand)
            command = pComm["command"]
            params = pComm["params"]

            if params.find('@REFERER@'):
                referer = item['referer']
                if not referer:
                    referer = ''
                params = params.replace('@REFERER@', referer)

            if command == 'convDate':
                src = cc.convDate(params, src)

            elif command == 'convTimestamp':
                src = cc.convTimestamp(params, src)

            elif command == 'convDateUtil':
                src = cc.convDateUtil(params, src)

            elif command == 'select':
                src = cc.select(params, src)
                if not src:
                    continue

            elif command == 'unicode_escape':
                try:
                    src = src.decode('unicode-escape')
                except:
                    src = src

            elif command == 'replaceFromDict':
                dictName = str(params.strip('\''))
                path = os.path.join(common.Paths.dictsDir, dictName + '.txt')
                if not (os.path.exists(path)):
                    common.log('Dictionary file not found: ' + path)
                    continue
                src = cc.replaceFromDict(path, src)

            elif command == 'time':
                src = time.time()

            elif command == 'timediff':
                src = dt.timediff(src, params.strip('\''))

            elif command == 'offset':
                src = cc.offset(params, src)

            elif command == 'getSource':
                src = cc.getSource(params, src)

            elif command == 'quote':
                try:
                    src = urllib.quote(
                        params.strip("'").replace('%s', src), '')
                except:
                    cleanParams = params.strip("'")
                    cleanParams = cleanParams.replace("%s", src)
                    src = urllib.quote(cleanParams.encode('utf-8'), '')

            elif command == 'unquote':
                src = urllib.unquote(params.strip("'").replace('%s', src))

            elif command == 'parseText':
                src = cc.parseText(item, params, src)

            elif command == 'getInfo':
                src = cc.getInfo(item, params, src)

            elif command == 'getXML':
                src = cc.getInfo(item, params, src, xml=True)

            elif command == 'getMobile':
                src = cc.getInfo(item, params, src, mobile=True)

            elif command == 'decodeBase64':
                src = cc.decodeBase64(src)

            elif command == 'decodeBase64Special':
                src = cc.decodeBase64Special(params, src)

            elif command == 'encodeBase64':
                src = cc.encodeBase64(src)

            elif command == 'decodeRawUnicode':
                src = cc.decodeRawUnicode(src)

            elif command == 'decodeHex':
                src = cc.hex2ascii(src)

            elif command == 'resolve':
                src = cc.resolve(src)

            elif command == 'decodeXppod':
                src = cc.decodeXppod(src)

            elif command == 'decodeXppodHLS':
                if 'stkey' in item.infos:
                    src = src.replace(item.infos['stkey'], '')
                src = cc.decodeXppod_hls(src)

            elif command == 'decodeBCast':
                src = cc.bcast64(src)

            elif command == 'replace':
                src = cc.replace(item, params, src)

            elif command == 'replaceRegex':
                src = cc.replaceRegex(item, params, src)

            elif command == 'subRegex':
                src = cc.subRegex(item, params, src)

            elif command == 'ifEmpty':
                src = cc.ifEmpty(item, params, src)

            elif command == 'ifContains':
                src = cc.ifContains(item, params, src)

            elif command == 'isEqual':
                src = cc.isEqual(item, params, src)

            elif command == 'ifFileExists':
                src = cc.ifFileExists(item, params, src)

            elif command == 'ifExists':
                src = cc.ifExists(item, params, src)

            elif command == 'encryptJimey':
                src = crypt.encryptJimey(params.strip("'").replace('%s', src))

            elif command == 'gAesDec':
                src = crypt.gAesDec(src, item.infos[params])

            elif command == 'cjsAesDec':
                src = crypt.cjsAesDec(src, item.infos[params])

            elif command == 'jsCryptoAESDec':
                src = crypt.jsCryptoAESDec(src, item.infos[params])

            elif command == 'decryptMarioCS':
                src = crypt.decryptMarioCS(src, item.infos[params])

            elif command == 'm3u8AesDec':
                src = crypt.m3u8AesDec(src, item.infos[params])

            elif command == 'drenchDec':
                src = crypt.drenchDec(src, item.infos[params])

            elif command == 'onetv':
                src = crypt.onetv(src)

            elif command == 'getCookies':
                src = cc.getCookies(params, src)

            elif command == 'destreamer':
                src = crypt.destreamer(params.strip("'").replace('%s', src))

            elif command == 'unixTimestamp':
                src = dt.getUnixTimestamp()

            elif command == 'rowbalance':
                src = rb.get(src)

            elif command == 'simpleToken':
                src = cc.simpleToken(src)

            #elif command == 'wasteg':
            #    paramArr = params.split(',')
            #    ref = str(paramArr[1])
            #    src = getsaw.compose(ref, src)

            elif command == 'saurusDec':
                src = crypt.decryptSaurus(src)

            elif command == 'urlMerge':
                src = cc.urlMerge(params, src)

            elif command == 'translate':
                try:
                    src = common.translate(int(src))
                except:
                    pass

            elif command == 'camelcase':
                src = string.capwords(string.capwords(src, '-'))

            elif command == 'lowercase':
                src = string.lower(src)

            elif command == 'reverse':
                src = src[::-1]

            elif command == 'demystify':
                src = crypt.doDemystify(src)

            elif command == 'random':
                paramArr = params.split(',')
                minimum = int(paramArr[0])
                maximum = int(paramArr[1])
                src = str(random.randrange(minimum, maximum))

            elif command == 'randomfloat':
                paramArr = params.split(',')
                minimum = float(paramArr[0])
                maximum = float(paramArr[1])
                src = str(random.uniform(minimum, maximum))

            elif command == 'debug':
                common.log('Debug from cfg file: ' + src)

            # elif command == 'startLivestreamerProxy':
            #     libPath = os.path.join(common.Paths.rootDir, 'lib')
            #     serverPath = os.path.join(libPath, 'livestreamerXBMCLocalProxy.py')
            #     try:
            #         import requests
            #         requests.get('http://127.0.0.1:19000/version')
            #         proxyIsRunning = True
            #     except:
            #         proxyIsRunning = False
            #     if not proxyIsRunning:
            #         xbmc.executebuiltin('RunScript(' + serverPath + ')')

            # elif command == 'startLivestreamerProxy':
            #     libPath = os.path.join(common.Paths.rootDir, 'service')
            #     serverPath = os.path.join(libPath, 'livestreamerXBMCLocalProxy.py')
            #     try:
            #         import requests
            #         requests.get('http://127.0.0.1:19000/version')
            #         proxyIsRunning = True
            #     except:
            #         proxyIsRunning = False
            #     if not proxyIsRunning:
            #         xbmc.executebuiltin('RunScript(' + serverPath + ')')
            #xbmc.sleep(500)
            #     common.log('Debug from cfg file: ' + requests.get('http://127.0.0.1:19001/version').text)

            elif command == 'divide':
                paramArr = params.split(',')
                a = paramArr[0].strip().strip("'").replace('%s', src)
                a = resolveVariable(a, item)
                b = paramArr[1].strip().strip("'").replace('%s', src)
                b = resolveVariable(b, item)

                if not a or not b:
                    continue

                a = int(a)
                b = int(b)
                try:
                    src = str(a / b)
                except:
                    pass

        return src