def decryptSignatures(self, encSignatures, playerUrl): decSignatures = [] code = '' jsname = 'ytsigndec' jshash = 'hash7_' + playerUrl.split('://', 1)[-1] if not is_js_cached(jsname, jshash): # get main function sts, self.playerData = self.cm.getPage(playerUrl) if not sts: return [] t1 = time.time() code = [] mainFunctionName = self._findMainFunctionName() if not mainFunctionName: SetIPTVPlayerLastHostError( _('Encryption function name extraction failed!\nPlease report the problem to %s' ) % 'https://github.com/persianpros/e2iplayer/issues') return [] printDBG("mainFunctionName >> %s" % mainFunctionName) mainFunction = self._findFunction(mainFunctionName) if not mainFunction: SetIPTVPlayerLastHostError( _('Encryption function body extraction failed!\nPlease report the problem to %s' ) % 'https://github.com/persianpros/e2iplayer/issues') return [] code.append(mainFunction) funNames = self._getAllLocalSubFunNames(mainFunction) for funName in funNames: fun = self._findFunction(funName) code.insert(0, fun) objects = self._getAllObjectsWithMethods(mainFunction) for objName, methods in objects.iteritems(): obj = self._findObject(objName, methods) code.insert(0, obj) code.append( 'e2i_dec=[];for (var idx in e2i_enc){e2i_dec.push(%s(e2i_enc[idx]));};print(JSON.stringify(e2i_dec));' % mainFunctionName) code = '\n'.join(code) printDBG("---------------------------------------") printDBG("| ALGO FOR SIGNATURE DECRYPTION |") printDBG("---------------------------------------") printDBG(code) printDBG("---------------------------------------") else: printDBG("USE ALGO FROM CACHE: %s" % jshash) js_params = [{'code': 'e2i_enc = %s;' % json_dumps(encSignatures)}] js_params.append({'name': jsname, 'code': code, 'hash': jshash}) ret = js_execute_ext(js_params) if ret['sts'] and 0 == ret['code']: try: decSignatures = json_loads(ret['data']) except Exception: printExc() return decSignatures
def listSearchResult(self, cItem, searchPattern, searchType): printDBG("CartoonHD.listSearchResult cItem[%s], searchPattern[%s] searchType[%s]" % (cItem, searchPattern, searchType)) sts, data = self.cm.getPage(self.MAIN_URL, self.defaultParams) if not sts: return vars = self.cm.ph.getDataBeetwenMarkers(data, 'var ', '</script>')[1] if vars == '': return vars = vars[:-9] jsUrl = self.getFullUrl(self.cm.ph.getSearchGroups(data, '''<script[^>]+?src=['"]([^'^"]*?foxycomplete.js[^'^"]*?)['"]''')[0]) if not self.cm.isValidUrl(jsUrl): return jsHash = jsUrl.rsplit('=', 1)[-1] js_execute_ext, is_js_cached if not is_js_cached('cartoonhd', jsHash): sts, jsdata = self.cm.getPage(jsUrl, self.defaultParams) if not sts: return else: jsdata = '' post_data = {'q':searchPattern, 'limit':100, 'timestamp':str(int(time.time()*1000))} try: js_params = [{'path':GetJSScriptFile('cartoonhd.byte')}] js_params.append({'code':vars}) js_params.append({'name':'cartoonhd', 'hash':jsHash, 'code':jsdata}) ret = js_execute_ext( js_params ) if ret['sts'] and 0 == ret['code']: decoded = ret['data'].strip() printDBG('DECODED DATA -> [%s]' % decoded) decoded = json_loads(decoded) self.SEARCH_URL = decoded.pop('url', None) post_data.update(decoded) except Exception: printExc() httpParams = dict(self.defaultParams) httpParams['header'] = {'Referer':self.MAIN_URL, 'User-Agent':self.cm.HOST, 'X-Requested-With':'XMLHttpRequest', 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'} sts, data = self.cm.getPage(self.SEARCH_URL, httpParams, post_data=post_data) if not sts: return printDBG(data) try: data = json_loads(data) for item in data: desc = item['meta'] if 'movie' in desc.lower(): category = 'explore_item' elif 'tv show' in desc.lower(): category = 'list_seasons' else: category = None if None != category: title = item['title'] url = item['permalink'].replace('\\/', '/') icon = item.get('image', '').replace('\\/', '/') if '' != url: params = {'good_for_fav':True, 'name':'category', 'title':title, 'url':self.getFullUrl(url), 'desc':desc, 'icon':self.getFullUrl(icon), 'category':category} if category == 'explore_item': self.addVideo(params) else: self.addDir(params) except Exception: printExc()
def _getLinks(self, cUrl, data): linksTab = [] ad = self.cm.ph.getSearchGroups( data, '''var\s+?ad\s*?=\s*?['"]([^'^"]+?)['"]''', 1, True)[0] tmp = re.compile( '''<script[^>]+?src=['"]([^'^"]*?(?:view|providers)[^'^"]*?\.js(?:\?[^'^"]*?)?)['"]''', re.I).findall(data) tabJs = {} for item in tmp: version = item.split('?', 1)[-1] if 'providers' in item: tabJs['providers'] = { 'url': self.getFullUrl(item), 'hash': version + '.1' } elif 'view' in item: tabJs['view'] = { 'url': self.getFullUrl(item), 'hash': version + '.1' } for key in tabJs.iterkeys(): tabJs[key]['name'] = 'hdfull.me_%s' % key if not is_js_cached(tabJs[key]['name'], tabJs[key]['hash']): sts, jsdata = self.getPage(tabJs[key]['url']) if sts: if 'providers' == key: idx1 = jsdata.find('providers') idx2 = jsdata.find(';', idx1 + 9) funName = self.cm.ph.getSearchGroups( jsdata[idx2 + 1:], '''function\s+?([^\(]+?)\(''')[0] tabJs[key][ 'code'] = 'function buildIframeEmbed(){return arguments[0];}\nbuildIframeGenericEmbed=buildIframeEmbed;\n' + jsdata[:idx2 + 1] + '; function %s(){return function(){};}' % funName printDBG(">>>>") printDBG(tabJs[key]['code']) printDBG("<<<<") else: tmp = [ 'window=this,window.atob=function(e){e.length%4==3&&(e+="="),e.length%4==2&&(e+="=="),e=Duktape.dec("base64",e),decText="";for(var t=0;t<e.byteLength;t++)decText+=String.fromCharCode(e[t]);return decText};' ] start = 0 while True: idx1 = jsdata.find('String.prototype.', start) if idx1 < 0: break idx2 = jsdata.find('{', idx1 + 17) if idx2 < 0: break num = 1 while num > 0: idx2 += 1 if idx2 >= len(jsdata): break if jsdata[idx2] == '{': num += 1 elif jsdata[idx2] == '}': num -= 1 if num == 0: tmp.append(jsdata[idx1:idx2 + 1]) start = idx2 + 1 else: break mark = 'this.options.links' tt = 'function e2iLinks(r){r=%s;for(var i in r)provider=providers[r[i].provider],r[i].provider=provider.d.split("://")[1],r[i].embed=provider.e(r[i].code,"800","600"),r[i].download=provider.l(r[i].code,"800","600");print(JSON.stringify(r))}' tmp.append(tt % self.cm.ph.getDataBeetwenMarkers( jsdata, mark + '=', ';', False)[1].replace( mark, 'r')) tabJs[key]['code'] = '\n'.join(tmp) printDBG(">>>>") printDBG(tabJs[key]['code']) printDBG("<<<<") try: js_params = [tabJs['providers']] js_params.append(tabJs['view']) js_params.append({'code': 'e2iLinks("%s");' % ad}) ret = js_execute_ext(js_params) data = json_loads(ret['data']) for item in data: name = '%s | %s | %s ' % (item['lang'], item['provider'], item['quality']) url = item['embed'] if not url: url = item['download'] linksTab.append({ 'name': name, 'url': strwithmeta(url, {'Referer': cUrl}), 'need_resolve': 1 }) except Exception: printExc() return linksTab