提交 f2ef5244 编写于 作者: H hjdhnx

增加推荐内容支持js:写法

上级 789affa5
......@@ -434,41 +434,94 @@ class CMS:
return result
def homeVideoContent(self,html,fypage=1):
if not self.推荐:
p = self.推荐
if not p:
return self.blank()
p = self.推荐.split(';') # 解析
if not self.double and len(p) < 5:
return self.blank()
if self.double and len(p) < 6:
return self.blank()
jsp = jsoup(self.homeUrl)
result = {}
videos = []
jsp = jsoup(self.homeUrl)
is_json = str(p[0]).startswith('json:')
pdfh = jsp.pjfh if is_json else jsp.pdfh
pdfa = jsp.pjfa if is_json else jsp.pdfa
pd = jsp.pj if is_json else jsp.pd
# print(html)
try:
if self.double:
items = pdfa(html, p[0])
for item in items:
items2 = pdfa(item,p[1])
for item2 in items2:
is_js = isinstance(p, str) and str(p).strip().startswith('js:') # 是js
if is_js:
headers['Referer'] = getHome(self.host)
py_ctx.update({
'input': self.homeUrl,
'HOST': self.host,
'TYPE': 'home', # 海阔js环境标志
'fetch_params': {'headers': headers, 'timeout': self.d.timeout, 'encoding': self.d.encoding},
'd': self.d,
'getParse': self.d.getParse,
'saveParse': self.d.saveParse,
'jsp': jsp, 'setDetail': setDetail,
})
ctx = py_ctx
jscode = getPreJs() + p.strip().replace('js:', '', 1)
# print(jscode)
try:
loader, _ = runJScode(jscode, ctx=ctx)
# print(loader.toString())
vods = loader.eval('VODS')
# print(vods)
if isinstance(vods, JsObjectWrapper):
videos = vods.to_list()
except Exception as e:
logger.info(f'首页推荐执行js获取列表出错:{e}')
else:
p = p.strip().split(';') # 解析
if not self.double and len(p) < 5:
return self.blank()
if self.double and len(p) < 6:
return self.blank()
jsp = jsoup(self.homeUrl)
is_json = str(p[0]).startswith('json:')
pdfh = jsp.pjfh if is_json else jsp.pdfh
pdfa = jsp.pjfa if is_json else jsp.pdfa
pd = jsp.pj if is_json else jsp.pd
# print(html)
try:
if self.double:
items = pdfa(html, p[0])
for item in items:
items2 = pdfa(item,p[1])
for item2 in items2:
try:
title = pdfh(item2, p[2])
img = pd(item2, p[3])
desc = pdfh(item2, p[4])
links = [pd(item2, p5) if not self.detailUrl else pdfh(item2, p5) for p5 in p[5].split('+')]
link = '$'.join(links)
content = '' if len(p) < 7 else pdfh(item2, p[6])
videos.append({
"vod_id": link,
"vod_name": title,
"vod_pic": img,
"vod_remarks": desc,
"no_use":{
"vod_content": content,
"type_id": 1,
"type_name": "首页推荐",
},
})
except:
pass
else:
items = pdfa(html, p[0].replace('json:',''))
# print(items)
for item in items:
try:
title = pdfh(item2, p[2])
img = pd(item2, p[3])
desc = pdfh(item2, p[4])
links = [pd(item2, p5) if not self.detailUrl else pdfh(item2, p5) for p5 in p[5].split('+')]
title = pdfh(item, p[1])
img = pd(item, p[2])
desc = pdfh(item, p[3])
# link = pd(item, p[4])
links = [pd(item, p5) if not self.detailUrl else pdfh(item, p5) for p5 in p[4].split('+')]
link = '$'.join(links)
content = '' if len(p) < 7 else pdfh(item2, p[6])
content = '' if len(p) < 6 else pdfh(item, p[5])
videos.append({
"vod_id": link,
"vod_name": title,
"vod_pic": img,
"vod_remarks": desc,
"no_use":{
"no_use": {
"vod_content": content,
"type_id": 1,
"type_name": "首页推荐",
......@@ -476,46 +529,24 @@ class CMS:
})
except:
pass
else:
items = pdfa(html, p[0].replace('json:',''))
# print(items)
for item in items:
try:
title = pdfh(item, p[1])
img = pd(item, p[2])
desc = pdfh(item, p[3])
# link = pd(item, p[4])
links = [pd(item, p5) if not self.detailUrl else pdfh(item, p5) for p5 in p[4].split('+')]
link = '$'.join(links)
content = '' if len(p) < 6 else pdfh(item, p[5])
videos.append({
"vod_id": link,
"vod_name": title,
"vod_pic": img,
"vod_remarks": desc,
"no_use": {
"vod_content": content,
"type_id": 1,
"type_name": "首页推荐",
},
})
except:
pass
# result['list'] = videos[min((fypage-1)*self.limit,len(videos)-1):min(fypage*self.limit,len(videos))]
result['list'] = videos
result['no_use'] = {
'code':1,
'msg':'数据列表',
'page':fypage,
'pagecount':math.ceil(len(videos)/self.limit),
'limit':self.limit,
'total':len(videos),
'now_count':len(result['list']),
}
return result
except Exception as e:
logger.info(f'首页内容获取失败:{e}')
return self.blank()
except Exception as e:
logger.info(f'首页内容获取失败:{e}')
return self.blank()
result['list'] = videos
result['no_use'] = {
'code': 1,
'msg': '数据列表',
'page': fypage,
'pagecount': math.ceil(len(videos) / self.limit),
'limit': self.limit,
'total': len(videos),
'now_count': len(result['list']),
}
# print(result)
return result
def categoryContent(self, fyclass, fypage):
"""
......@@ -548,7 +579,7 @@ class CMS:
headers['Referer'] = getHome(url)
py_ctx.update({
'input': url,
'TYPE': 'home', # 海阔js环境标志
'TYPE': 'cate', # 海阔js环境标志
'fetch_params': {'headers': headers, 'timeout': self.d.timeout, 'encoding': self.d.encoding},
'd': self.d,
'cateID':fyclass, # 分类id
......
......@@ -21,6 +21,8 @@ var rule = {
// lazy:'js:input="https://cache.json.icu/home/api?type=ys&uid=292796&key=fnoryABDEFJNPQV269&url="+input.split("?")[0];log(input);let html=JSON.parse(request(input));log(html);input=html.url||input',
// 推荐:'.list_item;img&&alt;img&&src;a&&Text;a&&data-float',
// 一级:'json:.data.list;.name;.imageUrl;.latestOrder;.albumId',
推荐:'',
// 推荐:'js:let d=[];fetch_params.headers["user-agent"]=PC_UA;pdfh=jsp.pdfh;pdfa=jsp.pdfa;pd=jsp.pd;let html=fetch(HOST,fetch_params);let lists=pdfa(html,".qy-mod-li");lists.forEach(function(it){try{let title=pdfh(it,"p.sub&&title");let desc=pdfh(it,".qy-mod-label&&Text");let pic_url=pd(it,"img&&src");d.push({title:title,desc:desc,img:pic_url})}catch(e){}});res=setResult(d);',
一级:'js:let d=[];if(cateID==="16"){input=input.replace("channel_id=16","channel_id=1").split("three_category_id")[0];input+="three_category_id=27401"}else if(cateID==="5"){input=input.replace("data_type=1","data_type=2")}let html=request(input);let json=JSON.parse(html);if(json.code==="A00003"){fetch_params.headers["user-agent"]=PC_UA;json=JSON.parse(fetch(input,fetch_params))}json.data.list.forEach(function(data){if(data.channelId===1){desc=data.hasOwnProperty("score")?data.score+"分\\t":""}else if(data.channelId===2||data.channelId===4){if(data.latestOrder===data.videoCount){desc=(data.hasOwnProperty("score")?data.score+"分\\t":"")+data.latestOrder+"集全"}else{if(data.videoCount){desc=(data.hasOwnProperty("score")?data.score+"分\\t":"")+data.latestOrder+"/"+data.videoCount+"集"}else{desc="更新至 "+data.latestOrder+"集"}}}else if(data.channelId===6){desc=data.period+"期"}else if(data.channelId===5){desc=data.focus}else{if(data.latestOrder){desc="更新至 第"+data.latestOrder+"期"}else if(data.period){desc=data.period}else{desc=data.focus}}url=cateID+"$"+data.albumId;d.push({url:url,title:data.name,desc:desc,pic_url:data.imageUrl.replace(".jpg","_390_520.jpg?caplist=jpg,webp")})});setResult(d);',
// 一级:'js:let d=[];if(cateID==="16"){input=input.replace("channel_id=16","channel_id=1").split("three_category_id")[0];input+="three_category_id=27401"}else if(cateID==="5"){input=input.replace("data_type=1","data_type=2")}let html=fetch(input,fetch_params);let json=JSON.parse(html);if(json.code==="A00003"){fetch_params.headers["user-agent"]=PC_UA;json=JSON.parse(fetch(input,fetch_params))}json.data.list.forEach(function(data){if(data.channelId===1){desc=data.hasOwnProperty("score")?data.score+"分\\t":""}else if(data.channelId===2||data.channelId===4){if(data.latestOrder===data.videoCount){desc=(data.hasOwnProperty("score")?data.score+"分\\t":"")+data.latestOrder+"集全"}else{if(data.videoCount){desc=(data.hasOwnProperty("score")?data.score+"分\\t":"")+data.latestOrder+"/"+data.videoCount+"集"}else{desc="更新至 "+data.latestOrder+"集"}}}else if(data.channelId===6){desc=data.period+"期"}else if(data.channelId===5){desc=data.focus}else{if(data.latestOrder){desc="更新至 第"+data.latestOrder+"期"}else if(data.period){desc=data.period}else{desc=data.focus}}url=cateID+"$"+data.albumId;d.push({url:url,title:data.name,desc:desc,pic_url:data.imageUrl.replace(".jpg","_390_520.jpg?caplist=jpg,webp")})});setResult(d);',
// 一级:'json:.data.list;.name;.imageUrl;.playUrl;.latestOrder',
......
js:
let d =[];
// print(input);
// print(HOST);
fetch_params.headers['user-agent'] = PC_UA;
// print(fetch_params);
pdfh = jsp.pdfh;
pdfa = jsp.pdfa;
pd = jsp.pd;
let html = fetch(HOST,fetch_params);
let lists = pdfa(html,'.qy-mod-li');
// print(lists.length);
lists.forEach(function (it){
try {
let title = pdfh(it,'p.sub&&title');
let desc = pdfh(it,'.qy-mod-label&&Text');
let pic_url = pd(it,'img&&src');
d.push({
title:title,
desc:desc,
img:pic_url,
});
}catch(e){
// print(e.message);
}
});
// print(d);
res = setResult(d);
// print(res);
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册