提交 55b1ec5a 编写于 作者: H hjdhnx

支持js免嗅

上级 7ae407d7
......@@ -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')
......
......@@ -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}')
......
......@@ -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, // 推荐内容是否双层定位
......
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:'',
......
......@@ -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',
......
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_(.*?)=(.*?)</)[2];
let url = JSON.parse(ret).url;
if(/\.m3u8|\.mp4/.test(url)){
input = url
}else if(!/http/.test(url)&&!/\//.test(url)){
try {
url = unescape(base64Decode(url));
if(/http/.test(url)){
input = url
}
}catch (e) {
print('解码url发生错误:'+e.message);
}
}
}catch (e) {
print('发生错误:'+e.message);
}
}
......@@ -18,6 +18,14 @@ import js2py
# os.environ["EXECJS_RUNTIME"] = "JScript"
# print(execjs.get().name)
def runJScode(jscode,loader=None,ctx=None):
if loader is None:
if ctx is None:
ctx = {}
loader = js2py.EvalJs(ctx)
loader.execute(jscode)
return loader, jscode
def runJs(jsPath, before='', after='', ctx=None):
# base_path = os.path.dirname(os.path.abspath(__file__)) # 当前文件所在目录
# base_path = os.path.dirname(os.getcwd()) # 当前主程序所在工作目录
......@@ -52,9 +60,11 @@ def runJs(jsPath, before='', after='', ctx=None):
if after:
jscode_to_run += after
loader = js2py.EvalJs(ctx)
return runJScode(jscode_to_run,loader)
# loader = execjs.compile(jscode_to_run)
loader.execute(jscode_to_run)
return loader,js_code
# print(jscode_to_run)
# loader.execute(jscode_to_run)
# return loader,js_code
def toJs(jsPath):
base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录
......@@ -96,7 +106,7 @@ def runPy(pyPath):
f.write(py_code)
except Exception as e:
print('发生了错误:',e)
return None, ''
return None
else:
with open(cache_path, 'r', encoding='UTF-8') as fp:
py_code = fp.read()
......@@ -119,6 +129,7 @@ def covert_demo():
loader.execute('function f(x) {return x*x};var a=py_sum([2,3]);var b=[a,5];var c={"a":a};')
f = loader.f
print(f(8))
print(f.toString())
print(loader.eval('py_sum(new Array(1, 2, 3))'))
print(loader.eval('py_sum([1, 2])'))
a = loader.a
......@@ -141,7 +152,10 @@ def covert_demo():
print(r[0].a)
print(loader.eval('r = requests.get("https://www.baidu.com/");r.encoding = "utf-8";r.text'))
# 下面是错误用法,没有loader环境没法正确eval_js,有loader用eval不需要eval_js
print(js2py.eval_js('r = requests.get("https://www.baidu.com/");r.encoding = "utf-8";r.text'))
# print(js2py.eval_js('r = requests.get("https://www.baidu.com/");r.encoding = "utf-8";r.text'))
with open('../js/夜空.js',encoding='utf-8') as f:
yk = f.read()
print(yk)
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册