/*
@header({
  searchable: 1,
  filterable: 1,
  quickSearch: 0,
  title: '好乐影视',
  lang: 'ds'
})
*/

var rule = {
    类型: '影视',
    title: '好乐影视',
    host: 'https://www.haolev.com',
    url: '/haoshow/fyfilter',
    searchUrl: '/lesearch/**----------fypage---.html',
    headers: {'User-Agent': 'MOBILE_UA'},
    searchable: 1, quickSearch: 0, filterable: 1, play_parse: true, double: false, limit: 6,
    filter_url: '{{fl.cateId}}-{{fl.area}}-{{fl.by}}-{{fl.class}}-----fypage---{{fl.year}}.html',
    filter_def: {
        '1': {cateId: '1'}, '2': {cateId: '2'}, '3': {cateId: '3'}, '4': {cateId: '4'}
    },
    class_name: '电影&电视剧&动漫&综艺',
    class_url: '1&2&4&3',
    filter: 'H4sIAAAAAAAAA+2Zy04bSRSG9/MYXrOohtwmrzLKwhNZSpRMRoJMJBQhQcDEBgcbROw4OEDENYRLcxkwDbZfxlVtv8WUXVXnnJ4hx42HRRbe+T+nbn91ddXX5bcJL/H4t7eJF6nxxOPE05fJsbHEUOJV8o+UljK7o6bTWr9Jvvwr1S33qhNO77andzthLRITQzY6t9usVWzUCsgVK7otlzPC5cKdRXl5ZXNWuJyaKqjJos1ZAfUyx3ZwKKA/GDgKaDPzqRlkXZtGuFzr0Je1jzZnBfEXLl+hv46ANqfn1LvPrk0jYJxzR2Ftz43TCKj3bj8sLrp6RkB/s0vt8jfXnxGQ23qPc2YF5A7PZXDgckZAbmFW5k9czgiXa16va8c2ZwXUy2+2NmA+jXC59tpp87Jgc1ZAvUJOTcJzNwLmulHQs+jm2giYl4PtZn3dzYsRMJ9rB2H2vZtPI7BerpVZhXpdAf1tNXDVWgHjnGmE37fcOI2A/qbq7c91158RuJbyauUE1lJXQL3KWjMIwp1JVxU0zNyXJfXJ9WrFxJNO1ryNydFUkryMFV/mgrgv4+ZOuzzrDBkB3W6XVfXIdWsEPmhfXdbhQXcFGKovyJWac2METERpS1X23UQYgQvkG9azAh7K/DHmrIA2Tz9izgoYZ/0Cc1Z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8S4+7s2DtJ7r6L++++vtDeWMMjvCN+YlLhaISjmH5Jhf2nkqOYGDdWDAvcwa1UjFu1u7i36u/OacA1A64ZcM0NXDPxDyQRoaiuJgAA',
    lazy: async function () {
        let {input, pdfa, pdfh, pd} = this
        const html = JSON.parse((await req(input)).content.match(/r player_.*?=(.*?)</)[1]);
        let url = html.url;
        if (html.encrypt == "1") {
            url = unescape(url)
            return {parse: 0, url: url}
        } else if (html.encrypt == "2") {
            url = unescape(base64Decode(url))
            return {parse: 0, url: url}
        }
        if (/m3u8|mp4/.test(url)) {
            input = url
            return {parse: 0, url: input}
        } else {
            return {parse: 1, url: input}
        }
    },
    推荐: async function () {
        let {input, pdfa, pdfh, pd} = this;
        let html = await request(input);
        let d = [];
        let data = pdfa(html, '.hl-vod-list li');
        data.forEach((it) => {
            d.push({
                title: pdfh(it, 'a&&title'),
                pic_url: pd(it, '.hl-lazy&&data-original'),
                desc: pdfh(it, '.hl-pic-text&&Text'),
                url: pd(it, 'a&&href'),
            })
        });
        return setResult(d)
    },
    一级: async function () {
        let {input, pdfa, pdfh, pd} = this;
        let html = await request(input);
        let d = [];
        let data = pdfa(html, '.hl-vod-list li');
        data.forEach((it) => {
            d.push({
                title: pdfh(it, 'a&&title'),
                pic_url: pd(it, '.hl-lazy&&data-original'),
                desc: pdfh(it, '.hl-pic-text&&Text'),
                url: pd(it, 'a&&href'),
            })
        });
        return setResult(d)
    },
    二级: async function () {
        let {input, pdfa, pdfh, pd} = this;
        let html = await request(input);
        let VOD = {};
        VOD.vod_name = pdfh(html, '.h2&&Text');
        VOD.vod_content = pdfh(html, '.hl-dc-content&&.blurb&&Text');
        let playlist = pdfa(html, '.hl-plays-list')
        let tabs = pdfa(html, '.hl-plays-from.hl-tabs a');
        let playmap = {};
        tabs.map((item, i) => {
            const form = pdfh(item, 'Text')
            const list = playlist[i]
            const a = pdfa(list, 'body&&a:not(:contains(展开))')
            a.map((it) => {
                let title = pdfh(it, 'a&&Text')
                let urls = pd(it, 'a&&href', input)
                if (!playmap.hasOwnProperty(form)) {
                    playmap[form] = [];
                }
                playmap[form].push(title + "$" + urls);
            });
        });
        VOD.vod_play_from = Object.keys(playmap).join('$$$');
        const urls = Object.values(playmap);
        const playUrls = urls.map((urllist) => {
            return urllist.join("#")
        });
        VOD.vod_play_url = playUrls.join('$$$');
        return VOD
    },
    搜索: async function () {
        let {input, pdfa, pdfh, pd} = this;
        let html = await request(input);
        let d = [];
        let data = pdfa(html, '.hl-one-list li');
        data.forEach((it) => {
            d.push({
                title: pdfh(it, '.hl-item-title&&Text'),
                pic_url: pd(it, '.hl-lazy&&data-original'),
                desc: pdfh(it, '.hl-pic-text&&Text'),
                url: pd(it, 'a&&href'),
                content: pdfh(it, '.hl-item-content&&p:eq(0)&&Text'),
            })
        });
        return setResult(d)
    }
}
