drpy.js 72.7 KB
Newer Older
1
// import 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/es6py.js';
H
hjdhnx 已提交
2
// import {是否正版,urlDeal,setResult,setResult2,setHomeResult,maoss,urlencode} from 'http://192.168.10.103:5705/libs/es6py.js';
3
// import 'http://192.168.1.124:5705/libs/es6py.js';
H
hjdhnx 已提交
4 5
import cheerio from 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/cheerio.min.js';
// import cheerio from 'http://192.168.10.103:5705/libs/cheerio.min.js';
H
hjdhnx 已提交
6
import 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/crypto-js.js';
H
hjdhnx 已提交
7 8
import 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/drT.js';
// import 'http://192.168.10.103:5705/libs/drT.js';
H
hjdhnx 已提交
9
// import muban from 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/模板.js';
H
hjdhnx 已提交
10
// import muban from 'http://192.168.10.103:5705/admin/view/模板.js';
H
hjdhnx 已提交
11 12

// const key = 'drpy_zbk';
13
// eval(req('http://192.168.1.124:5705/libs/es6py.js').content);
H
hjdhnx 已提交
14
function init_test(){
15
    // console.log(typeof(CryptoJS));
H
hjdhnx 已提交
16
    console.log("init_test_start");
H
hjdhnx 已提交
17
    console.log("当前版本号:"+VERSION);
H
hjdhnx 已提交
18
    console.log(RKEY);
H
hjdhnx 已提交
19
    console.log(JSON.stringify(rule));
20
    // console.log('123456的md5值是:'+md5('123456'));
H
hjdhnx 已提交
21 22 23 24
    // let aa = base64Encode('编码测试一下')
    // log(aa);
    // let bb = base64Decode(aa);
    // log('bb:'+bb);
H
hjdhnx 已提交
25 26 27 28 29 30 31
    // clearItem(RULE_CK);
    // console.log(JSON.stringify(rule));
    // console.log(request('https://www.baidu.com',{withHeaders:true}));
    // console.log(request('https://www.baidu.com/favicon.ico',{toBase64:true}));
    // require('http://192.168.10.99:5705/txt/pluto/drT.js');
    // console.log(typeof(drT));
    // console.log(drT.renderText('{{fl.cate}},hi, {{fl}}哈哈.{{fl}}',{sort: 1,cate:'movie'},'fl'));
H
hjdhnx 已提交
32
    console.log("init_test_end");
H
hjdhnx 已提交
33 34
}

H
hjdhnx 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/**
 * 执行预处理代码
 */
function pre(){
    if(typeof(rule.预处理) === 'string' && rule.预处理 && rule.预处理.trim()){
        let code = rule.预处理.trim();
        console.log("执行预处理代码:"+code);
        if(code.startsWith('js:')){
            code = code.replace('js:','');
        }
        try {
            // code里可以进行get 或者 post请求cookie并改变rule.headers 里的cookie
            //  直接操作 rule_fetch_params 这个变量 .headers.Cookie
            eval(code);
        }catch (e) {
            console.log('预处理执行失败:'+e.message);
        }
    }
}

H
hjdhnx 已提交
55
let rule = {};
H
hjdhnx 已提交
56
const VERSION = '3.9.20beta7';
H
hjdhnx 已提交
57
/** 已知问题记录
58
 * 1.影魔的jinjia2引擎不支持 {{fl}}对象直接渲染 (有能力解决的话尽量解决下,支持对象直接渲染字符串转义,如果加了|safe就不转义)[影魔牛逼,最新的文件发现这问题已经解决了]
H
hjdhnx 已提交
59 60
 * Array.prototype.append = Array.prototype.push; 这种js执行后有毛病,for in 循环列表会把属性给打印出来 (这个大毛病需要重点排除一下)
 * 2.import es6py.js但是里面的函数没有被装载进来.比如drpy规则报错setResult2 is undefiend(合并文件了可以不管了)
H
hjdhnx 已提交
61
 * 3.无法重复导入cheerio(怎么解决drpy和parseTag里都需要导入cheerio的问题) 无法在副文件导入cheerio (现在是全部放在drpy一个文件里了,凑合解决?)
62
 * 4.有个错误不知道哪儿来的 executeScript: com.quickjs.JSObject$Undefined cannot be cast to java.lang.String 在 点击选集播放打印init_test_end后面打印(貌似不影响使用)
H
hjdhnx 已提交
63
 * 5.需要实现 stringify 函数,比起JSON.stringify函数,它会原封不动保留中文不会编码unicode
64 65
 * 6.base64Encode,base64Decode,md5函数还没有实现 (抄影魔代码实现了)
 * 7.eval(getCryptoJS());还没有实现 (可以空实现了,以后遇到能忽略)
H
hjdhnx 已提交
66
 * done:  jsp:{pdfa,pdfh,pd},json:{pdfa,pdfh,pd},jq:{pdfa,pdfh,pd}
67 68 69 70 71 72
 *  * 电脑看日志调试
 adb tcpip 5555
 adb connect 192.168.10.192
 adb devices -l
 adb logcat -c
 adb logcat | grep -i QuickJS
H
hjdhnx 已提交
73 74 75
 adb logcat -c -b events
 adb logcat -c -b main -b events -b radio -b system
 adb logcat > 2.log DRPY:E | grep -i QuickJS
H
hjdhnx 已提交
76
 * **/
H
hjdhnx 已提交
77 78 79 80 81 82 83 84 85


/*** 以下是内置变量和解析方法 **/
const MOBILE_UA = 'Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36';
const PC_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36';
const UA = 'Mozilla/5.0';
const UC_UA = 'Mozilla/5.0 (Linux; U; Android 9; zh-CN; MI 9 Build/PKQ1.181121.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/12.5.5.1035 Mobile Safari/537.36';
const IOS_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1';
const RULE_CK = 'cookie'; // 源cookie的key值
H
hjdhnx 已提交
86
// const KEY = typeof(key)!=='undefined'&&key?key:'drpy_' + (rule.title || rule.host); // 源的唯一标识
H
hjdhnx 已提交
87 88 89 90
const CATE_EXCLUDE = '首页|留言|APP|下载|资讯|新闻|动态';
const TAB_EXCLUDE = '猜你|喜欢|APP|下载|剧情|热播';
const OCR_RETRY = 3;//ocr验证重试次数
// const OCR_API = 'http://dm.mudery.com:10000';//ocr在线识别接口
H
hjdhnx 已提交
91
// const OCR_API = 'http://192.168.3.239:5705/parse/ocr';//ocr在线识别接口
H
hjdhnx 已提交
92 93
// const OCR_API = 'http://cms.nokia.press/parse/ocr';//ocr在线识别接口
const OCR_API = 'http://cms.nokia.press:5706/parse/ocr';//ocr在线识别接口
H
hjdhnx 已提交
94 95 96
if(typeof(MY_URL)==='undefined'){
    var MY_URL; // 全局注入变量,pd函数需要
}
H
hjdhnx 已提交
97
var RKEY; // 源的唯一标识
H
hjdhnx 已提交
98 99 100
var fetch;
var print;
var log;
H
hjdhnx 已提交
101 102
var rule_fetch_params;
var fetch_params; // 每个位置单独的
H
hjdhnx 已提交
103
var oheaders;
H
hjdhnx 已提交
104
// var play_url; // 二级详情页注入变量,为了适配js模式0 (不在这里定义了,直接二级里定义了个空字符串)
H
hjdhnx 已提交
105 106 107
var _pdfh;
var _pdfa;
var _pd;
H
hjdhnx 已提交
108
// const DOM_CHECK_ATTR = ['url', 'src', 'href', 'data-original', 'data-src'];
H
hjdhnx 已提交
109
const DOM_CHECK_ATTR = /(url|src|href|-original|-src|-play|-url)$/;
H
hjdhnx 已提交
110 111 112
const SELECT_REGEX = /:eq|:lt|:gt|#/g;
const SELECT_REGEX_A = /:eq|:lt|:gt/g;

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
/**
es6py扩展
 */
if (typeof Object.assign != 'function') {
    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;
    };
}
if (!String.prototype.includes) {
    String.prototype.includes = function (search, start) {
        if (typeof start !== 'number') {
            start = 0;
        }

        if (start + search.length > this.length) {
            return false;
        } else {
            return this.indexOf(search, start) !== -1;
        }
    };
}

if (!Array.prototype.includes) {
    Object.defineProperty(Array.prototype, 'includes', {
        value: function (searchElement, fromIndex) {

            if (this == null) {//this是空或者未定义,抛出错误
                throw new TypeError('"this" is null or not defined');
            }

            var o = Object(this);//将this转变成对象
            var len = o.length >>> 0;//无符号右移0位,获取对象length属性,如果未定义就会变成0

            if (len === 0) {//length为0直接返回false未找到目标值
                return false;
            }

            var n = fromIndex | 0;//查找起始索引
            var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);//计算正确起始索引,因为有可能是负值

            while (k < len) {//从起始索引处开始循环
                if (o[k] === searchElement) {//如果某一位置与寻找目标相等,返回true,找到了
                    return true;
                }
                k++;
            }
            return false;//未找到,返回false
        }
    });
}
if (typeof String.prototype.startsWith != 'function') {
    String.prototype.startsWith = function (prefix){
        return this.slice(0, prefix.length) === prefix;
    };
}
if (typeof String.prototype.endsWith != 'function') {
    String.prototype.endsWith = function(suffix) {
        return this.indexOf(suffix, this.length - suffix.length) !== -1;
    };
}
Object.prototype.myValues=function(obj){
    if(obj ==null) {
        throw new TypeError("Cannot convert undefined or null to object");
    }
    var res=[]
    for(var k in obj){
        if(obj.hasOwnProperty(k)){//需判断是否是本身的属性
            res.push(obj[k]);
        }
    }
    return res;
}
if (typeof Object.prototype.values != 'function') {
    Object.prototype.values=function(obj){
        if(obj ==null) {
            throw new TypeError("Cannot convert undefined or null to object");
        }
        var res=[]
        for(var k in obj){
            if(obj.hasOwnProperty(k)){//需判断是否是本身的属性
                res.push(obj[k]);
            }
        }
        return res;
    }
}
if (typeof Array.prototype.join != 'function') {
    Array.prototype.join = function (emoji) {
        // emoji = emoji||',';
        emoji = emoji||'';
        let self = this;
        let str = "";
        let i = 0;
        if (!Array.isArray(self)) {throw String(self)+'is not Array'}
        if(self.length===0){return ''}
        if (self.length === 1){return String(self[0])}
        i = 1;
        str = this[0];
        for (; i < self.length; i++) {
            str += String(emoji)+String(self[i]);
        }
        return str;
    };
}

String.prototype.rstrip = function (chars) {
    let regex = new RegExp(chars + "$");
    return this.replace(regex, "");
};

Array.prototype.append = Array.prototype.push;
String.prototype.strip = String.prototype.trim;
function 是否正版(vipUrl){
    let flag = new RegExp('qq\.com|iqiyi\.com|youku\.com|mgtv\.com|bilibili\.com|sohu\.com|ixigua\.com|pptv\.com|miguvideo\.com|le\.com|1905\.com|fun\.tv');
    return  flag.test(vipUrl);
}
function urlDeal(vipUrl){
    if(!vipUrl){
        return ''
    }
    if(!是否正版(vipUrl)){
        return vipUrl
    }
    if(!/miguvideo/.test(vipUrl)){
        vipUrl=vipUrl.split('#')[0].split('?')[0];
    }
    return vipUrl
}
function setResult(d){
    if(!Array.isArray(d)){
        return []
    }
    VODS = [];
H
hjdhnx 已提交
255
    // print(d);
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
    d.forEach(function (it){
        let obj = {
            vod_id:it.url||'',
            vod_name: it.title||'',
            vod_remarks: it.desc||'',
            vod_content: it.content||'',
            vod_pic: it.pic_url||it.img||'',
        };
        let keys = Object.keys(it);
        if(keys.includes('tname')){
            obj.type_name = it.tname||'';
        }
        if(keys.includes('tid')){
            obj.type_id = it.tid||'';
        }
        if(keys.includes('year')){
            obj.vod_year = it.year||'';
        }
        if(keys.includes('actor')){
            obj.vod_actor = it.actor||'';
        }
        if(keys.includes('director')){
            obj.vod_director = it.director||'';
        }
        if(keys.includes('area')){
            obj.vod_area = it.area||'';
        }
        VODS.push(obj);
    });
    return VODS
}
function setResult2(res){
    VODS = res.list||[];
    return VODS
}
function setHomeResult(res){
    if(!res||typeof(res)!=='object'){
        return []
    }
    return setResult(res.list);
}
H
hjdhnx 已提交
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
// 猫了个咪
function rc(js) {
    if (js === 'maomi_aes.js') {
        var a = CryptoJS.enc.Utf8.parse("625222f9149e961d");
        var t = CryptoJS.enc.Utf8.parse("5efdtf6060e2o330");
        return {
            De: function (word) {
                word = CryptoJS.enc.Hex.parse(word)
                return CryptoJS.AES.decrypt(CryptoJS.enc.Base64.stringify(word), a, {
                    iv: t,
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7
                }).toString(CryptoJS.enc.Utf8)
            },
            En: function (word) {
                // print(a);
                // print(word);
                var Encrypted = CryptoJS.AES.encrypt(word, a, {
                    iv: t,
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7
                });
                return Encrypted.ciphertext.toString();
            }
        };
    }
    return {};
}

326 327 328
// 千万不要用for in 推荐 forEach (for in 会打乱顺序)
//猫函数
function maoss(jxurl, ref, key) {
329
    fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
    eval(getCryptoJS());
    try {
        var getVideoInfo = function (text) {
            return CryptoJS.AES.decrypt(text, key, {iv: iv, padding: CryptoJS.pad.Pkcs7}).toString(CryptoJS.enc.Utf8);
        };
        var token_key = key == undefined ? 'dvyYRQlnPRCMdQSe' : key;
        if (ref) {
            var html = request(jxurl, {
                headers: {
                    'Referer': ref
                }
            });
        } else {
            var html = request(jxurl);
        }
        // print(html);
        if (html.indexOf('&btwaf=') != -1) {
            html = request(jxurl + '&btwaf' + html.match(/&btwaf(.*?)"/)[1], {
                headers: {
                    'Referer': ref
                }
            })
        }
        var token_iv = html.split('_token = "')[1].split('"')[0];
        var key = CryptoJS.enc.Utf8.parse(token_key);
        var iv = CryptoJS.enc.Utf8.parse(token_iv);
        // log("iv:"+iv);
        //  log(html);
        // print(key);
        // print(iv);
        eval(html.match(/var config = {[\s\S]*?}/)[0] + '');
        // config.url = config.url.replace(/,/g,'');
        // print(config.url);
        if (!config.url.startsWith('http')) {
            //config.url = decodeURIComponent(AES(config.url, key, iv));
            config.url = CryptoJS.AES.decrypt(config.url, key, {
                iv: iv,
                padding: CryptoJS.pad.Pkcs7
            }).toString(CryptoJS.enc.Utf8)
        }
        return config.url;
    } catch (e) {
        return '';
    }
}

function urlencode (str) {
    str = (str + '').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}
H
hjdhnx 已提交
381 382

function base64Encode(text){
383 384
    return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(text));
    // return text
H
hjdhnx 已提交
385 386
}

H
hjdhnx 已提交
387
function base64Decode(text){
388 389 390 391 392 393 394 395 396 397 398
    return CryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(text));
    // return text
}

function md5(text) {
    return CryptoJS.MD5(text).toString();
}

function getCryptoJS(){
    // return request('https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/crypto-hiker.js');
    return 'console.log("CryptoJS已装载");'
H
hjdhnx 已提交
399 400
}

H
hjdhnx 已提交
401 402
let VODS = [];// 一级或者搜索需要的数据列表
let VOD = {};// 二级的单个数据
H
hjdhnx 已提交
403 404
let TABS = [];// 二级的自定义线路列表 如: TABS=['道长在线','道长在线2']
let LISTS = [];// 二级的自定义选集播放列表 如: LISTS=[['第1集$http://1.mp4','第2集$http://2.mp4'],['第3集$http://1.mp4','第4集$http://2.mp4']]
H
hjdhnx 已提交
405 406 407
globalThis.encodeUrl = urlencode;
globalThis.urlencode = urlencode;

408 409


H
hjdhnx 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
/**
 *  url拼接
 * @param fromPath 初始当前页面url
 * @param nowPath 相对当前页面url
 * @returns {*}
 */
function urljoin(fromPath, nowPath) {
    fromPath = fromPath||'';
    nowPath = nowPath||'';
    return joinUrl(fromPath, nowPath);
    // try {
    //     // import Uri from './uri.min.js';
    //     // var Uri = require('./uri.min.js');
    //     // eval(request('https://cdn.bootcdn.net/ajax/libs/URI.js/1.19.11/URI.min.js'));
    //     // let new_uri = URI(nowPath, fromPath);

    //     let new_uri = Uri(nowPath, fromPath);
    //     new_uri = new_uri.toString();
    //     // console.log(new_uri);
    //     // return fromPath + nowPath
    //     return new_uri
    // }
    // catch (e) {
    //     console.log('urljoin发生错误:'+e.message);
    //     if(nowPath.startsWith('http')){
    //         return nowPath
    //     }if(nowPath.startsWith('/')){
    //         return getHome(fromPath)+nowPath
    //     }
    //     return fromPath+nowPath
    // }
}
442
var urljoin2 = urljoin;
H
hjdhnx 已提交
443

H
hjdhnx 已提交
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
// 内置 pdfh,pdfa,pd
const defaultParser = {
    pdfh:pdfh,
    pdfa:pdfa,
    pd(html,parse,uri){
        let ret = this.pdfh(html,parse);
        if(typeof(uri)==='undefined'||!uri){
            uri = '';
        }
        if(DOM_CHECK_ATTR.test(parse)){
            if(/http/.test(ret)){
                ret = ret.substr(ret.indexOf('http'));
            }else{
                ret = urljoin(MY_URL,ret)
            }
        }
        return ret
    },
};

H
hjdhnx 已提交
464

H
hjdhnx 已提交
465 466 467 468 469 470 471
/**
 *  pdfh原版优化,能取style属性里的图片链接
 * @param html 源码
 * @param parse 解析表达式
 * @returns {string|*}
 */
function pdfh2(html,parse){
472 473 474 475 476 477 478 479 480
    let html2 = html;
    try {
        if(typeof(html)!=='string'){
            html2 = html.rr(html.ele).toString();
        }
    }catch (e) {
        print('html对象转文本发生了错误:'+e.message);
    }
    let result = defaultParser.pdfh(html2,parse);
H
hjdhnx 已提交
481 482 483 484 485 486 487 488 489
    let option = parse.includes('&&')?parse.split('&&').slice(-1)[0]:parse.split(' ').slice(-1)[0];
    if(/style/.test(option.toLowerCase())&&/url\(/.test(result)){
        try {
            result =  result.match(/url\((.*?)\)/)[1];
        }catch (e) {}
    }
    return result
}

490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
/**
 * pdfa原版优化,可以转换jq的html对象
 * @param html
 * @param parse
 * @returns {*}
 */
function pdfa2(html,parse){
    let html2 = html;
    try {
        if(typeof(html)!=='string'){
            html2 = html.rr(html.ele).toString();
        }
    }catch (e) {
        print('html对象转文本发生了错误:'+e.message);
    }
    return defaultParser.pdfa(html2,parse);
}

H
hjdhnx 已提交
508
/**
H
hjdhnx 已提交
509
 * pd原版方法重写-增加自动urljoin
H
hjdhnx 已提交
510 511 512 513 514
 * @param html
 * @param parse
 * @param uri
 * @returns {*}
 */
H
hjdhnx 已提交
515
function pd2(html,parse,uri){
H
hjdhnx 已提交
516
    let ret = pdfh2(html,parse);
H
hjdhnx 已提交
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
    if(typeof(uri)==='undefined'||!uri){
        uri = '';
    }
    if(DOM_CHECK_ATTR.test(parse)){
        if(/http/.test(ret)){
            ret = ret.substr(ret.indexOf('http'));
        }else{
            ret = urljoin(MY_URL,ret)
        }
    }
    // MY_URL = getItem('MY_URL',MY_URL);
    // console.log(`规则${RKEY}打印MY_URL:${MY_URL},uri:${uri}`);
    return ret
}

const parseTags = {
    jsp:{
H
hjdhnx 已提交
534
        pdfh:pdfh2,
535
        pdfa:pdfa2,
H
hjdhnx 已提交
536
        pd:pd2,
H
hjdhnx 已提交
537 538 539 540 541 542
    },
    json:{
        pdfh(html, parse) {
            if (!parse || !parse.trim()){
                return '';
            }
H
hjdhnx 已提交
543 544
            if (typeof(html) === 'string'){
                // print('jsonpath:pdfh字符串转dict');
H
hjdhnx 已提交
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
                html = JSON.parse(html);
            }
            parse = parse.trim();
            if (!parse.startsWith('$.')){
                parse = '$.' + parse;
            }
            parse = parse.split('||');
            for (let ps of parse) {
                let ret = cheerio.jp(ps, html);
                if (Array.isArray(ret)){
                    ret = ret[0] || '';
                } else{
                    ret = ret || ''
                }
                if (ret && typeof (ret) !== 'string'){
                    ret = ret.toString();
                }
                if(ret){
                    return ret
                }
            }
            return '';
        },
        pdfa(html, parse) {
            if (!parse || !parse.trim()){
                return '';
            }
H
hjdhnx 已提交
572 573
            if (typeof(html) === 'string'){
                // print('jsonpath:pdfa字符串转dict');
H
hjdhnx 已提交
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
                html = JSON.parse(html);
            }
            parse = parse.trim()
            if (!parse.startsWith('$.')){
                parse = '$.' + parse;
            }
            let ret = cheerio.jp(parse, html);
            if (Array.isArray(ret) && Array.isArray(ret[0]) && ret.length === 1){
                return ret[0] || []
            }
            return ret || []
        },
        pd(html,parse){
            let ret = parseTags.json.pdfh(html,parse);
            if(ret){
                return urljoin(MY_URL,ret);
            }
            return ret
        },
    },
    jq:{
        pdfh(html, parse, base_url) {
H
hjdhnx 已提交
596
            if (!parse || !parse.trim()) {
H
hjdhnx 已提交
597 598
                return ''
            }
H
hjdhnx 已提交
599
            let eleFind = typeof html === 'object';
H
hjdhnx 已提交
600
            let option = undefined;
H
hjdhnx 已提交
601 602 603 604 605 606 607
            if (eleFind && parse.startsWith('body&&')) {
                parse = parse.substr(6);
                if (parse.indexOf('&&') < 0) {
                    option = parse.trim();
                    parse = '*=*';
                }
            }
H
hjdhnx 已提交
608 609 610 611 612 613
            if (parse.indexOf('&&') > -1) {
                let sp = parse.split('&&');
                option = sp[sp.length - 1];
                sp.splice(sp.length - 1);
                if (sp.length > 1) {
                    for (let i in sp) {
H
hjdhnx 已提交
614 615 616 617 618
                        //Javascript自定义Array.prototype干扰for-in循环
                        if(sp.hasOwnProperty(i)){
                            if (!SELECT_REGEX.test(sp[i])) {
                                sp[i] = sp[i] + ':eq(0)';
                            }
H
hjdhnx 已提交
619 620 621 622 623 624 625 626 627 628
                        }
                    }
                } else {
                    if (!SELECT_REGEX.test(sp[0])) {
                        sp[0] = sp[0] + ':eq(0)';
                    }
                }
                parse = sp.join(' ');
            }
            let result = '';
H
hjdhnx 已提交
629 630
            const $ = eleFind ? html.rr : cheerio.load(html);
            let ret = eleFind ? ((parse === '*=*' || $(html.ele).is(parse)) ? html.ele : $(html.ele).find(parse)) : $(parse);
H
hjdhnx 已提交
631
            if (option) {
H
hjdhnx 已提交
632
                if (option === 'Text') {
H
hjdhnx 已提交
633 634
                    result = $(ret).text();
                }
H
hjdhnx 已提交
635
                else if (option === 'Html') {
H
hjdhnx 已提交
636 637
                    result = $(ret).html();
                }
H
hjdhnx 已提交
638
                else {
H
hjdhnx 已提交
639
                    result = $(ret).attr(option);
H
hjdhnx 已提交
640 641 642 643 644
                    if(/style/.test(option.toLowerCase())&&/url\(/.test(result)){
                        try {
                            result =  result.match(/url\((.*?)\)/)[1];
                        }catch (e) {}
                    }
H
hjdhnx 已提交
645 646
                }
                if (result && base_url && DOM_CHECK_ATTR.test(option)) {
H
hjdhnx 已提交
647
                    if (/http/.test(result)) {
H
hjdhnx 已提交
648
                        result = result.substr(result.indexOf('http'));
H
hjdhnx 已提交
649 650
                    } else {
                        result = urljoin(base_url, result)
H
hjdhnx 已提交
651 652 653 654 655 656 657 658
                    }
                }
            } else {
                result = $(ret).toString();
            }
            return result;
        },
        pdfa(html, parse) {
H
hjdhnx 已提交
659
            if (!parse || !parse.trim()) {
H
hjdhnx 已提交
660
                print('!parse');
H
hjdhnx 已提交
661 662
                return [];
            }
H
hjdhnx 已提交
663
            let eleFind = typeof html === 'object';
H
hjdhnx 已提交
664
            // print('parse前:'+parse);
H
hjdhnx 已提交
665 666 667
            if (parse.indexOf('&&') > -1) {
                let sp = parse.split('&&');
                for (let i in sp) {
H
hjdhnx 已提交
668 669 670 671 672 673
                    if(sp.hasOwnProperty(i)){
                        if (!SELECT_REGEX_A.test(sp[i]) && i < sp.length - 1) {
                            if(sp[i]!=='body'){
                                // sp[i] = sp[i] + ':eq(0)';
                                sp[i] = sp[i] + ':first';
                            }
H
hjdhnx 已提交
674
                        }
H
hjdhnx 已提交
675 676 677 678
                    }
                }
                parse = sp.join(' ');
            }
H
hjdhnx 已提交
679
            // print('parse后:'+parse);
H
hjdhnx 已提交
680 681
            const $ = eleFind ? html.rr : cheerio.load(html);
            let ret = eleFind ? ($(html.ele).is(parse) ? html.ele : $(html.ele).find(parse)) : $(parse);
H
hjdhnx 已提交
682
            let result = [];
H
hjdhnx 已提交
683 684
            // print('outerHTML:');
            // print($(ret[0]).prop("outerHTML"));
H
hjdhnx 已提交
685 686
            if (ret) {
                ret.each(function (idx, ele) {
H
hjdhnx 已提交
687
                    result.push({ rr: $, ele: ele });
H
hjdhnx 已提交
688
                    // result.push({ rr: $, ele: $(ele).prop("outerHTML")}); // 性能贼差
H
hjdhnx 已提交
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
                });
            }
            return result;
        },
        pd(html,parse,uri){
            return parseTags.jq.pdfh(html, parse, MY_URL);
        },
    },
    getParse(p0){//非js开头的情况自动获取解析标签
        if(p0.startsWith('jsp:')){
            return this.jsp
        }else if(p0.startsWith('json:')){
            return this.json
        }else if(p0.startsWith('jq:')){
            return this.jq
        }else {
            return this.jq
        }
    }
};

const stringify = JSON.stringify;
H
hjdhnx 已提交
711
const jsp = parseTags.jsp;
712
const jq = parseTags.jq;
H
hjdhnx 已提交
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731

/*** 后台需要实现的java方法并注入到js中 ***/

/**
 * 读取本地文件->应用程序目录
 * @param filePath
 * @returns {string}
 */
function readFile(filePath){
    filePath = filePath||'./uri.min.js';
    var fd = os.open(filePath);
    var buffer = new ArrayBuffer(1024);
    var len = os.read(fd, buffer, 0, 1024);
    console.log(len);
    let text = String.fromCharCode.apply(null, new Uint8Array(buffer));
    console.log(text);
    return text
}

H
hjdhnx 已提交
732 733 734 735 736 737 738
/**
 * 处理返回的json数据
 * @param html
 * @returns {*}
 */
function dealJson(html) {
    try {
739
        // html = html.match(/[\w|\W|\s|\S]*?(\{[\w|\W|\s|\S]*\})/).group[1];
H
hjdhnx 已提交
740 741 742 743
        html = html.trim();
        if(!((html.startsWith('{') && html.endsWith('}'))||(html.startsWith('[') && html.endsWith(']')))){
            html = '{'+html.match(/.*?\{(.*)\}/m)[1]+'}';
        }
H
hjdhnx 已提交
744 745
    } catch (e) {
    }
H
hjdhnx 已提交
746 747 748 749
    try {
        html = JSON.parse(html);
    }catch (e) {}
    // console.log(typeof(html));
H
hjdhnx 已提交
750 751 752
    return html;
}

H
hjdhnx 已提交
753 754 755 756 757 758 759 760 761
/**
 * 验证码识别逻辑,需要java实现(js没有bytes类型,无法调用后端的传递图片二进制获取验证码文本的接口)
 * @type {{api: string, classification: (function(*=): string)}}
 */
var OcrApi={
    api:OCR_API,
    classification:function (img){ // img是byte类型,这里不方便搞啊
        let code = '';
        try {
762
            let html = request(this.api,{data:{img:img},headers:{'User-Agent':PC_UA},'method':'POST'},true);
H
hjdhnx 已提交
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
            html = JSON.parse(html);
            code = html.url||'';
        }catch (e) {}
        return code
    }
};
/**
 * 验证码识别,暂未实现
 * @param url 验证码图片链接
 * @returns {string} 验证成功后的cookie
 */
function verifyCode(url){
    let cnt = 0;
    let host = getHome(url);
    let cookie = '';
    while (cnt < OCR_RETRY){
        try{
            // let obj = {headers:headers,timeout:timeout};
            let yzm_url = `${host}/index.php/verify/index.html`;
            console.log(`验证码链接:${yzm_url}`);
783
            let hhtml = request(yzm_url,{withHeaders:true,toBase64:true},true);
H
hjdhnx 已提交
784 785
            let json = JSON.parse(hhtml);
            if(!cookie){
786 787 788 789
                // print(json);
                let setCk = Object.keys(json).find(it=>it.toLowerCase()==='set-cookie');
                // cookie = json['set-cookie']?json['set-cookie'].split(';')[0]:'';
                cookie = setCk?json[setCk].split(';')[0]:'';
H
hjdhnx 已提交
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
            }
            // console.log(hhtml);
            console.log('cookie:'+cookie);
            let img = json.body;
            // console.log(img);
            let code = OcrApi.classification(img);
            console.log(`第${cnt+1}次验证码识别结果:${code}`);
            let submit_url = `${host}/index.php/ajax/verify_check?type=search&verify=${code}`;
            console.log(submit_url);
            let html = request(submit_url,{headers:{Cookie:cookie,'User-Agent':MOBILE_UA},'method':'POST'});
            // console.log(html);
            html = JSON.parse(html);
            if(html.msg === 'ok'){
                console.log(`第${cnt+1}次验证码提交成功`);
                return cookie // 需要返回cookie
            }else if(html.msg!=='ok'&&cnt+1>=OCR_RETRY){
                cookie = ''; // 需要清空返回cookie
            }
        }catch (e) {
            console.log(`第${cnt+1}次验证码提交失败:${e.message}`);
            if(cnt+1>=OCR_RETRY){
                cookie = '';
            }
        }
        cnt+=1
    }
    return cookie
}

/**
 * 存在数据库配置表里, key字段对应值value,没有就新增,有就更新,调用此方法会清除key对应的内存缓存
 * @param k 键
 * @param v 值
 */
function setItem(k,v){
H
hjdhnx 已提交
825 826
    local.set(RKEY,k,v);
    console.log(`规则${RKEY}设置${k} => ${v}`)
H
hjdhnx 已提交
827 828 829 830 831 832 833 834 835
}

/**
 *  获取数据库配置表对应的key字段的value,没有这个key就返回value默认传参.需要有缓存,第一次获取后会存在内存里
 * @param k 键
 * @param v 值
 * @returns {*}
 */
function getItem(k,v){
H
hjdhnx 已提交
836
    return local.get(RKEY,k) || v;
H
hjdhnx 已提交
837 838 839 840 841 842 843
}

/**
 *  删除数据库key对应的一条数据,并清除此key对应的内存缓存
 * @param k
 */
function clearItem(k){
H
hjdhnx 已提交
844
    local.delete(RKEY,k);
H
hjdhnx 已提交
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
}

/*** js自封装的方法 ***/

/**
 * 获取链接的host(带http协议的完整链接)
 * @param url 任意一个正常完整的Url,自动提取根
 * @returns {string}
 */
function getHome(url){
    if(!url){
        return ''
    }
    let tmp = url.split('//');
    url = tmp[0] + '//' + tmp[1].split('/')[0];
H
hjdhnx 已提交
860 861 862
    try {
        url = decodeURIComponent(url);
    }catch (e) {}
H
hjdhnx 已提交
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
    return url
}

/**
 * get参数编译链接,类似python params字典自动拼接
 * @param url 访问链接
 * @param obj 参数字典
 * @returns {*}
 */
function buildUrl(url,obj){
    obj = obj||{};
    if(url.indexOf('?')<0){
        url += '?'
    }
    let param_list = [];
    let keys = Object.keys(obj);
    keys.forEach(it=>{
        param_list.push(it+'='+obj[it])
    });
    let prs = param_list.join('&');
    if(keys.length > 0 && !url.endsWith('?')){
        url += '&'
    }
    url+=prs;
    return url
}

/**
 * 远程依赖执行函数
 * @param url 远程js地址
 */
function require(url){
    eval(request(url));
}
/**
 * 海阔网页请求函数完整封装
 * @param url 请求链接
 * @param obj 请求对象 {headers:{},method:'',timeout:5000,body:'',withHeaders:false}
901
 * @param ocr_flag 标识此flag是用于请求ocr识别的,自动过滤content-type指定编码
H
hjdhnx 已提交
902 903
 * @returns {string|string|DocumentFragment|*}
 */
904 905
function request(url,obj,ocr_flag){
    ocr_flag = ocr_flag||false;
H
hjdhnx 已提交
906
    if(typeof(obj)==='undefined'||!obj||obj==={}){
H
hjdhnx 已提交
907 908 909 910 911 912 913
        if(!fetch_params||!fetch_params.headers){
            let headers = {
                'User-Agent':MOBILE_UA,
            };
            if(rule.headers){
                Object.assign(headers,rule.headers);
            }
914 915 916
            if(!fetch_params){
                fetch_params = {};
            }
H
hjdhnx 已提交
917
            fetch_params.headers = headers;
H
hjdhnx 已提交
918
        }
H
hjdhnx 已提交
919 920
        if(!fetch_params.headers.Referer){
            fetch_params.headers.Referer = getHome(url)
H
hjdhnx 已提交
921
        }
H
hjdhnx 已提交
922
        obj = fetch_params;
H
hjdhnx 已提交
923 924 925 926 927 928 929 930 931 932
    }else{
        let headers = obj.headers||{};
        let keys = Object.keys(headers).map(it=>it.toLowerCase());
        if(!keys.includes('user-agent')){
            headers['User-Agent'] = MOBILE_UA;
        }if(!keys.includes('referer')){
            headers['Referer'] = getHome(url);
        }
        obj.headers = headers;
    }
933
    if(rule.encoding&&rule.encoding!=='utf-8'&&!ocr_flag){
H
hjdhnx 已提交
934
        if(!obj.headers.hasOwnProperty('Content-Type')&&!obj.headers.hasOwnProperty('content-type')){ // 手动指定了就不管
H
hjdhnx 已提交
935 936
            obj.headers["Content-Type"] = 'text/html; charset='+rule.encoding;
        }
937
    }
H
hjdhnx 已提交
938
    if(typeof(obj.body)!='undefined'&&obj.body&&typeof (obj.body)==='string'){
H
hjdhnx 已提交
939
        let data = {};
H
hjdhnx 已提交
940
        obj.body.split('&').forEach(it=>{
H
hjdhnx 已提交
941 942 943
            data[it.split('=')[0]] = it.split('=')[1]
        });
        obj.data = data;
H
hjdhnx 已提交
944 945 946 947
        delete obj.body
    }else if(typeof(obj.body)!='undefined'&&obj.body&&typeof (obj.body)==='object'){
        obj.data = obj.body;
        delete obj.body
H
hjdhnx 已提交
948 949 950 951 952 953 954 955
    }
    if(!url){
        return obj.withHeaders?'{}':''
    }
    if(obj.toBase64){ // 返回base64,用于请求图片
        obj.buffer = 2;
        delete obj.toBase64
    }
H
hjdhnx 已提交
956 957
    console.log(JSON.stringify(obj.headers));
    // console.log('request:'+url+' obj:'+JSON.stringify(obj));
H
hjdhnx 已提交
958
    console.log('request:'+url);
H
hjdhnx 已提交
959 960
    let res = req(url, obj);
    let html = res.content||'';
H
hjdhnx 已提交
961
    // console.log(html);
H
hjdhnx 已提交
962 963 964 965 966 967 968 969 970
    if(obj.withHeaders){
        let htmlWithHeaders = res.headers;
        htmlWithHeaders.body = html;
        return JSON.stringify(htmlWithHeaders);
    }else{
        return html
    }
}

H
hjdhnx 已提交
971 972 973 974 975 976 977 978 979 980 981
/**
 *  快捷post请求
 * @param url 地址
 * @param obj 对象
 * @returns {string|DocumentFragment|*}
 */
function post(url,obj){
    obj.method = 'POST';
    return request(url,obj);
}

H
hjdhnx 已提交
982 983 984
fetch = request;
print = function (data){
    data = data||'';
H
hjdhnx 已提交
985
    if(typeof(data)=='object'&&Object.keys(data).length>0){
H
hjdhnx 已提交
986 987
        try {
            data = JSON.stringify(data);
H
hjdhnx 已提交
988
            console.log(data);
H
hjdhnx 已提交
989
        }catch (e) {
H
hjdhnx 已提交
990 991 992
            // console.log('print:'+e.message);
            console.log(typeof(data)+':'+data.length);
            return
H
hjdhnx 已提交
993
        }
H
hjdhnx 已提交
994
    }else if(typeof(data)=='object'&&Object.keys(data).length<1){
H
hjdhnx 已提交
995
        console.log('null object');
H
hjdhnx 已提交
996 997 998
    }else{
        console.log(data);
    }
H
hjdhnx 已提交
999
}
H
md  
hjdhnx 已提交
1000
log = print;
H
hjdhnx 已提交
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
/**
 * 检查宝塔验证并自动跳过获取正确源码
 * @param html 之前获取的html
 * @param url 之前的来源url
 * @param obj 来源obj
 * @returns {string|DocumentFragment|*}
 */
function checkHtml(html,url,obj){
    if(/\?btwaf=/.test(html)){
        let btwaf = html.match(/btwaf(.*?)"/)[1];
        url = url.split('#')[0]+'?btwaf'+btwaf;
H
hjdhnx 已提交
1012
        print('宝塔验证访问链接:'+url);
H
hjdhnx 已提交
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
        html = request(url,obj);
    }
    return html
}

/**
 *  带一次宝塔验证的源码获取
 * @param url 请求链接
 * @param obj 请求参数
 * @returns {string|DocumentFragment}
 */
function getCode(url,obj){
    let html = request(url,obj);
    html = checkHtml(html,url,obj);
    return html
}

/**
 * 源rule专用的请求方法,自动注入cookie
 * @param url 请求链接
 * @returns {string|DocumentFragment}
 */
function getHtml(url){
    let obj = {};
    if(rule.headers){
        obj.headers = rule.headers;
    }
    let cookie = getItem(RULE_CK,'');
    if(cookie){
        if(obj.headers && ! Object.keys(obj.headers).map(it=>it.toLowerCase()).includes('cookie')){
            obj.headers['Cookie'] = cookie;
        }else if(!obj.headers){
            obj.headers = {Cookie:cookie};
        }
    }
    let html = getCode(url,obj);
    return html
}

/**
 * 首页分类解析,筛选暂未实现
 * @param homeObj 首页传参对象
 * @returns {string}
 */
function homeParse(homeObj) {
H
hjdhnx 已提交
1058
    fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
H
hjdhnx 已提交
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
    let classes = [];
    if (homeObj.class_name && homeObj.class_url) {
        let names = homeObj.class_name.split('&');
        let urls = homeObj.class_url.split('&');
        let cnt = Math.min(names.length, urls.length);
        for (let i = 0; i < cnt; i++) {
            classes.push({
                'type_id': urls[i],
                'type_name': names[i]
            });
        }
    }

    if (homeObj.class_parse) {
        let p = homeObj.class_parse.split(';');
1074 1075 1076 1077 1078 1079
        let _ps = parseTags.getParse(p[0]);
        _pdfa = _ps.pdfa;
        _pdfh = _ps.pdfh;
        _pd = _ps.pd;
        MY_URL = rule.url;
        if (p.length >= 3) { // 可以不写正则
H
hjdhnx 已提交
1080 1081 1082
            try {
                let html = getHtml(homeObj.MY_URL);
                if (html) {
H
hjdhnx 已提交
1083
                    homeHtmlCache = html;
1084
                    let list = _pdfa(html, p[0]);
H
hjdhnx 已提交
1085
                    if (list && list.length > 0) {
H
hjdhnx 已提交
1086
                        list.forEach((it,idex) => {
H
hjdhnx 已提交
1087
                            try {
1088
                                let name = _pdfh(it, p[1]);
H
hjdhnx 已提交
1089 1090 1091
                                if (homeObj.cate_exclude && (new RegExp(homeObj.cate_exclude).test(name))) {
                                    return;
                                }
1092 1093 1094
                                // let url = pdfh(it, p[2]);
                                let url = _pd(it, p[2]);
                                if (p.length > 3 && p[3]) {
H
hjdhnx 已提交
1095 1096 1097 1098 1099
                                    let exp = new RegExp(p[3]);
                                    url = url.match(exp)[1];
                                }

                                classes.push({
H
hjdhnx 已提交
1100 1101
                                    'type_id': url.trim(),
                                    'type_name': name.trim()
H
hjdhnx 已提交
1102 1103
                                });
                            } catch (e) {
H
hjdhnx 已提交
1104
                                console.log(`分类列表定位第${idex}个元素正常报错:${e.message}`);
H
hjdhnx 已提交
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
                            }
                        });
                    }
                }
            } catch (e) {
                console.log(e.message);
            }

        }
    }
H
hjdhnx 已提交
1115 1116
    // 排除分类
    classes = classes.filter(it=>!homeObj.cate_exclude || !(new RegExp(homeObj.cate_exclude).test(it.type_name)));
H
hjdhnx 已提交
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
    let resp = {
        'class': classes
    };
    if(homeObj.filter){
        resp.filters = homeObj.filter;
    }
    console.log(JSON.stringify(resp));
    return JSON.stringify(resp);

}

H
hjdhnx 已提交
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
/**
 * 推荐和搜索单字段继承一级
 * @param p 推荐或搜索的解析分割;列表
 * @param pn 自身列表序号
 * @param pp  一级解析分割;列表
 * @param ppn 继承一级序号
 * @returns {*}
 */
function getPP(p, pn, pp, ppn){
    let ps = p[pn] === '*' && pp.length > ppn ?pp[ppn]:p[pn]
    return ps
}

H
hjdhnx 已提交
1141 1142 1143 1144 1145 1146
/**
 *  首页推荐列表解析
 * @param homeVodObj
 * @returns {string}
 */
function homeVodParse(homeVodObj){
H
hjdhnx 已提交
1147
    fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
H
hjdhnx 已提交
1148 1149 1150 1151
    let d = [];
    MY_URL = homeVodObj.homeUrl;
    // setItem('MY_URL',MY_URL);
    console.log(MY_URL);
H
hjdhnx 已提交
1152
    let t1 = (new Date()).getTime();
H
hjdhnx 已提交
1153
    let p = homeVodObj.推荐;
H
hjdhnx 已提交
1154
    print('p:'+p);
H
hjdhnx 已提交
1155 1156 1157 1158
    if(p==='*' && rule.一级){
        p = rule.一级;
        homeVodObj.double = false;
    }
H
hjdhnx 已提交
1159
    if(!p||typeof(p)!=='string'){
H
hjdhnx 已提交
1160 1161
        return '{}'
    }
H
hjdhnx 已提交
1162
    p = p.trim();
H
hjdhnx 已提交
1163
    let pp = rule.一级.split(';');
H
hjdhnx 已提交
1164
    if(p.startsWith('js:')){
H
hjdhnx 已提交
1165 1166 1167
        const TYPE = 'home';
        var input = MY_URL;
        const HOST = rule.host;
H
hjdhnx 已提交
1168
        eval(p.replace('js:',''));
H
hjdhnx 已提交
1169 1170 1171 1172 1173 1174 1175 1176
        d = VODS;
    }else {
        p = p.split(';');
        if (!homeVodObj.double && p.length < 5) {
            return '{}'
        } else if (homeVodObj.double && p.length < 6) {
            return '{}'
        }
H
hjdhnx 已提交
1177 1178
        let p0 = getPP(p,0,pp,0)
        let _ps = parseTags.getParse(p0);
H
hjdhnx 已提交
1179 1180 1181
        _pdfa = _ps.pdfa;
        _pdfh = _ps.pdfh;
        _pd = _ps.pd;
H
hjdhnx 已提交
1182 1183
        let is_json = p0.startsWith('json:');
        p0 = p0.replace(/^(jsp:|json:|jq:)/,'');
H
hjdhnx 已提交
1184
        // print(p[0]);
H
hjdhnx 已提交
1185 1186
        let html = homeHtmlCache || getHtml(MY_URL);
        homeHtmlCache = undefined;
H
hjdhnx 已提交
1187
        if(is_json){
H
hjdhnx 已提交
1188
            // print('是json,开始处理');
H
hjdhnx 已提交
1189 1190
            html = dealJson(html);
        }
H
hjdhnx 已提交
1191 1192 1193
        try {
            console.log('double:' + homeVodObj.double);
            if (homeVodObj.double) {
H
hjdhnx 已提交
1194
                let items = _pdfa(html, p0);
H
hjdhnx 已提交
1195 1196 1197
                // console.log(items.length);
                for (let item of items) {
                    // console.log(p[1]);
H
hjdhnx 已提交
1198
                    let items2 = _pdfa(item, p[1]);
H
hjdhnx 已提交
1199 1200 1201
                    // console.log(items2.length);
                    for (let item2 of items2) {
                        try {
H
hjdhnx 已提交
1202 1203
                            let p2 = getPP(p,2,pp,1);
                            let title = _pdfh(item2, p2);
H
hjdhnx 已提交
1204 1205
                            let img = '';
                            try {
H
hjdhnx 已提交
1206 1207 1208 1209 1210 1211 1212 1213 1214
                                let p3 = getPP(p,3,pp,2);
                                img = _pd(item2, p3);
                            } catch (e) {}
                            let desc = '';
                            try {
                                let p4 = getPP(p,4,pp,3);
                                desc = _pdfh(item2, p4);
                            }catch (e) {}
                            let p5 = getPP(p,5,pp,4);
H
hjdhnx 已提交
1215
                            let links = [];
H
hjdhnx 已提交
1216 1217
                            for (let _p5 of p5.split('+')) {
                                let link = !homeVodObj.detailUrl ? _pd(item2, _p5, MY_URL) : _pdfh(item2, _p5);
H
hjdhnx 已提交
1218 1219
                                links.push(link);
                            }
H
hjdhnx 已提交
1220 1221 1222 1223 1224 1225 1226
                            let content;
                            if(p.length > 6 && p[6]){
                                let p6 = getPP(p,6,pp,5);
                                content = _pdfh(item2, p6);
                            } else{
                                content = '';
                            }
H
hjdhnx 已提交
1227 1228 1229 1230
                            let vid = links.join('$');
                            if(rule.二级==='*'){
                                vid = vid+'@@'+title+'@@'+img;
                            }
H
hjdhnx 已提交
1231 1232 1233 1234
                            let vod = {
                                vod_name: title,
                                vod_pic: img,
                                vod_remarks: desc,
H
hjdhnx 已提交
1235
                                vod_content: content,
H
hjdhnx 已提交
1236
                                vod_id: vid
H
hjdhnx 已提交
1237
                            };
H
hjdhnx 已提交
1238
                            // print(vod);
H
hjdhnx 已提交
1239 1240
                            d.push(vod);
                        } catch (e) {
H
hjdhnx 已提交
1241
                            console.log('首页列表处理发生错误:'+e.message);
H
hjdhnx 已提交
1242 1243 1244 1245 1246 1247 1248 1249 1250
                        }

                    }


                }


            } else {
H
hjdhnx 已提交
1251
                let items = _pdfa(html, p0);
H
hjdhnx 已提交
1252 1253
                for (let item of items) {
                    try {
H
hjdhnx 已提交
1254 1255
                        let p1 = getPP(p,1,pp,1);
                        let title = _pdfh(item, p1);
H
hjdhnx 已提交
1256 1257
                        let img = '';
                        try {
H
hjdhnx 已提交
1258 1259 1260 1261 1262 1263 1264 1265 1266
                            let p2 = getPP(p,2,pp,2);
                            img = _pd(item, p2, MY_URL);
                        } catch (e) {}
                        let desc = '';
                        try {
                            let p3 = getPP(p,3,pp,3);
                            desc = _pdfh(item, p3);
                        }catch (e) {}
                        let p4 = getPP(p,4,pp,4);
H
hjdhnx 已提交
1267
                        let links = [];
H
hjdhnx 已提交
1268 1269
                        for (let _p5 of p4.split('+')) {
                            let link = !homeVodObj.detailUrl ? _pd(item, _p5, MY_URL) : _pdfh(item, _p5);
H
hjdhnx 已提交
1270 1271
                            links.push(link);
                        }
H
hjdhnx 已提交
1272 1273 1274 1275 1276 1277 1278
                        let content;
                        if(p.length > 5 && p[5]){
                            let p5 = getPP(p,5,pp,5);
                            content = _pdfh(item, p5);
                        }else{
                            content = ''
                        }
H
hjdhnx 已提交
1279 1280 1281 1282
                        let vid = links.join('$');
                        if(rule.二级==='*'){
                            vid = vid+'@@'+title+'@@'+img;
                        }
H
hjdhnx 已提交
1283 1284 1285 1286
                        let vod = {
                            vod_name: title,
                            vod_pic: img,
                            vod_remarks: desc,
H
hjdhnx 已提交
1287
                            vod_content: content,
H
hjdhnx 已提交
1288
                            vod_id: vid
H
hjdhnx 已提交
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
                        };
                        d.push(vod);

                    } catch (e) {

                    }

                }

            }

        } catch (e) {

        }
    }
H
hjdhnx 已提交
1304 1305
    let t2 = (new Date()).getTime();
    console.log('加载首页推荐耗时:'+(t2-t1)+'毫秒');
H
hjdhnx 已提交
1306
    // console.log(JSON.stringify(d));
H
hjdhnx 已提交
1307 1308 1309 1310 1311 1312 1313
    if(rule.图片来源){
        d.forEach(it=>{
            if(it.vod_pic&&it.vod_pic.startsWith('http')){
                it.vod_pic = it.vod_pic + rule.图片来源;
            }
        });
    }
H
hjdhnx 已提交
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
    return JSON.stringify({
        list:d
    })
}

/**
 * 一级分类页数据解析
 * @param cateObj
 * @returns {string}
 */
function categoryParse(cateObj) {
H
hjdhnx 已提交
1325
    fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
H
hjdhnx 已提交
1326
    let p = cateObj.一级;
H
hjdhnx 已提交
1327 1328 1329
    if(!p||typeof(p)!=='string'){
        return '{}'
    }
H
hjdhnx 已提交
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
    let d = [];
    // let url = cateObj.url.replaceAll('fyclass', cateObj.tid).replaceAll('fypage', cateObj.pg);
    let url = cateObj.url.replaceAll('fyclass', cateObj.tid);
    if(rule.filter_url){
        if(!/fyfilter/.test(url)){
            if(!url.endsWith('&')&&!rule.filter_url.startsWith('&')){
                url+='&'
            }
            url+=rule.filter_url;
        }else{
            url = url.replace('fyfilter', rule.filter_url);
        }
        // console.log('filter:'+cateObj.filter);
        let fl = cateObj.filter?cateObj.extend:{};
H
hjdhnx 已提交
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
        // 自动合并 不同分类对应的默认筛选
        if(rule.filter_def && typeof(rule.filter_def)==='object'){
            try {
                if(Object.keys(rule.filter_def).length>0 && rule.filter_def.hasOwnProperty(cateObj.tid)){
                    let self_fl_def = rule.filter_def[cateObj.tid];
                    if(self_fl_def && typeof(self_fl_def)==='object'){
                        // 引用传递转值传递,避免污染self变量
                        let fl_def = JSON.parse(JSON.stringify(self_fl_def));
                        fl = Object.assign(fl_def,fl);
                    }
                }
            }catch (e) {
                print('合并不同分类对应的默认筛选出错:'+e.message);
            }
        }
H
hjdhnx 已提交
1359 1360
        let new_url;
        new_url = cheerio.jinja2(url,{fl:fl});
1361
        // console.log('jinjia2执行后的new_url类型为:'+typeof(new_url));
H
hjdhnx 已提交
1362 1363 1364 1365
        if(/object Object/.test(new_url)){
            new_url = drT.renderText(url,fl);
        }
        url = new_url;
H
hjdhnx 已提交
1366 1367 1368 1369
    }
    if(/fypage/.test(url)){
        if(url.includes('(')&&url.includes(')')){
            let url_rep = url.match(/.*?\((.*)\)/)[1];
H
hjdhnx 已提交
1370
            // console.log(url_rep);
H
hjdhnx 已提交
1371
            let cnt_page = url_rep.replaceAll('fypage', cateObj.pg);
H
hjdhnx 已提交
1372 1373 1374
            // console.log(cnt_page);
            let cnt_pg = eval(cnt_page);
            // console.log(cnt_pg);
H
hjdhnx 已提交
1375 1376 1377 1378 1379 1380 1381
            url = url.replaceAll(url_rep,cnt_pg).replaceAll('(','').replaceAll(')','');
        }else{
            url = url.replaceAll('fypage',cateObj.pg);
        }
    }
    if(cateObj.pg === 1 && url.includes('[')&&url.includes(']')){
        url = url.split('[')[1].split(']')[0];
H
hjdhnx 已提交
1382 1383
    }else if(cateObj.pg > 1 && url.includes('[')&&url.includes(']')){
        url = url.split('[')[0];
H
hjdhnx 已提交
1384 1385 1386 1387
    }
    MY_URL = url;
    // setItem('MY_URL',MY_URL);
    console.log(MY_URL);
H
hjdhnx 已提交
1388
    p = p.trim();
1389
    const MY_CATE = cateObj.tid;
H
hjdhnx 已提交
1390
    if(p.startsWith('js:')){
H
hjdhnx 已提交
1391
        var MY_FL = cateObj.extend;
H
hjdhnx 已提交
1392 1393 1394
        const TYPE = 'cate';
        var input = MY_URL;
        const MY_PAGE = cateObj.pg;
H
hjdhnx 已提交
1395
        var desc = '';
H
hjdhnx 已提交
1396 1397 1398 1399 1400 1401 1402
        eval(p.trim().replace('js:',''));
        d = VODS;
    }else {
        p = p.split(';');
        if (p.length < 5) {
            return '{}'
        }
H
hjdhnx 已提交
1403 1404 1405 1406
        let _ps = parseTags.getParse(p[0]);
        _pdfa = _ps.pdfa;
        _pdfh = _ps.pdfh;
        _pd = _ps.pd;
H
hjdhnx 已提交
1407
        let is_json = p[0].startsWith('json:');
H
hjdhnx 已提交
1408
        p[0] = p[0].replace(/^(jsp:|json:|jq:)/,'');
H
hjdhnx 已提交
1409 1410 1411
        try {
            let html = getHtml(MY_URL);
            if (html) {
H
hjdhnx 已提交
1412 1413 1414
                if(is_json){
                    html = dealJson(html);
                }
H
hjdhnx 已提交
1415
                let list = _pdfa(html, p[0]);
H
hjdhnx 已提交
1416
                list.forEach(it => {
1417
                    let links = p[4].split('+').map(p4=>{
1418
                        return !rule.detailUrl?_pd(it, p4,MY_URL):_pdfh(it, p4);
1419 1420 1421
                    });
                    let link = links.join('$');
                    let vod_id = rule.detailUrl?MY_CATE+'$'+link:link;
H
hjdhnx 已提交
1422 1423 1424 1425 1426 1427 1428

                    let vod_name = _pdfh(it, p[1]).replace(/\n|\t/g,'').trim();
                    let vod_pic = _pd(it, p[2],MY_URL);

                    if(rule.二级==='*'){
                        vod_id = vod_id+'@@'+vod_name+'@@'+vod_pic;
                    }
H
hjdhnx 已提交
1429
                    d.push({
1430
                        'vod_id': vod_id,
H
hjdhnx 已提交
1431 1432
                        'vod_name': vod_name,
                        'vod_pic': vod_pic,
H
hjdhnx 已提交
1433
                        'vod_remarks': _pdfh(it, p[3]).replace(/\n|\t/g,'').trim(),
H
hjdhnx 已提交
1434 1435 1436 1437 1438 1439 1440
                    });
                });
            }
        } catch (e) {
            console.log(e.message);
        }
    }
H
hjdhnx 已提交
1441 1442 1443 1444 1445 1446 1447
    if(rule.图片来源){
        d.forEach(it=>{
            if(it.vod_pic&&it.vod_pic.startsWith('http')){
                it.vod_pic = it.vod_pic + rule.图片来源;
            }
        });
    }
1448
    // print(d);
H
hjdhnx 已提交
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
    return d.length<1?'{}':JSON.stringify({
        'page': parseInt(cateObj.pg),
        'pagecount': 999,
        'limit': 20,
        'total': 999,
        'list': d,
    });
}

/**
 * 搜索列表数据解析
 * @param searchObj
 * @returns {string}
 */
function searchParse(searchObj) {
H
hjdhnx 已提交
1464
    fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
H
hjdhnx 已提交
1465 1466 1467 1468 1469
    let d = [];
    if(!searchObj.searchUrl){
        return '{}'
    }
    let p = searchObj.搜索==='*'&&rule.一级 ? rule.一级 : searchObj.搜索;
H
hjdhnx 已提交
1470 1471 1472 1473
    if(!p||typeof(p)!=='string'){
        return '{}'
    }
    p = p.trim();
H
hjdhnx 已提交
1474
    let pp = rule.一级.split(';');
H
hjdhnx 已提交
1475 1476 1477
    let url = searchObj.searchUrl.replaceAll('**', searchObj.wd).replaceAll('fypage', searchObj.pg);
    MY_URL = url;
    console.log(MY_URL);
H
hjdhnx 已提交
1478
    // log(searchObj.搜索);
H
hjdhnx 已提交
1479
    // setItem('MY_URL',MY_URL);
H
hjdhnx 已提交
1480
    if(p.startsWith('js:')){
H
hjdhnx 已提交
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492
        const TYPE = 'search';
        const MY_PAGE = searchObj.pg;
        const KEY = searchObj.wd;
        var input = MY_URL;
        var detailUrl = rule.detailUrl||'';
        eval(p.trim().replace('js:',''));
        d = VODS;
    }else{
        p = p.split(';');
        if (p.length < 5) {
            return '{}'
        }
H
hjdhnx 已提交
1493 1494
        let p0 = getPP(p,0,pp,0);
        let _ps = parseTags.getParse(p0);
H
hjdhnx 已提交
1495 1496 1497
        _pdfa = _ps.pdfa;
        _pdfh = _ps.pdfh;
        _pd = _ps.pd;
H
hjdhnx 已提交
1498 1499
        let is_json = p0.startsWith('json:');
        p0 = p0.replace(/^(jsp:|json:|jq:)/,'');
H
hjdhnx 已提交
1500
        // print('1381 p0:'+p0);
H
hjdhnx 已提交
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
        try {
            let html = getHtml(MY_URL);
            if (html) {
                if(/系统安全验证|输入验证码/.test(html)){
                    let cookie = verifyCode(MY_URL);
                    if(cookie){
                        console.log(`本次成功过验证,cookie:${cookie}`);
                        setItem(RULE_CK,cookie);
                    }else{
                        console.log(`本次自动过搜索验证失败,cookie:${cookie}`);
                    }
                    // obj.headers['Cookie'] = cookie;
                    html = getHtml(MY_URL);
                }
                if(!html.includes(searchObj.wd)){
                    console.log('搜索结果源码未包含关键字,疑似搜索失败,正为您打印结果源码');
                    console.log(html);
                }
H
hjdhnx 已提交
1519
                if(is_json){
H
hjdhnx 已提交
1520
                    // console.log(html);
H
hjdhnx 已提交
1521
                    html = dealJson(html);
1522
                    // console.log(JSON.stringify(html));
H
hjdhnx 已提交
1523
                }
1524
                // console.log(html);
H
hjdhnx 已提交
1525
                let list = _pdfa(html, p0);
H
hjdhnx 已提交
1526 1527
                // print(list.length);
                // print(list);
H
hjdhnx 已提交
1528
                list.forEach(it => {
H
hjdhnx 已提交
1529 1530 1531 1532 1533 1534
                    let p1 = getPP(p, 1, pp, 1);
                    let p2 = getPP(p, 2, pp, 2);
                    let p3 = getPP(p, 3, pp, 3);
                    let p4 = getPP(p, 4, pp, 4);
                    let links = p4.split('+').map(_p4=>{
                        return !rule.detailUrl?_pd(it, _p4,MY_URL):_pdfh(it, _p4)
1535 1536
                    });
                    let link = links.join('$');
H
hjdhnx 已提交
1537 1538 1539
                    let content;
                    if(p.length > 5 && p[5]){
                        let p5 = getPP(p,5,pp,5);
H
hjdhnx 已提交
1540
                        content = _pdfh(it, p5);
H
hjdhnx 已提交
1541 1542 1543
                    }else{
                        content = '';
                    }
H
hjdhnx 已提交
1544 1545 1546 1547 1548 1549
                    let vod_id = link;
                    let vod_name = _pdfh(it, p1).replace(/\n|\t/g,'').trim();
                    let vod_pic = _pd(it, p2,MY_URL);
                    if(rule.二级==='*'){
                        vod_id = vod_id+'@@'+vod_name+'@@'+vod_pic;
                    }
H
hjdhnx 已提交
1550
                    let ob = {
H
hjdhnx 已提交
1551 1552 1553
                        'vod_id': vod_id,
                        'vod_name': vod_name,
                        'vod_pic': vod_pic,
H
hjdhnx 已提交
1554 1555
                        'vod_remarks': _pdfh(it, p3).replace(/\n|\t/g,'').trim(),
                        'vod_content': content.replace(/\n|\t/g,'').trim(),
H
hjdhnx 已提交
1556 1557 1558 1559 1560 1561
                    };
                    d.push(ob);
                });

            }
        } catch (e) {
H
hjdhnx 已提交
1562
            print('搜索发生错误:'+e.message);
H
hjdhnx 已提交
1563 1564 1565
            return '{}'
        }
    }
H
hjdhnx 已提交
1566 1567 1568 1569 1570 1571 1572 1573
    if(rule.图片来源){
        d.forEach(it=>{
            if(it.vod_pic&&it.vod_pic.startsWith('http')){
                it.vod_pic = it.vod_pic + rule.图片来源;
            }
        });
    }
    // print(d);
H
hjdhnx 已提交
1574 1575 1576 1577 1578 1579 1580
    return JSON.stringify({
        'page': parseInt(searchObj.pg),
        'pagecount': 10,
        'limit': 20,
        'total': 100,
        'list': d,
    });
H
hjdhnx 已提交
1581 1582 1583 1584 1585 1586 1587 1588
}

/**
 * 二级详情页数据解析
 * @param detailObj
 * @returns {string}
 */
function detailParse(detailObj){
H
hjdhnx 已提交
1589
    let t1 = (new Date()).getTime();
H
hjdhnx 已提交
1590
    fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
H
hjdhnx 已提交
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601
    let orId = detailObj.orId;
    let vod_name = '片名';
    let vod_pic = '';
    let vod_id = orId;
    if(rule.二级==='*'){
        // vod_id = orId.split('@@')[0]; // 千万不能分割
        let extra = orId.split('@@');
        vod_name = extra.length>1?extra[1]:vod_name;
        vod_pic = extra.length>2?extra[2]:vod_pic;
    }
    // print(vod_pic);
H
hjdhnx 已提交
1602
    let vod = {
H
hjdhnx 已提交
1603 1604 1605 1606
        vod_id: vod_id, //"id",
        vod_name: vod_name,
        vod_pic: vod_pic,
        type_name: "类型",
H
hjdhnx 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620
        vod_year: "年份",
        vod_area: "地区",
        vod_remarks: "更新信息",
        vod_actor: "主演",
        vod_director: "导演",
        vod_content: "简介"
    };
    let p = detailObj.二级;
    let url = detailObj.url;
    let detailUrl = detailObj.detailUrl;
    let fyclass = detailObj.fyclass;
    let tab_exclude = detailObj.tab_exclude;
    let html = detailObj.html||'';
    MY_URL = url;
H
hjdhnx 已提交
1621
    // console.log(MY_URL);
H
hjdhnx 已提交
1622 1623 1624 1625 1626 1627
    // setItem('MY_URL',MY_URL);
    if(p==='*'){
        vod.vod_play_from = '道长在线';
        vod.vod_remarks = detailUrl;
        vod.vod_actor = '没有二级,只有一级链接直接嗅探播放';
        vod.vod_content = MY_URL;
H
hjdhnx 已提交
1628
        vod.vod_play_url = '嗅探播放$' + MY_URL.split('@@')[0];
H
hjdhnx 已提交
1629 1630 1631
    }else if(typeof(p)==='string'&&p.trim().startsWith('js:')){
        const TYPE = 'detail';
        var input = MY_URL;
H
hjdhnx 已提交
1632
        var play_url = '';
H
hjdhnx 已提交
1633
        eval(p.trim().replace('js:',''));
1634
        vod = VOD;
H
hjdhnx 已提交
1635
        console.log(JSON.stringify(vod));
H
hjdhnx 已提交
1636
    }else if(p&&typeof(p)==='object'){
H
hjdhnx 已提交
1637
        let tt1 = (new Date()).getTime();
H
hjdhnx 已提交
1638 1639 1640
        if(!html){
            html = getHtml(MY_URL);
        }
H
hjdhnx 已提交
1641
        print(`二级${MY_URL}仅获取源码耗时:${(new Date()).getTime()-tt1}毫秒`);
1642
        let _impJQP = false;
H
hjdhnx 已提交
1643 1644
        let _ps;
        if(p.is_json){
H
hjdhnx 已提交
1645
            print('二级是json');
H
hjdhnx 已提交
1646
            _ps = parseTags.json;
H
hjdhnx 已提交
1647
            html = dealJson(html);
H
hjdhnx 已提交
1648
        }else if(p.is_jsp){
H
hjdhnx 已提交
1649
            print('二级是jsp');
H
hjdhnx 已提交
1650 1651
            _ps = parseTags.jsp;
        }else if(p.is_jq){
H
hjdhnx 已提交
1652
            print('二级是jq');
H
hjdhnx 已提交
1653 1654
            _ps = parseTags.jq;
        }else{
H
hjdhnx 已提交
1655
            print('二级默认jq');
H
hjdhnx 已提交
1656
            _ps = parseTags.jq;
1657
            // print('二级默认jsp');
H
hjdhnx 已提交
1658
            // _ps = parseTags.jsp;
H
hjdhnx 已提交
1659
        }
1660 1661 1662 1663
        if(_ps === parseTags.jq){ // jquery解析提前load(html)
            _impJQP = true;
        }
        if (_impJQP) {
H
hjdhnx 已提交
1664
            let ttt1 = (new Date()).getTime();
H
hjdhnx 已提交
1665
            let c$ = cheerio.load(html);
H
hjdhnx 已提交
1666 1667 1668
            // print(`二级${MY_URL}仅c$源码耗时:${(new Date()).getTime()-ttt1}毫秒`);
            html = { rr: c$, ele: c$('html')[0] };
            print(`二级${MY_URL}仅cheerio.load源码耗时:${(new Date()).getTime()-ttt1}毫秒`);
H
hjdhnx 已提交
1669
        }
H
hjdhnx 已提交
1670 1671
        let tt2 = (new Date()).getTime();
        print(`二级${MY_URL}获取并装载源码耗时:${tt2-tt1}毫秒`);
H
hjdhnx 已提交
1672 1673 1674
        _pdfa = _ps.pdfa;
        _pdfh = _ps.pdfh;
        _pd = _ps.pd;
H
hjdhnx 已提交
1675 1676
        if(p.title){
            let p1 = p.title.split(';');
H
hjdhnx 已提交
1677 1678
            vod.vod_name = _pdfh(html, p1[0]).replace(/\n|\t/g,'').trim();
            let type_name = p1.length > 1 ? _pdfh(html, p1[1]).replace(/\n|\t/g,'').replace(/ /g,'').trim():'';
H
hjdhnx 已提交
1679 1680 1681 1682 1683
            vod.type_name = type_name||vod.type_name;
        }
        if(p.desc){
            try{
                let p1 = p.desc.split(';');
H
hjdhnx 已提交
1684 1685 1686 1687 1688 1689
                vod.vod_remarks =  _pdfh(html, p1[0]).replace(/\n|\t/g,'').trim();
                vod.vod_year = p1.length > 1 ? _pdfh(html, p1[1]).replace(/\n|\t/g,'').trim():'';
                vod.vod_area = p1.length > 2 ? _pdfh(html, p1[2]).replace(/\n|\t/g,'').trim():'';
                // vod.vod_actor = p1.length > 3 ? _pdfh(html, p1[3]).replaceAll('\n', ' ').trim():'';
                vod.vod_actor = p1.length > 3 ? _pdfh(html, p1[3]).replace(/\n|\t/g,'').trim():'';
                vod.vod_director = p1.length > 4 ? _pdfh(html, p1[4]).replace(/\n|\t/g,'').trim():'';
H
hjdhnx 已提交
1690 1691 1692 1693 1694 1695 1696 1697
            }
            catch (e) {

            }
        }
        if(p.content){
            try{
                let p1 = p.content.split(';');
H
hjdhnx 已提交
1698
                vod.vod_content =  _pdfh(html, p1[0]).replace(/\n|\t/g,'').trim();
H
hjdhnx 已提交
1699 1700 1701 1702 1703 1704
            }
            catch (e) {}
        }
        if(p.img){
            try{
                let p1 = p.img.split(';');
H
hjdhnx 已提交
1705
                vod.vod_pic =  _pd(html, p1[0],MY_URL);
H
hjdhnx 已提交
1706 1707 1708 1709 1710 1711 1712
            }
            catch (e) {}
        }

        let vod_play_from = '$$$';
        let playFrom = [];
        if(p.重定向&&p.重定向.startsWith('js:')){
1713
            print('开始执行重定向代码:'+p.重定向);
H
hjdhnx 已提交
1714
            html = eval(p.重定向.replace('js:',''));
H
hjdhnx 已提交
1715 1716 1717 1718
            if (_impJQP) {
                let c$ = cheerio.load(html);
                html = { rr: c$, ele: c$('html')[0] }
            }
H
hjdhnx 已提交
1719 1720 1721 1722
        }
        
// console.log(2);
        if(p.tabs){
H
hjdhnx 已提交
1723 1724
            if(p.tabs.startsWith('js:')){
                print('开始执行tabs代码:'+p.tabs);
1725
                if(html&&_impJQP&&typeof (html)!=='string'){
H
升级  
hjdhnx 已提交
1726 1727 1728
                    try { // 假装是jq的对象拿来转换一下字符串,try为了防止json的情况报错
                        html = html.rr(html.ele).toString();
                    }catch (e) {}
H
hjdhnx 已提交
1729 1730 1731 1732 1733 1734
                }
                var input = MY_URL;
                eval(p.tabs.replace('js:',''));
                playFrom = TABS;
            }else{
                let p_tab = p.tabs.split(';')[0];
H
hjdhnx 已提交
1735
                // console.log(p_tab);
H
hjdhnx 已提交
1736 1737
                let vHeader = _pdfa(html, p_tab);
                console.log(vHeader.length);
H
hjdhnx 已提交
1738 1739
                let tab_text = p.tab_text||'body&&Text';
                // print('tab_text:'+tab_text);
H
hjdhnx 已提交
1740
                for(let v of vHeader){
H
hjdhnx 已提交
1741
                    let v_title = _pdfh(v,tab_text).trim();
H
hjdhnx 已提交
1742 1743 1744 1745 1746
                    console.log(v_title);
                    if(tab_exclude&& (new RegExp(tab_exclude)).test(v_title)){
                        continue;
                    }
                    playFrom.push(v_title);
H
hjdhnx 已提交
1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
                }
            }
            console.log(JSON.stringify(playFrom));
        }else{
            playFrom = ['道长在线']
        }
        vod.vod_play_from = playFrom.join(vod_play_from);

// console.log(3);
        let vod_play_url = '$$$';
        let vod_tab_list = [];
        if(p.lists){
H
hjdhnx 已提交
1759 1760
            if(p.lists.startsWith('js:')){
                print('开始执行lists代码:'+p.lists);
H
hjdhnx 已提交
1761
                try {
1762
                    if(html&&_impJQP&&typeof (html)!=='string'){
H
hjdhnx 已提交
1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783
                        // 假装是jq的对象拿来转换一下字符串,try为了防止json的情况报错
                        try {
                            html = html.rr(html.ele).toString();
                        }catch (e) {}
                    }
                    var input = MY_URL;
                    var play_url = '';
                    eval(p.lists.replace('js:',''));
                    for(let i in LISTS){
                        if(LISTS.hasOwnProperty(i)){
                            // print(i);
                            try {
                                LISTS[i] = LISTS[i].map(it=>it.split('$').slice(0,2).join('$'));
                            }catch (e) {
                                print('格式化LISTS发生错误:'+e.message);
                            }
                        }
                    }
                    vod_play_url = LISTS.map(it=>it.join('#')).join(vod_play_url);
                }catch (e) {
                    print('js执行lists: 发生错误:'+e.message);
H
hjdhnx 已提交
1784
                }
H
hjdhnx 已提交
1785

H
hjdhnx 已提交
1786
            }else{
H
hjdhnx 已提交
1787 1788 1789 1790
                let list_text = p.list_text||'body&&Text';
                let list_url = p.list_url||'a&&href';
                // print('list_text:'+list_text);
                // print('list_url:'+list_url);
H
md  
hjdhnx 已提交
1791
                // print('list_parse:'+p.lists);
H
hjdhnx 已提交
1792
                let is_tab_js = p.tabs.trim().startsWith('js:');
H
hjdhnx 已提交
1793 1794
                for(let i=0;i<playFrom.length;i++){
                    let tab_name = playFrom[i];
H
hjdhnx 已提交
1795
                    let tab_ext =  p.tabs.split(';').length > 1 && !is_tab_js ? p.tabs.split(';')[1] : '';
H
hjdhnx 已提交
1796 1797
                    let p1 = p.lists.replaceAll('#idv', tab_name).replaceAll('#id', i);
                    tab_ext = tab_ext.replaceAll('#idv', tab_name).replaceAll('#id', i);
1798
                    // 测试jsp提速
H
hjdhnx 已提交
1799
                    // console.log(p1);
H
hjdhnx 已提交
1800 1801
                    // p1 = p1.replace(':eq(0)',',0').replace(' ','&&');
                    // console.log(p1);
H
hjdhnx 已提交
1802 1803 1804 1805 1806 1807 1808 1809 1810
                    // console.log(html);
                    let vodList = [];
                    try {
                        vodList =  _pdfa(html, p1);
                        console.log('len(vodList):'+vodList.length);
                    }catch (e) {
                        // console.log(e.message);
                    }
                    let new_vod_list = [];
H
hjdhnx 已提交
1811
                    // print('tab_ext:'+tab_ext);
H
hjdhnx 已提交
1812 1813 1814
                    let tabName = tab_ext?_pdfh(html, tab_ext):tab_name;
                    console.log(tabName);
                    // console.log('cheerio解析Text');
H
hjdhnx 已提交
1815 1816 1817 1818
                    // 此处存在性能问题: pt版2000集需要650毫秒,俊版1300毫秒 特么的优化不动 主要后面定位url的我拿他没法
                    // 主要性能问题在于 _pd(it, list_url, MY_URL)
                    let tt1 = (new Date()).getTime();
                    vodList.forEach((it,idex)=>{
H
hjdhnx 已提交
1819 1820 1821
                        // 请注意,这里要固定pdfh解析body&&Text,不需要下划线,没写错
                        // new_vod_list.push(pdfh(it,'body&&Text')+'$'+_pd(it,'a&&href',MY_URL));
                        // new_vod_list.push(cheerio.load(it).text()+'$'+_pd(it,'a&&href',MY_URL));
H
hjdhnx 已提交
1822
                        // new_vod_list.push(_pdfh(it, list_text).trim() + '$' + _pd(it, list_url, MY_URL));
H
hjdhnx 已提交
1823 1824 1825
                        // new_vod_list.push(_pdfh(it, list_text).trim() + '$' +idex);
                        // new_vod_list.push(idex + '$' +_pdfh(it, list_url));
                        new_vod_list.push(_pdfh(it, list_text).trim() + '$' +_pd(it, list_url,MY_URL));
H
hjdhnx 已提交
1826
                    });
H
log  
hjdhnx 已提交
1827 1828 1829
                    if(vodList.length>0){
                        console.log(`drpy影响性能代码共计列表数循环次数:${vodList.length},耗时:${(new Date()).getTime()-tt1}毫秒`);
                    }
H
hjdhnx 已提交
1830 1831 1832 1833
                    let vlist = new_vod_list.join('#');
                    vod_tab_list.push(vlist);
                }
                vod_play_url = vod_tab_list.join(vod_play_url);
H
hjdhnx 已提交
1834 1835
            }
        }
H
hjdhnx 已提交
1836
        vod.vod_play_url = vod_play_url;
H
hjdhnx 已提交
1837
    }
H
hjdhnx 已提交
1838 1839 1840
    if(rule.图片来源 && vod.vod_pic && vod.vod_pic.startsWith('http')){
        vod.vod_pic = vod.vod_pic + rule.图片来源;
    }
H
hjdhnx 已提交
1841
    if(!vod.vod_id){
H
hjdhnx 已提交
1842
        vod.vod_id = vod_id;
H
hjdhnx 已提交
1843
    }
H
hjdhnx 已提交
1844 1845
    let t2 = (new Date()).getTime();
    console.log(`加载二级界面${MY_URL}耗时:${t2-t1}毫秒`);
H
hjdhnx 已提交
1846
    // print(vod);
H
hjdhnx 已提交
1847 1848 1849 1850 1851
    return JSON.stringify({
        list: [vod]
    })
}

1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
/**
 * 判断是否需要解析
 * @param url
 * @returns {number|number}
 */
function tellIsJx(url){
    try {
        let is_vip = !/\.(m3u8|mp4|m4a)$/.test(url.split('?')[0]) && 是否正版(url);
        return is_vip?1:0
    }catch (e) {
        return 1
    }
}
H
hjdhnx 已提交
1865 1866 1867 1868 1869 1870
/**
 * 选集播放点击事件解析
 * @param playObj
 * @returns {string}
 */
function playParse(playObj){
H
hjdhnx 已提交
1871
    fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
H
hjdhnx 已提交
1872
    MY_URL = playObj.url;
H
hjdhnx 已提交
1873 1874 1875 1876 1877 1878 1879
    if(!/http/.test(MY_URL)){
        try {
            MY_URL = base64Decode(MY_URL);
        }catch (e) {}
    }
    MY_URL = decodeURIComponent(MY_URL);
    var input = MY_URL;//注入给免嗅js
H
hjdhnx 已提交
1880 1881
    let common_play = {
        parse:1,
1882
        url:input,
H
hjdhnx 已提交
1883
        // url:urlencode(input),
1884
        jx:tellIsJx(input)
H
hjdhnx 已提交
1885 1886 1887 1888 1889 1890
    };
    let lazy_play;
    if(!rule.play_parse||!rule.lazy){
        lazy_play =  common_play;
    }else if(rule.play_parse&&rule.lazy&&typeof(rule.lazy)==='string'){
        try {
H
hjdhnx 已提交
1891 1892 1893
            let lazy_code = rule.lazy.replace('js:','').trim();
            print('开始执行js免嗅=>'+lazy_code);
            eval(lazy_code);
H
hjdhnx 已提交
1894 1895
            lazy_play = typeof(input) === 'object'?input:{
                parse:1,
1896
                jx:tellIsJx(input),
H
hjdhnx 已提交
1897 1898 1899
                url:input
            };
        }catch (e) {
H
hjdhnx 已提交
1900
            print('js免嗅错误:'+e.message);
H
hjdhnx 已提交
1901 1902 1903 1904 1905
            lazy_play =  common_play;
        }
    }else{
        lazy_play =  common_play;
    }
H
升级  
hjdhnx 已提交
1906 1907
    // print('play_json:'+typeof(rule.play_json));
    // console.log(Array.isArray(rule.play_json));
H
hjdhnx 已提交
1908 1909 1910 1911 1912 1913
    if(Array.isArray(rule.play_json) && rule.play_json.length >0){ // 数组情况判断长度大于0
        let web_url = lazy_play.url;
        for(let pjson of rule.play_json){
            if(pjson.re && (pjson.re==='*'||web_url.match(new RegExp(pjson.re)))){
                if(pjson.json && typeof(pjson.json)==='object'){
                    let base_json = pjson.json;
H
升级  
hjdhnx 已提交
1914 1915
                    // print('开始合并:');
                    // print(base_json);
H
hjdhnx 已提交
1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933
                    lazy_play = Object.assign(lazy_play,base_json);
                    break;
                }
            }
        }
    }else if(rule.play_json && !Array.isArray(rule.play_json)){ // 其他情况 非[] 判断true/false
        let base_json = {
            jx:1,
            parse:1,
        };
        lazy_play = Object.assign(lazy_play,base_json);
    }else if(!rule.play_json){ // 不解析传0
        let base_json = {
            jx:0,
            parse:1,
        };
        lazy_play = Object.assign(lazy_play,base_json);
    }
H
hjdhnx 已提交
1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
    console.log(JSON.stringify(lazy_play));
    return JSON.stringify(lazy_play);
}

/**
 * js源预处理特定返回对象中的函数
 * @param ext
 */
 function init(ext) {
    console.log('init');
    try {
H
hjdhnx 已提交
1945 1946 1947 1948 1949 1950 1951 1952
        // make shared jsContext happy muban不能import,不然会造成换源继承后变量被篡改
        if (typeof (globalThis.mubanJs) === 'undefined') {
            let mubanJs = request('https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/模板.js', { 'User-Agent': MOBILE_UA });
            mubanJs = mubanJs.replace('export default', '(function() {return muban;}()) // export default');
            // console.log(mubanJs);
            globalThis.mubanJs = mubanJs;
        }
        let muban = eval(globalThis.mubanJs);
H
hjdhnx 已提交
1953 1954 1955 1956 1957
        if (typeof ext == 'object'){
            rule = ext;
        } else if (typeof ext == 'string') {
            if (ext.startsWith('http')) {
                let js = request(ext,{'method':'GET'});
H
hjdhnx 已提交
1958 1959 1960 1961
                if (js){
                    eval(js.replace('var rule', 'rule'));
                }
                }
H
hjdhnx 已提交
1962 1963 1964 1965 1966 1967 1968
        } else {
            eval(ext.replace('var rule', 'rule'));
        }
        if (rule.模板 && muban.hasOwnProperty(rule.模板)) {
            print('继承模板:'+rule.模板);
            rule = Object.assign(muban[rule.模板], rule);
        }
H
hjdhnx 已提交
1969 1970 1971 1972 1973 1974 1975 1976
        /** 处理一下 rule规则关键字段没传递的情况 **/
        let rule_cate_excludes = (rule.cate_exclude||'').split('|').filter(it=>it.trim());
        let rule_tab_excludes = (rule.tab_exclude||'').split('|').filter(it=>it.trim());
        rule_cate_excludes = rule_cate_excludes.concat(CATE_EXCLUDE.split('|').filter(it=>it.trim()));
        rule_tab_excludes = rule_tab_excludes.concat(TAB_EXCLUDE.split('|').filter(it=>it.trim()));

        rule.cate_exclude = rule_cate_excludes.join('|');
        rule.tab_exclude = rule_tab_excludes.join('|');
H
hjdhnx 已提交
1977
        rule.host = (rule.host||'').rstrip('/');
H
hjdhnx 已提交
1978
        rule.url = rule.url||'';
H
hjdhnx 已提交
1979
        rule.double = rule.double||false;
H
hjdhnx 已提交
1980
        rule.homeUrl = rule.homeUrl||'';
1981
        rule.detailUrl = rule.detailUrl||'';
H
hjdhnx 已提交
1982
        rule.searchUrl = rule.searchUrl||'';
1983 1984
        rule.homeUrl = rule.host&&rule.homeUrl?urljoin(rule.host,rule.homeUrl):(rule.homeUrl||rule.host);
        rule.detailUrl = rule.host&&rule.detailUrl?urljoin(rule.host,rule.detailUrl):rule.detailUrl;
H
hjdhnx 已提交
1985 1986 1987 1988 1989 1990 1991 1992 1993
        if(rule.url.includes('[')&&rule.url.includes(']')){
            let u1 = rule.url.split('[')[0]
            let u2 = rule.url.split('[')[1].split(']')[0]
            rule.url = rule.host && rule.url?urljoin(rule.host,u1)+'['+urljoin(rule.host,u2)+']':rule.url;
        }else{
            rule.url = rule.host && rule.url ? urljoin(rule.host,rule.url) : rule.url;
        }
        rule.searchUrl = rule.host && rule.searchUrl ? urljoin(rule.host,rule.searchUrl) : rule.searchUrl;

H
hjdhnx 已提交
1994 1995
        rule.timeout = rule.timeout||5000;
        rule.encoding = rule.编码||rule.encoding||'utf-8';
H
hjdhnx 已提交
1996
        rule.图片来源 = rule.图片来源||'';
H
hjdhnx 已提交
1997
        rule.play_json = rule.hasOwnProperty('play_json')?rule.play_json:[];
H
hjdhnx 已提交
1998
        if(rule.headers && typeof(rule.headers) === 'object'){
H
hjdhnx 已提交
1999 2000 2001 2002 2003 2004 2005 2006 2007
            try {
                let header_keys = Object.keys(rule.headers);
                for(let k of header_keys){
                    if(k.toLowerCase() === 'user-agent'){
                        let v = rule.headers[k];
                        console.log(v);
                        if(['MOBILE_UA','PC_UA','UC_UA','IOS_UA','UA'].includes(v)){
                            rule.headers[k] = eval(v);
                        }
H
hjdhnx 已提交
2008 2009
                    }
                }
H
hjdhnx 已提交
2010 2011
            }catch (e) {
                console.log('处理headers发生错误:'+e.message);
H
hjdhnx 已提交
2012 2013
            }
        }
H
hjdhnx 已提交
2014 2015
        // print(rule.headers);
        rule_fetch_params  = {'headers': rule.headers||false, 'timeout': rule.timeout, 'encoding': rule.encoding};
H
hjdhnx 已提交
2016
        oheaders = rule.headers||{};
H
hjdhnx 已提交
2017
        RKEY = typeof(key)!=='undefined'&&key?key:'drpy_' + (rule.title || rule.host);
H
hjdhnx 已提交
2018
        pre(); // 预处理
H
hjdhnx 已提交
2019
        init_test();
H
hjdhnx 已提交
2020 2021 2022 2023 2024
    }catch (e) {
        console.log('init_test发生错误:'+e.message);
    }
}

H
hjdhnx 已提交
2025 2026
let homeHtmlCache = undefined;

H
hjdhnx 已提交
2027 2028 2029 2030 2031 2032 2033 2034 2035
/**
 * js源获取首页分类和筛选特定返回对象中的函数
 * @param filter 筛选条件字典对象
 * @returns {string}
 */
function home(filter) {
    console.log("home");
    let homeObj = {
        filter:rule.filter||false,
H
hjdhnx 已提交
2036
        MY_URL: rule.homeUrl,
H
hjdhnx 已提交
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050
        class_name: rule.class_name || '',
        class_url: rule.class_url || '',
        class_parse: rule.class_parse || '',
        cate_exclude: rule.cate_exclude,
    };
    return homeParse(homeObj);
}

/**
 * js源获取首页推荐数据列表特定返回对象中的函数
 * @param params
 * @returns {string}
 */
function homeVod(params) {
H
hjdhnx 已提交
2051
    console.log("homeVod");
H
hjdhnx 已提交
2052 2053 2054
    let homeVodObj = {
        推荐:rule.推荐,
        double:rule.double,
2055 2056
        homeUrl:rule.homeUrl,
        detailUrl:rule.detailUrl
H
hjdhnx 已提交
2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071
    };
    return homeVodParse(homeVodObj)
    // return "{}";
}

/**
 * js源获取分类页一级数据列表特定返回对象中的函数
 * @param tid 分类id
 * @param pg 页数
 * @param filter 当前选中的筛选条件
 * @param extend 扩展
 * @returns {string}
 */
function category(tid, pg, filter, extend) {
    let cateObj = {
H
hjdhnx 已提交
2072
        url: rule.url,
H
hjdhnx 已提交
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088
        一级: rule.一级,
        tid: tid,
        pg: parseInt(pg),
        filter: filter,
        extend: extend
    };
    // console.log(JSON.stringify(extend));
    return categoryParse(cateObj)
}

/**
 * js源获取二级详情页数据特定返回对象中的函数
 * @param vod_url 一级列表中的vod_id或者是带分类的自拼接 vod_id 如 fyclass$vod_id
 * @returns {string}
 */
function detail(vod_url) {
H
hjdhnx 已提交
2089
    let orId = vod_url;
H
hjdhnx 已提交
2090 2091 2092 2093 2094 2095
    let fyclass = '';
    if(vod_url.indexOf('$')>-1){
        let tmp = vod_url.split('$');
        fyclass = tmp[0];
        vod_url = tmp[1];
    }
H
hjdhnx 已提交
2096
    let detailUrl = vod_url.split('@@')[0];
H
hjdhnx 已提交
2097 2098 2099 2100 2101 2102 2103 2104 2105
    let url;
    if(!detailUrl.startsWith('http')&&!detailUrl.includes('/')){
        url = rule.detailUrl.replaceAll('fyid', detailUrl).replaceAll('fyclass',fyclass);
    }else if(detailUrl.includes('/')){
        url = urljoin(rule.homeUrl,detailUrl);
    }else{
        url = detailUrl
    }
    let detailObj = {
H
hjdhnx 已提交
2106
        orId: orId,
H
hjdhnx 已提交
2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139
        url:url,
        二级:rule.二级,
        detailUrl:detailUrl,
        fyclass:fyclass,
        tab_exclude:rule.tab_exclude,
    }
    return detailParse(detailObj)
}

/**
 * js源选集按钮播放点击事件特定返回对象中的函数
 * @param flag 线路名
 * @param id 播放按钮的链接
 * @param flags 全局配置的flags是否需要解析的标识列表
 * @returns {string}
 */
function play(flag, id, flags) {
    let playObj = {
        url:id,
        flag:flag,
        flags:flags
    }
    return playParse(playObj);
}

/**
 * js源搜索返回的数据列表特定返回对象中的函数
 * @param wd 搜索关键字
 * @param quick 是否来自快速搜索
 * @returns {string}
 */
function search(wd, quick) {
    let searchObj = {
H
hjdhnx 已提交
2140
        searchUrl: rule.searchUrl,
H
hjdhnx 已提交
2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173
        搜索: rule.搜索,
        wd: wd,
        //pg: pg,
        pg: 1,
        quick: quick,
    };
    // console.log(JSON.stringify(searchObj));
    return searchParse(searchObj)
}

function DRPY(){//导出函数
    return {
        init: init,
        home: home,
        homeVod: homeVod,
        category: category,
        detail: detail,
        play: play,
        search: search,
    }
}

// 导出函数对象
export default {
    init: init,
    home: home,
    homeVod: homeVod,
    category: category,
    detail: detail,
    play: play,
    search: search,
    DRPY:DRPY
}