/*
@header({
  searchable: 2,
  filterable: 1,
  quickSearch: 0,
  title: '素白白',
  lang: 'ds'
})
*/

// http://localhost:5757/api/素白白?ac=list&t=movie_bt&pg=1
// http://localhost:5757/api/素白白?ac=detail&ids=57235
// http://localhost:5757/api/素白白?wd=我的&pg=1
// http://localhost:5757/api/素白白?play=bXZfNTcyMzUtbm1fMQ%3D%3D&flag=由qq倾情打造
const {getHtml} = $.require('./_lib.request.js')
var rule = {
    类型: '影视',
    title: '素白白',
    desc: '素白白纯js版本',
    host: 'https://www.subaibaiys.com',
    homeUrl: '',
    url: '',
    searchUrl: '/page/fypage?s=**',
    searchable: 2,
    quickSearch: 0,
    timeout: 5000,
    play_parse: true,
    filterable: 1,
    filter_url: '{{fl.class || fl.area || fl.year || fl.catedd}}',
    filter: 'H4sIAAAAAAAAA+2dWVPbyBbHvwvPQ0UmYHvmS9x5vzU11djC1mBLjhYIpKYqTICwJcCEgRD2JCxJIGxZwGxfxpLsb3GPjKUjaB9zU8V9uFXnIRms/veif3efPv1zMnnSVjT6NPX3brvtl38/aetVB9p+acsIW81m235q00VRhc/u2Kh/eAaf+0TBUetCPXg8slN7thM8hg9tf/70pP7Dg7DB3y3V1FTrQdbQc0Wh/+EEDQbVJna880/u+PadVbIDN6r4c1/di0O61oCmZx2s8+LALW/dVSfnGJl8fHBLF5XydsvBNapgR/Uqd3VkalEf3sJmyw5MLd48qGtrH+5q3nCKaqyH3W3/8mXLTuoVsJN6hbs6sUWsi+ODlu3beRFrHsRLF3fOhdBz2P7JvjvduotAb8d7qVe5q5eskYFX121hhvX88kf34h9//DldaRAW5IAW6s/Oq+NlWhxfTzB1Ld/hsQYvEbxI9Ba1rUV4Ef9s2h05Cd/lt6B+Y28WhGXh1oR96a5O/vDWtEXOelAySu3wyykIs9H3r//61fs6VN2Yoqp0a0bOFKV8ONjK+Xr18wGlzuS1QjbcJcNX/qdNSimyfTAljqmG6tG/a4sfyIEXDDsUjm97z0bIZjO2ZugYRCoXy6RU14rqjXD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YODBxYOLAxIGJAxMHJg5MHJg4MHG4R+Lw538AfqGHU+THAAA=',
    headers: {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Cache-Control': 'no-cache',
        'Pragma': 'no-cache',
        'Referer': 'https://www.subaibaiys.com/',
        'Upgrade-Insecure-Requests': '1',
    },
    class_parse: async () => {
        return {
            class: [{type_id: "movie_bt", type_name: "影视筛选"}, {
                type_id: "new-movie",
                type_name: "电影"
            }, {type_id: "tv-drama", type_name: "电视剧"}, {
                type_id: "hot-month",
                type_name: "热门电影"
            }, {type_id: "high-movie", type_name: "高分电影"}, {
                type_id: "cartoon-movie",
                type_name: "动漫电影"
            }, {type_id: "hongkong-movie", type_name: "香港经典电影"}, {
                type_id: "domestic-drama",
                type_name: "国产剧"
            }, {type_id: "american-drama", type_name: "欧美剧"}, {
                type_id: "korean-drama",
                type_name: "韩剧"
            }, {type_id: "anime-drama", type_name: "动漫剧"}, {
                type_id: "marvel-movies",
                type_name: "漫威宇宙电影系列"
            }, {type_id: "fastfurious", type_name: "速度与激情电影系列"}, {
                type_id: "zero-zero-seven",
                type_name: "007系列(25部正传+2部外传)"
            }],
        }
    },
    预处理: async () => {
        return []
    },
    推荐: async () => {
        return []
    },
    一级: async function (tid, pg, filter, extend) {
        let {MY_CATE, input} = this;
        if (pg <= 0) pg = 1;
        const html = (await getHtml({
            url: rule.host + "/" + (extend.class || tid) + (extend.area || "") + (extend.year || "") + (extend.catedd || "") + "/page/" + pg,
            headers: rule.headers
        })).data
        const $ = pq(html);
        let videos = []
        for (const item of $("div.bt_img > ul > li")) {
            const img = $(item).find("img:first")[0],
                a = $(item).find("a:first")[0],
                hdinfo = $($(item).find("div.hdinfo")[0]).text().trim(),
                remark = $($(item).find("div.jidi")[0]).text().trim();
            videos.push({
                vod_id: a.attribs.href.replace(/.*?\/movie\/(.*).html/g, "$1"),
                vod_name: img.attribs.alt,
                vod_pic: img.attribs["data-original"],
                vod_remarks: remark || hdinfo || ""
            })
        }
        return videos
    },
    二级: async function (ids) {
        let {input} = this;
        const html = (await getHtml({
            url: rule.host + "/movie/" + ids[0] + ".html",
            headers: rule.headers
        })).data
        const $ = pq(html);
        const html_js = $("ul.moviedteail_list > li");
        let vod = {
            vod_id: ids[0],
            vod_pic: $("div.dyimg img:first").attr("src"),
            vod_remarks: "",
            vod_content: misc.stripHtmlTag($("div.yp_context").html()).trim()
        };
        const playlist = $('div.paly_list_btn > a').map((_, a) => {
            return a.children[0].data + '$' + a.attribs.href.replace(/.*?\/v_play\/(.*).html/g, '$1');
        }).get();
        let playFroms = [];
        playFroms.push('由qq倾情打造');
        vod.vod_play_from = playFroms.join('$$$');
        vod.vod_play_url = playlist.join("#");
        return vod
    },
    搜索: async function (wd, quick, pg) {
        let {input} = this
        const html = await request(input);
        const $ = pq(html);
        let videos = []
        for (const item of $("div.search_list > ul > li")) {
            const img = $(item).find("img:first")[0],
                a = $(item).find("a:first")[0],
                hdinfo = $($(item).find("div.hdinfo")[0]).text().trim(),
                remark = $($(item).find("div.jidi")[0]).text().trim();
            videos.push({
                vod_id: a.attribs.href.replace(/.*?\/movie\/(.*).html/g, "$1"),
                vod_name: img.attribs.alt,
                vod_pic: img.attribs["data-original"],
                vod_remarks: remark || hdinfo || ""
            })
        }
        return videos
    },
    lazy: async function (flag, id, flags) {
        let {input} = this;
        const link = rule.host + "/v_play/" + id + ".html"
        const html = (await getHtml({
            url: link,
            headers: rule.headers
        })).data
        const $ = pq(html)
        const js = $('script:contains(window.wp_nonce)').html();
        const group = js.match(/(var.*)eval\((\w*\(\w*\))\)/);
        const result = eval('md5 = CryptoJS;' + group[1] + group[2]);
        const play_url = result.match(/url:.*?['"](.*?)['"]/)[1];
        return {parse: 0, url: play_url}
    },
};
