diff --git a/app.py b/app.py index dbefabecd0524173de16b133fd7bd3f709666df9..1f3e054f05ad4e274c2c4d93232c0a85ca52b918 100644 --- a/app.py +++ b/app.py @@ -88,13 +88,14 @@ def vod(): return jsonify(error.failed('爬虫规则加载失败')) # rule = ctx.eval('rule') - rule = ctx.rule.to_dict() + ruleDict = ctx.rule.to_dict() + ruleDict['id'] = rule # 把路由请求的id装到字典里,后面播放嗅探才能用 # print(rule) # print(type(rule)) logger.info(f'js装载耗时:{get_interval(t2)}毫秒') # print(rule) - cms = CMS(rule,db,RuleClass,PlayParse,app.config) + cms = CMS(ruleDict,db,RuleClass,PlayParse,app.config) wd = getParmas('wd') ac = getParmas('ac') quick = getParmas('quick') diff --git a/classes/cms.py b/classes/cms.py index 23ddff11e53270c3f89510ce34a631e08383221e..a13f9cdb9291fb6fdf26d2c02a41c75dce1dc389 100644 --- a/classes/cms.py +++ b/classes/cms.py @@ -12,7 +12,7 @@ from models import * from utils.config import config from utils.log import logger from utils.safePython import safePython -from utils.parser import runPy +from utils.parser import runPy,runJScode from utils.htmlParser import jsoup from urllib.parse import urljoin from concurrent.futures import ThreadPoolExecutor # 引入线程池 @@ -24,6 +24,7 @@ class CMS: if new_conf is None: new_conf = {} self.title = rule.get('title', '') + self.id = rule.get('id', self.title) self.lazy = rule.get('lazy', False) self.play_disable = new_conf.get('PLAY_DISABLE',False) self.vod = redirect(url_for('vod')).headers['Location'] @@ -35,7 +36,7 @@ class CMS: play_url = 'http://'+play_url if self.play_parse: # self.play_url = play_url + self.vod + '?play_url=' - self.play_url = f'{play_url}{self.vod}?rule={self.title}&play_url=' + self.play_url = f'{play_url}{self.vod}?rule={self.id}&play_url=' # logger.info(f'cms重定向链接:{self.play_url}') else: self.play_url = '' @@ -615,17 +616,32 @@ class CMS: def playContent(self, play_url): if self.lazy: print(f'{play_url}->开始执行免嗅代码->{self.lazy}') - pycode = runPy(self.lazy) - if pycode: - # print(pycode) - pos = pycode.find('def lazyParse') - if pos < 0: - return play_url - pyenv = safePython(self.lazy,pycode[pos:]) - lazy_url = pyenv.action_task_exec('lazyParse',[play_url,self.d]) - logger.info(f'播放免嗅结果:{lazy_url}') - if isinstance(lazy_url,str) and lazy_url.startswith('http'): - play_url = lazy_url + if not str(self.lazy).startswith('js:'): + pycode = runPy(self.lazy) + if pycode: + # print(pycode) + pos = pycode.find('def lazyParse') + if pos < 0: + return play_url + pyenv = safePython(self.lazy,pycode[pos:]) + lazy_url = pyenv.action_task_exec('lazyParse',[play_url,self.d]) + logger.info(f'播放免嗅结果:{lazy_url}') + if isinstance(lazy_url,str) and lazy_url.startswith('http'): + play_url = lazy_url + else: + jscode = str(self.lazy).split('js:')[1] + # jscode = f'var input={play_url};{jscode}' + # print(jscode) + loader,_ = runJScode(jscode,ctx={'input':play_url, + 'requests':requests,'print':print,'d':self.d, + 'log':logger.info,'pdfh':self.d.jsp.pdfh, + 'pdfa': self.d.jsp.pdfa,'pd':self.d.jsp.pd, + }) + # print(loader.toString()) + play_url = loader.eval('input') + print('play_url:',play_url) + + return play_url else: logger.info(f'播放重定向到:{play_url}') diff --git "a/js/\345\271\262\351\245\255\345\275\261\350\247\206.js" "b/js/\345\271\262\351\245\255\345\275\261\350\247\206.js" index 739f5b766e93781527fe8519db8d54cd1da5c605..aec33b9ca2a32a59e7c93fee4c11fbe3a27c30eb 100644 --- "a/js/\345\271\262\351\245\255\345\275\261\350\247\206.js" +++ "b/js/\345\271\262\351\245\255\345\275\261\350\247\206.js" @@ -11,7 +11,9 @@ var rule = { // class_url:'20&1&2&3&4&23', class_parse:'.stui-header__menu li:gt(0):lt(5);a&&Text;a&&href;/(\\d+).html', play_parse:true, - lazy:'干饭', + // lazy:'干饭', + // lazy:'@js:cacheUrl = d.getParse(input);print(cacheUrl);input=cacheUrl', + lazy:'js:cacheUrl = d.getParse(input);print(cacheUrl);input=cacheUrl', limit:5, 推荐:'ul.stui-vodlist.clearfix;li;a&&title;.lazyload&&data-original;;a&&href', double:true, // 推荐内容是否双层定位 diff --git "a/js/\346\250\241\346\235\277.js" "b/js/\346\250\241\346\235\277.js" index 02c7001b7dc33b56fbe725d007d4e55a28988f9e..17abcda7cb7576ddf8c9d22d686b910ed6ab4447 100644 --- "a/js/\346\250\241\346\235\277.js" +++ "b/js/\346\250\241\346\235\277.js" @@ -1,3 +1,15 @@ +Object.assign = function () { + var target = arguments[0]; + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; +}; var muban = { mxpro:{ title:'', diff --git "a/js/\350\223\235\350\216\223\345\275\261\350\247\206.js" "b/js/\350\223\235\350\216\223\345\275\261\350\247\206.js" index 968e3d6dfad210d1dc0835ac6172f4d92ee5ec2c..776e9e6aa61663d0abf20350d996c09f859b2b3c 100644 --- "a/js/\350\223\235\350\216\223\345\275\261\350\247\206.js" +++ "b/js/\350\223\235\350\216\223\345\275\261\350\247\206.js" @@ -10,7 +10,7 @@ var rule = { // class_name:'电影&网剧&剧集&动漫&综艺&记录', // class_url:'20&1&2&3&4&23', class_parse:'.navbar-items li:gt(1):lt(8);a&&Text;a&&href;/(\\d+).html', - play_parse:true, + play_parse:true,//一般有免嗅才开,没免嗅还开只能服务器打印日志进行监听并重定向 // lazy:'通用免嗅', limit:30, 推荐:'.tab-list.active;a.module-poster-item.module-item;.module-poster-item-title&&Text;.lazyload&&data-original;.module-item-note&&Text;a&&href', diff --git "a/py/\345\271\262\351\245\255.js" "b/py/\345\271\262\351\245\255.js" new file mode 100644 index 0000000000000000000000000000000000000000..e64396193278b29645ef5abc423dfc5d25140f33 --- /dev/null +++ "b/py/\345\271\262\351\245\255.js" @@ -0,0 +1,28 @@ +js: +cacheUrl = d.getParse(input); +print(cacheUrl); +if(cacheUrl){ + input=cacheUrl; +}else{ + try { + r = requests.get(input, headers=d.headers,timeout=d.timeout); + r.encoding = d.encoding; + html = r.text; + let ret = html.match(/var player_(.*?)=(.*?)