From 59f2b392a299b174e1ea345c2d354cf6619c9faa Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Sat, 15 Oct 2022 21:09:35 +0800 Subject: [PATCH] =?UTF-8?q?js=E6=A8=A1=E5=BC=8F0=E5=A2=9E=E5=8A=A0tabs?= =?UTF-8?q?=E5=92=8Clists=E6=89=A7=E8=A1=8Cjs:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/rules.db | Bin 86016 -> 86016 bytes controllers/cms.py | 102 ++++++++++++++++++++++++++++++-------------- js/ddys.js | 2 +- utils/htmlParser.py | 6 ++- 4 files changed, 76 insertions(+), 34 deletions(-) diff --git a/base/rules.db b/base/rules.db index 24b4ca80beb097c63479852c327890079400a413..aa872794dd5de3851fbf55ad6076193634efa7cf 100644 GIT binary patch delta 26 icmZozz}m2Yb%Hdb%tRSyMwyKX3%VH%HZ%78KMVkLCkc-L delta 26 icmZozz}m2Yb%Hdb)I=F)MyZVn3%VH%H#7G9KMVkK^9hUq diff --git a/controllers/cms.py b/controllers/cms.py index a9f06ae..7e97344 100644 --- a/controllers/cms.py +++ b/controllers/cms.py @@ -882,7 +882,8 @@ class CMS: vod_play_from = '$$$' playFrom = [] - if p.get('重定向') and str(p['重定向']).startswith('js:'): + init_flag = {'ctx':False} + def js_pre(): headers['Referer'] = getHome(url) py_ctx.update({ 'input': url, @@ -896,6 +897,10 @@ class CMS: 'saveParse': self.d.saveParse, 'jsp': jsp, 'setDetail': setDetail, }) + init_flag['ctx'] = True + if p.get('重定向') and str(p['重定向']).startswith('js:'): + if not init_flag['ctx']: + js_pre() ctx = py_ctx # print(ctx) rcode = p['重定向'].replace('js:', '', 1) @@ -910,19 +915,34 @@ class CMS: if p.get('tabs'): vodHeader = [] - # print(p['tabs'].split(';')[0]) - vHeader = pdfa(html, p['tabs'].split(';')[0]) - # print(f'线路列表数:{len((vodHeader))}') - # print(vodHeader) - if not is_json: - for v in vHeader: - # 过滤排除掉线路标题 - v_title = pq(v).text() - if self.tab_exclude and jsp.test(self.tab_exclude, v_title): - continue - vodHeader.append(v_title) - else: + if str(p['tabs']).startswith('js:'): + if not init_flag['ctx']: + js_pre() + ctx = py_ctx + rcode = p['tabs'].replace('js:', '', 1) + jscode = getPreJs() + rcode + # print(jscode) + loader, _ = runJScode(jscode, ctx=ctx) + # print(loader.toString()) + logger.info(f'开始执行tabs代码:{rcode}') + vHeader = loader.eval('TABS') + if isinstance(vod, JsObjectWrapper): + vHeader = vHeader.to_list() vodHeader = vHeader + else: + # print(p['tabs'].split(';')[0]) + vHeader = pdfa(html, p['tabs'].split(';')[0]) + # print(f'线路列表数:{len((vodHeader))}') + # print(vodHeader) + if not is_json: + for v in vHeader: + # 过滤排除掉线路标题 + v_title = pq(v).text() + if self.tab_exclude and jsp.test(self.tab_exclude, v_title): + continue + vodHeader.append(v_title) + else: + vodHeader = vHeader else: vodHeader = ['道长在线'] @@ -935,25 +955,43 @@ class CMS: vod_play_url = '$$$' vod_tab_list = [] if p.get('lists'): - for i in range(len(vodHeader)): - tab_name = str(vodHeader[i]) - tab_ext = p['tabs'].split(';')[1] if len(p['tabs'].split(';')) > 1 else '' - p1 = p['lists'].replace('#idv', tab_name).replace('#id', str(i)) - tab_ext = tab_ext.replace('#idv', tab_name).replace('#id', str(i)) - vodList = pdfa(html, p1) # 1条线路的选集列表 - # print(vodList) - # vodList = [pq(i).text()+'$'+pd(i,'a&&href') for i in vodList] # 拼接成 名称$链接 - if self.play_parse: # 自动base64编码 - vodList = [(pdfh(html, tab_ext) if tab_ext else tab_name) + '$' + self.play_url + encodeUrl(i) for i - in vodList] if is_json else \ - [pq(i).text() + '$' + self.play_url + encodeUrl(pd(i, 'a&&href')) for i in vodList] # 拼接成 名称$链接 - else: - vodList = [(pdfh(html, tab_ext) if tab_ext else tab_name) + '$' + self.play_url + i for i in - vodList] if is_json else \ - [pq(i).text() + '$' + self.play_url + pd(i, 'a&&href') for i in vodList] # 拼接成 名称$链接 - vlist = '#'.join(vodList) # 拼多个选集 - vod_tab_list.append(vlist) - vod_play_url = vod_play_url.join(vod_tab_list) + if str(p['lists']).startswith('js:'): + if not init_flag['ctx']: + js_pre() + ctx = py_ctx + ctx['TABS'] = vodHeader # 把选集列表传过去 + rcode = p['lists'].replace('js:', '', 1) + jscode = getPreJs() + rcode + # print(jscode) + loader, _ = runJScode(jscode, ctx=ctx) + # print(loader.toString()) + logger.info(f'开始执行lists代码:{rcode}') + vlists = loader.eval('LISTS') + if isinstance(vod, JsObjectWrapper): + vlists = vlists.to_list() # [['第1集$http://1.mp4','第2集$http://2.mp4'],['第3集$http://1.mp4','第4集$http://2.mp4']] + + vod_play_url = vod_play_url.join(list(map(lambda x:'#'.join(x),vlists))) + else: + for i in range(len(vodHeader)): + tab_name = str(vodHeader[i]) + tab_ext = p['tabs'].split(';')[1] if len(p['tabs'].split(';')) > 1 else '' + p1 = p['lists'].replace('#idv', tab_name).replace('#id', str(i)) + tab_ext = tab_ext.replace('#idv', tab_name).replace('#id', str(i)) + vodList = pdfa(html, p1) # 1条线路的选集列表 + # print(vodList) + # vodList = [pq(i).text()+'$'+pd(i,'a&&href') for i in vodList] # 拼接成 名称$链接 + if self.play_parse: # 自动base64编码 + vodList = [(pdfh(html, tab_ext) if tab_ext else tab_name) + '$' + self.play_url + encodeUrl(i) for i + in vodList] if is_json else \ + [pq(i).text() + '$' + self.play_url + encodeUrl(pd(i, 'a&&href')) for i in vodList] # 拼接成 名称$链接 + else: + vodList = [(pdfh(html, tab_ext) if tab_ext else tab_name) + '$' + self.play_url + i for i in + vodList] if is_json else \ + [pq(i).text() + '$' + self.play_url + pd(i, 'a&&href') for i in vodList] # 拼接成 名称$链接 + vlist = '#'.join(vodList) # 拼多个选集 + vod_tab_list.append(vlist) + vod_play_url = vod_play_url.join(vod_tab_list) + # print(vod_play_url) vod['vod_play_from'] = vod_play_from # print(vod_play_from) diff --git a/js/ddys.js b/js/ddys.js index b938827..348d0c9 100644 --- a/js/ddys.js +++ b/js/ddys.js @@ -21,7 +21,7 @@ var rule={ //推荐:'.indexShowBox;ul&&li;a&&title;img&&data-src;.s1&&Text;a&&href', double:true, // 推荐内容是否双层定位 一级:'.post-box-list&&article;a:eq(-1)&&Text;.post-box-image&&style;a:eq(0)&&Text;a:eq(-1)&&href', - 二级:{"title":".post-title&&Text;.cat-links&&Text","img":".doulist-item&&img&&data-cfsrc","desc":".published&&Text","content":".abstract&&Text","tabs":".py-tabs&&option","lists":".player:eq(#id) li"}, + 二级:{"title":".post-title&&Text;.cat-links&&Text","img":".doulist-item&&img&&data-cfsrc","desc":".published&&Text","content":".abstract&&Text","tabs":"js:TABS=['道长在线','道长在线2']","lists":"js:log(TABS);LISTS=[['第1集$http://1.mp4','第2集$http://2.mp4'],['第3集$http://1.mp4','第4集$http://2.mp4']]"}, 搜索:'#main&&article;.post-title&&Text;;.published&&Text;a&&href', 推荐:'*' } \ No newline at end of file diff --git a/utils/htmlParser.py b/utils/htmlParser.py index 2b2c6e2..ad822e6 100644 --- a/utils/htmlParser.py +++ b/utils/htmlParser.py @@ -35,7 +35,11 @@ class jsoup: # FIXME 暂时不支持jsonpath那样的|| 分割取或属性 if option: # print(f'parse:{parse}=>(option:{option})') - ret = doc(parse) + if ':eq(-1)' in parse: + # 处理 eq(-1)的情况,兼容性差,暂时只支持一层eq + ret = doc(parse.replace(':eq(-1)','')).eq(-1) + else: + ret = doc(parse) # print(html) # FIXME 解析出来有多个的情况应该自动取第一个 if option == 'Text': -- GitLab