def replaceFromDict(dictFilePath, wrd): dictionary = enc.smart_unicode(getFileContent(dictFilePath)) dictionary = dictionary.replace('\r\n', '\n') p_reg = re.compile('^[^\r\n]+$', re.IGNORECASE + re.DOTALL + re.MULTILINE) m_reg = p_reg.findall(dictionary) word = enc.smart_unicode(wrd).replace(u'Ãœ', 'Ü').replace( u'Ö', 'Ö').replace(u'Ä', 'Ä') try: if m_reg and len(m_reg) > 0: index = '' words = [] newword = '' for m in m_reg: if not m.startswith(' '): index = m del words[:] else: replWord = m.strip() words.append(replWord) if word.find(' ') != -1: newword = word.replace(replWord, index) if (word in words) or (word == index): return index if newword != '' and newword != word: return newword except: common.log('Skipped Replacement: ' + word) return word
def replaceFromDict(dictFilePath, wrd): dictionary = enc.smart_unicode(getFileContent(dictFilePath)) dictionary = dictionary.replace('\r\n','\n') p_reg = re.compile('^[^\r\n]+$', re.IGNORECASE + re.DOTALL + re.MULTILINE) m_reg = p_reg.findall(dictionary) word = enc.smart_unicode(wrd).replace(u'Ãœ','Ü').replace(u'Ö','Ö').replace(u'Ä','Ä') try: if m_reg and len(m_reg) > 0: index = '' words = [] newword = '' for m in m_reg: if not m.startswith(' '): index = m del words[:] else: replWord = m.strip() words.append(replWord) if word.find(' ') != -1: newword = word.replace(replWord,index) if (word in words) or (word == index): return index if newword != '' and newword != word: return newword except: common.log('Skipped Replacement: ' + word) return word
def replace(params, src): src = enc.smart_unicode(src) paramArr = __parseParams(enc.smart_unicode(params)) paramstr = paramArr[0].replace('%s', src) paramSrch = paramArr[1] paramRepl = paramArr[2] return paramstr.replace(paramSrch, paramRepl)
def changeFanart(self, cfgFile, item, newFanart): if os.path.exists(cfgFile): fav = self._createFavourite(item) newfav = self._createFavourite(item, fanart=newFanart) old = fu.getFileContent(cfgFile) new = old.replace(enc.smart_unicode(fav).encode('utf-8'), enc.smart_unicode(newfav).encode('utf-8')) fu.setFileContent(cfgFile, new)
def replace(params, src): src = enc.smart_unicode(src) paramArr = __parseParams(enc.smart_unicode(params)) paramstr = paramArr[0].replace('%s', src) paramSrch = paramArr[1] paramRepl = paramArr[2] return paramstr.replace(paramSrch,paramRepl)
def getInfo(item, params, src): src = enc.smart_unicode(src).encode('utf-8') paramArr = __parseParams(params) paramPage = paramArr[0].replace('%s', src) if paramPage.startswith('@') and paramPage.endswith('@'): paramPage = item.getInfo(paramPage.strip('@')) paramRegex = paramArr[1].replace('%s', src) if paramRegex.startswith('@') and paramRegex.endswith('@'): paramRegex = item.getInfo(paramRegex.strip('@')) referer = '' form_data = '' variables=[] if len(paramArr) > 2: referer = paramArr[2] referer = referer.replace('%s', src) if referer.startswith('@') and referer.endswith('@'): referer = item.getInfo(referer.strip('@')) if len(paramArr) > 3: variables = paramArr[3].strip("'").split('|') common.log('Get Info from: "'+ paramPage + '" from "' + referer + '"') try: parts = (paramPage.split('|', 1) + [None] * 2)[:2] paramPage, form_data = parts form_data = urlparse.parse_qsl(form_data) except: pass data = common.getHTML(paramPage, form_data, referer, referer!='',demystify=True) return reg.parseText(data, paramRegex, variables)
def getInfo(item, params, src): src = enc.smart_unicode(src).encode('utf-8') paramArr = __parseParams(params) paramPage = paramArr[0].replace('%s', src) paramPage = urllib.unquote(paramPage) if paramPage.startswith('@') and paramPage.endswith('@'): paramPage = item.getInfo(paramPage.strip('@')) paramRegex = paramArr[1].replace('%s', src) if paramRegex.startswith('@') and paramRegex.endswith('@'): paramRegex = item.getInfo(paramRegex.strip('@')) referer = '' variables=[] if len(paramArr) > 2: referer = paramArr[2] referer = referer.replace('%s', src) if referer.startswith('@') and referer.endswith('@'): referer = item.getInfo(referer.strip('@')) if len(paramArr) > 3: variables = paramArr[3].strip("'").split('|') common.log('Get Info from: "'+ paramPage + '" from "' + referer + '"') data = common.getHTML(paramPage, referer, referer!='') return reg.parseText(data, paramRegex, variables)
def changeIcon(self, item, newIcon): found = self._findItem(item) if found: [cfgFile, data, fav] = found newfav = self._createFavourite(item, icon=newIcon) new = data.replace(fav, enc.smart_unicode(newfav).encode("utf-8")) fu.setFileContent(cfgFile, new)
def changeFanart(self, item, newFanart): found = self._findItem(item) if found: [cfgFile, data, fav] = found newfav = self._createFavourite(item, fanart=newFanart) new = data.replace(fav, enc.smart_unicode(newfav).encode('utf-8')) fu.setFileContent(cfgFile, new)
def changeLabel(self, item, newLabel): found = self._findItem(item) if found: item['title'] = newLabel [cfgFile, data, fav] = found # if it's a virtual folder, rename file, rename header, update link if self._isVirtualFolder(item): url = item.getInfo('url') oldFile = self._getFullPath(url) newFilename = urllib.quote_plus(fu.cleanFilename(newLabel)) virtualFolderFile = newFilename + '.cfg' physicalFolder = os.path.normpath(self._favouritesFoldersFolder) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) # check if new target is valid if os.path.exists(virtualFolderPath): prefix = newFilename + '-' suffix = '.cfg' virtualFolderFile = fu.randomFilename(directory=physicalFolder, prefix=prefix, suffix=suffix) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) # update header content = fu.getFileContent(oldFile) oldHeader = self.cfgBuilder.buildHeader(item['title']) newHeader = self.cfgBuilder.buildHeader(newLabel) content = content.replace(oldHeader, newHeader) # rename file self._removeVirtualFolder(oldFile, False) fu.setFileContent(virtualFolderPath, content) # update link item['url'] = self._getShortPath(virtualFolderPath) newfav = self._createFavourite(item) new = data.replace(fav, enc.smart_unicode(newfav).encode('utf-8')) fu.setFileContent(cfgFile, new)
def moveToFolder(self, cfgFile, item, newCfgFile): if os.path.exists(cfgFile) and os.path.exists(newCfgFile): fav = self._createFavourite(item) old = fu.getFileContent(cfgFile) new = old.replace(enc.smart_unicode(fav).encode('utf-8'),'') fu.setFileContent(cfgFile, new) fu.appendFileContent(newCfgFile, fav)
def getInfo(item, params, src): src = enc.smart_unicode(src).encode('utf-8') paramArr = __parseParams(params) paramPage = paramArr[0].replace('%s', src) paramPage = urllib.unquote(paramPage) if paramPage.startswith('@') and paramPage.endswith('@'): paramPage = item.getInfo(paramPage.strip('@')) paramRegex = paramArr[1].replace('%s', src) if paramRegex.startswith('@') and paramRegex.endswith('@'): paramRegex = item.getInfo(paramRegex.strip('@')) referer = '' form_data = '' variables=[] if len(paramArr) > 2: referer = paramArr[2] referer = referer.replace('%s', src) if referer.startswith('@') and referer.endswith('@'): referer = item.getInfo(referer.strip('@')) if len(paramArr) > 3: variables = paramArr[3].strip("'").split('|') common.log('Get Info from: "'+ paramPage + '" from "' + referer + '"') try: parts = (paramPage.split('|', 1) + [None] * 2)[:2] paramPage, form_data = parts form_data = urlparse.parse_qsl(form_data) except: pass data = common.getHTML(paramPage, form_data, referer, referer!='',demystify=True) return reg.parseText(data, paramRegex, variables)
def codeUrl(item): params = '' for info_name in item.infos_names: if info_name != 'url' and info_name.find('.tmp') == -1: info_value = item[info_name] try: value = urllib.quote(enc.smart_unicode(info_value).encode('utf-8')) except: value = enc.smart_unicode(info_value) keyValPair = enc.smart_unicode(info_name) + ':' + value params += '&' + keyValPair try: url = enc.smart_unicode(urllib.quote_plus(item['url'])) except: url = item['url'] params += '&url:' + url return params.lstrip('&')
def parseText(params, src): src = enc.smart_unicode(src) paramArr = __parseParams(params) text = paramArr[0].replace('%s',src) regex = paramArr[1].replace('%s', src) variables = [] if len(paramArr) > 2: variables = paramArr[2].split('|') return reg.parseText(text, regex, variables)
def buildItem(self, title, m_type, url, icon=None, fanart=None, cfg=None): sepLine = self.buildSeperator(title) data = ["\n" + sepLine, "title=" + enc.smart_unicode(title), "type=" + m_type] if icon: data.append("icon=" + icon) if fanart: data.append("fanart=" + fanart) if cfg: data.append("cfg=" + cfg) data.append("url=" + url) return "\n".join(data)
def buildItem(self, title, m_type, url, icon=None, fanart=None, cfg=None): sepLine = self.buildSeperator(title) data = [ '\n' + sepLine, 'title=' + enc.smart_unicode(title), 'type=' + m_type ] if icon: data.append('icon=' + icon) if fanart: data.append('fanart=' + fanart) if cfg: data.append('cfg=' + cfg) data.append('url=' + url) return '\n'.join(data)
def replaceRegex(params, src): src = enc.smart_unicode(src) paramArr = __parseParams(params) paramStr = paramArr[0].replace('%s', src) paramSrch = paramArr[1] paramRepl = paramArr[2] r = re.compile(paramSrch, re.DOTALL + re.IGNORECASE) ms = r.findall(paramStr) if ms: for m in ms: paramStr = paramStr.replace(m, paramRepl, 1) return paramStr return src
def replaceRegex(params, src): src = enc.smart_unicode(src) paramArr = __parseParams(params) paramStr = paramArr[0].replace('%s', src) paramSrch = paramArr[1] paramRepl = paramArr[2] r = re.compile(paramSrch, re.DOTALL + re.IGNORECASE) ms = r.findall(paramStr) if ms: for m in ms: paramStr = paramStr.replace(m, paramRepl,1) return paramStr return src
def removeItem(self, item): cfgFile = self._favouritesFile definedIn = item.getInfo('definedIn') if definedIn and definedIn.startswith('favfolders/'): cfgFile = os.path.join(self._favouritesFoldersFolder, definedIn.split('/')[1]) if os.path.exists(cfgFile): fav = self._createFavourite(item) old = fu.getFileContent(cfgFile) new = old.replace(enc.smart_unicode(fav).encode('utf-8'),'') fu.setFileContent(cfgFile, new) # delete virtual folder if self._isVirtualFolder(item): self._removeVirtualFolder(item)
def changeLabel(self, cfgFile, item, newLabel): if os.path.exists(cfgFile): oldfav = self._createFavourite(item) old = fu.getFileContent(cfgFile) # if it's a virtual folder, change target url too; check if target already exists; rename target # (helpful, if you want to edit files manually) if self._isVirtualFolder(item): url = item.getInfo('url') oldTargetFile = os.path.join(self._favouritesFoldersFolder, url.split('/')[1]) # check if new target is valid newTargetFile = os.path.join(self._favouritesFoldersFolder, urllib.quote_plus(newLabel) + '.cfg') if os.path.exists(newTargetFile): common.showInfo('Folder already exists') return # rename target os.rename(oldTargetFile, newTargetFile) # update target url item.setInfo('url', 'favfolders/' + urllib.quote_plus(newLabel) + '.cfg') newfav = self._createFavourite(item, title=newLabel) new = old.replace(enc.smart_unicode(oldfav).encode('utf-8'), enc.smart_unicode(newfav).encode('utf-8')) fu.setFileContent(cfgFile, new)
def parseText(item, params, src): src = enc.smart_unicode(src) paramArr = __parseParams(params) text = paramArr[0].replace('%s', src) if text.startswith('@') and text.endswith('@'): text = item.getInfo(text.strip('@')) regex = paramArr[1].replace('%s', src) if regex.startswith('@') and regex.endswith('@'): regex = item.getInfo(regex.strip('@')) variables = [] if len(paramArr) > 2: variables = paramArr[2].split('|') return reg.parseText(text, regex, variables)
def parseText(item, params, src): src = enc.smart_unicode(src) paramArr = __parseParams(params) text = paramArr[0].replace('%s',src) if text.startswith('@') and text.endswith('@'): text = item.getInfo(text.strip('@')) regex = paramArr[1].replace('%s', src) if regex.startswith('@') and regex.endswith('@'): regex = item.getInfo(regex.strip('@')) variables = [] if len(paramArr) > 2: variables = paramArr[2].split('|') return reg.parseText(text, regex, variables)
def getInfo(item, params, src, xml=False): src = enc.smart_unicode(src).encode('utf-8') paramArr = __parseParams(params) paramPage = paramArr[0].replace('%s', src) if paramPage.startswith('@') and paramPage.endswith('@'): paramPage = item.getInfo(paramPage.strip('@')) paramRegex = paramArr[1].replace('%s', src) if paramRegex.startswith('@') and paramRegex.endswith('@'): paramRegex = item.getInfo(paramRegex.strip('@')) referer = '' form_data = '' variables=[] if len(paramArr) > 2: referer = paramArr[2] referer = referer.replace('%s', src) if referer.startswith('@') and referer.endswith('@'): referer = item.getInfo(referer.strip('@')) if len(paramArr) > 3: variables = paramArr[3].strip("'").split('|') parsed_link = urlparse.urlsplit(referer) parsed_link = parsed_link._replace(netloc=parsed_link.netloc.encode('idna'),path=urllib.quote(parsed_link.path.encode('utf-8'))) referer = parsed_link.geturl().encode('utf-8') try: parts = (paramPage.split('|', 1) + [None] * 2)[:2] paramPage, form_data = parts form_data = urlparse.parse_qsl(form_data) except: pass common.log('Get Info from: "'+ paramPage + '" from "' + referer + '"') data = common.getHTML(paramPage, form_data, referer, xml, ignoreCache=False,demystify=True) return reg.parseText(data, paramRegex, variables)
def changeLabel(self, item, newLabel): found = self._findItem(item) if found: item['title'] = newLabel [cfgFile, data, fav] = found # if it's a virtual folder, rename file, rename header, update link if self._isVirtualFolder(item): url = item.getInfo('url') oldFile = self._getFullPath(url) newFilename = urllib.quote_plus(fu.cleanFilename(newLabel)) virtualFolderFile = newFilename + '.cfg' physicalFolder = os.path.normpath( self._favouritesFoldersFolder) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) # check if new target is valid if os.path.exists(virtualFolderPath): prefix = newFilename + '-' suffix = '.cfg' virtualFolderFile = fu.randomFilename( directory=physicalFolder, prefix=prefix, suffix=suffix) virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile) # update header content = fu.getFileContent(oldFile) oldHeader = self.cfgBuilder.buildHeader(item['title']) newHeader = self.cfgBuilder.buildHeader(newLabel) content = content.replace(oldHeader, newHeader) # rename file self._removeVirtualFolder(oldFile, False) fu.setFileContent(virtualFolderPath, content) # update link item['url'] = self._getShortPath(virtualFolderPath) newfav = self._createFavourite(item) new = data.replace(fav, enc.smart_unicode(newfav).encode('utf-8')) fu.setFileContent(cfgFile, new)
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 try: src = src.encode("utf-8") except: pass 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 == "select": src = cc.select(params, src) if not src: continue elif command == "smart_unicode": src = enc.smart_unicode(params.strip("'").replace("%s", src)) elif command == "safeGerman": src = enc.safeGerman(src) elif command == "safeRegex": src = enc.safeRegexEncoding(params.strip("'").replace("%s", enc.smart_unicode(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 == "getRedirect": src = get_redirected_url(params.strip("'").replace("%s", src)) elif command == "quote": try: src = urllib.quote(params.strip("'").replace("%s", urllib.quote(src))) except: cleanParams = params.strip("'") cleanParams = cleanParams.replace("%s", src.encode("utf-8")) src = urllib.quote(cleanParams) 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 == "decodeBase64": src = cc.decodeBase64(src) elif command == "decodeRawUnicode": src = cc.decodeRawUnicode(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 == "destreamer": src = crypt.destreamer(params.strip("'").replace("%s", src)) elif command == "unixTimestamp": src = dt.getUnixTimestamp() elif command == "urlMerge": src = cc.urlMerge(params, src) elif command == "translate": try: src = common.translate(int(src)) except: pass elif command == "camelcase": src = enc.smart_unicode(src) src = string.capwords(string.capwords(src, "-")) elif command == "demystify": print "demystify" src = crypt.doDemystify(src) print "after demystify", 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 == "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
def __parseHtml(self, url, data, rules, skills, definedIn, lItem): #common.log('_parseHtml called') items = [] for item_rule in rules: # common.log('rule: ' + item_rule.infos) if not hasattr(item_rule, 'precheck') or (item_rule.precheck in data): revid = re.compile(item_rule.infos, re.IGNORECASE + re.DOTALL + re.MULTILINE) for reinfos in revid.findall(data): tmp = CListItem() if lItem['referer']: tmp['referer'] = lItem['referer'] if item_rule.order.find('|') != -1: infos_names = item_rule.order.split('|') infos_values = list(reinfos) i = 0 for name in infos_names: tmp[name] = infos_values[i] i = i+1 else: tmp[item_rule.order] = reinfos for info in item_rule.info_list: info_value = tmp[info.name] if info_value: if info.build.find('%s') != -1: tmpVal = enc.smart_unicode(info.build % enc.smart_unicode(info_value)) tmp[info.name] = tmpVal continue if info.build.find('%s') != -1: if info.src.__contains__('+'): tmpArr = info.src.split('+') src = '' for t in tmpArr: t = t.strip() if t.find('\'') != -1: src = src + t.strip('\'') else: src = src + enc.smart_unicode(tmp[t]) elif info.src.__contains__('||'): variables = info.src.split('||') src = firstNonEmpty(tmp, variables) else: src = tmp[info.src] if src and info.convert != []: src = self.__parseCommands(tmp, src, info.convert) if isinstance(src, dict): for dKey in src: tmp[dKey] = src[dKey] src = src.values()[0] info_value = info.build % (enc.smart_unicode(src)) else: info_value = info.build tmp[info.name] = info_value tmp['url'] = enc.smart_unicode(item_rule.url_build % (enc.smart_unicode(tmp['url']))) tmp.merge(lItem) if item_rule.skill.find('append') != -1: tmp['url'] = url + tmp['url'] if item_rule.skill.find('space') != -1: tmp['title'] = ' %s ' % tmp['title'].strip() if skills.find('videoTitle') > -1: tmp['videoTitle'] = tmp['title'] tmp['definedIn'] = definedIn items.append(tmp) return items
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 try: src = src.encode('utf-8') except: pass 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 == 'select': src = cc.select(params, src) if not src: continue elif command == 'smart_unicode': src = enc.smart_unicode(params.strip("'").replace('%s', src)) elif command == 'safeGerman': src = enc.safeGerman(src) elif command == 'safeRegex': src = enc.safeRegexEncoding(params.strip("'").replace('%s', enc.smart_unicode(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 == 'getRedirect': src = get_redirected_url(params.strip("'").replace('%s', src)) elif command == 'quote': try: src = urllib.quote(params.strip("'").replace('%s', urllib.quote(src))) except: cleanParams = params.strip("'") cleanParams = cleanParams.replace("%s",src.encode('utf-8')) src = urllib.quote(cleanParams) 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 == 'decodeBase64': src = cc.decodeBase64(src) elif command == 'decodeRawUnicode': src = cc.decodeRawUnicode(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 == 'destreamer': src = crypt.destreamer(params.strip("'").replace('%s', src)) elif command == 'unixTimestamp': src = dt.getUnixTimestamp() elif command == 'urlMerge': src = cc.urlMerge(params, src) elif command == 'translate': try: src = common.translate(int(src)) except: pass elif command == 'camelcase': src = enc.smart_unicode(src) src = string.capwords(string.capwords(src, '-')) elif command == 'demystify': print 'demystify' src = crypt.doDemystify(src) print 'after demystify',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 == '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
def __parseHtml(self, url, data, rules, skills, definedIn, lItem): #common.log('_parseHtml called') items = [] for item_rule in rules: # common.log('rule: ' + item_rule.infos) if not hasattr(item_rule, 'precheck') or (item_rule.precheck in data): revid = re.compile(item_rule.infos, re.IGNORECASE + re.DOTALL + re.MULTILINE) for reinfos in revid.findall(data): tmp = CListItem() if lItem['referer']: tmp['referer'] = lItem['referer'] if item_rule.order.find('|') != -1: infos_names = item_rule.order.split('|') infos_values = list(reinfos) i = 0 for name in infos_names: tmp[name] = infos_values[i] i = i + 1 else: tmp[item_rule.order] = reinfos for info in item_rule.info_list: info_value = tmp[info.name] if info_value: if info.build.find('%s') != -1: tmpVal = enc.smart_unicode( info.build % enc.smart_unicode(info_value)) tmp[info.name] = tmpVal continue if info.build.find('%s') != -1: if info.src.__contains__('+'): tmpArr = info.src.split('+') src = '' for t in tmpArr: t = t.strip() if t.find('\'') != -1: src = src + t.strip('\'') else: src = src + enc.smart_unicode(tmp[t]) elif info.src.__contains__('||'): variables = info.src.split('||') src = firstNonEmpty(tmp, variables) else: src = tmp[info.src] if src and info.convert != []: src = self.__parseCommands( tmp, src, info.convert) if isinstance(src, dict): for dKey in src: tmp[dKey] = src[dKey] src = src.values()[0] info_value = info.build % (enc.smart_unicode(src)) else: info_value = info.build tmp[info.name] = info_value tmp['url'] = enc.smart_unicode( item_rule.url_build % (enc.smart_unicode(tmp['url']))) tmp.merge(lItem) if item_rule.skill.find('append') != -1: tmp['url'] = url + tmp['url'] if item_rule.skill.find('space') != -1: tmp['title'] = ' %s ' % tmp['title'].strip() if skills.find('videoTitle') > -1: tmp['videoTitle'] = tmp['title'] tmp['definedIn'] = definedIn items.append(tmp) return items
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 try: src = src.encode('utf-8') except: pass 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 == 'select': src = cc.select(params, src) if not src: continue elif command == 'smart_unicode': src = enc.smart_unicode(params.strip("'").replace('%s', src)) elif command == 'safeGerman': src = enc.safeGerman(src) elif command == 'safeRegex': src = enc.safeRegexEncoding( params.strip("'").replace('%s', enc.smart_unicode(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 == 'getRedirect': src = get_redirected_url(params.strip("'").replace('%s', src)) elif command == 'quote': try: src = urllib.quote( params.strip("'").replace('%s', urllib.quote(src))) except: cleanParams = params.strip("'") cleanParams = cleanParams.replace("%s", src.encode('utf-8')) src = urllib.quote(cleanParams) 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 == 'decodeBase64': src = cc.decodeBase64(src) elif command == 'decodeRawUnicode': src = cc.decodeRawUnicode(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 == 'destreamer': src = crypt.destreamer(params.strip("'").replace('%s', src)) elif command == 'unixTimestamp': src = dt.getUnixTimestamp() elif command == 'urlMerge': src = cc.urlMerge(params, src) elif command == 'translate': try: src = common.translate(int(src)) except: pass elif command == 'camelcase': src = enc.smart_unicode(src) src = string.capwords(string.capwords(src, '-')) elif command == 'demystify': print 'demystify' src = crypt.doDemystify(src) print 'after demystify', 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 == '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