var rule = {
    title: '斗鱼直播',
    host: 'https://m.douyu.com',
    homeUrl: '/api/home/mix',//网站的首页链接,用于分类获取和推荐获取
    url: '/api/room/list?page=fypage&type=fyfilter',
    filterable: 1,//是否启用分类筛选,
    filter_url: '{{fl.cateId}}',
    filter: '[encoded data, 18664 characters]',
    filter_def: {
        yl: {cateId: 'yqk'},
        PCgame: {cateId: 'LOL'},
        djry: {cateId: 'TVgame'},
        syxx: {cateId: 'wzry'},
        yz: {cateId: 'yz'},
        kjwh: {cateId: 'smkj'},
        yp: {cateId: 'yiqiwan'},
        voice: {cateId: 'yyzs'},
        znl: {cateId: 'znl'}
    },
    class_name: '娱乐天地&网游竞技&单机热游&手游休闲&颜值&科技文化&语音互动&语音直播&正能量',// /api/cate/list
    class_url: 'yl&PCgame&djry&syxx&yz&kjwh&yp&voice&znl',
    detailUrl: 'http://live.yj1211.work/api/live/getRoomInfo?uid=&platform=douyu&roomId=fyid',// JustLive
    searchUrl: '/api/search/liveRoom?#did=10000000000000000000000000001501&limit=20&offset=0&sk=**;post',
    searchable: 2,
    quickSearch: 0,
    headers: {
        'User-Agent': 'MOBILE_UA'
    },
    timeout: 5000,
    limit: 8,
    play_parse: true,
    lazy: '',
    推荐: `js:
        let d = [];
        let jo = JSON.parse(request(input)).data;
        jo.forEach((it,idex) => {
            let slist = jo[idex].list ;
            slist.forEach(it => {
                d.push({
                    url: it.rid,
                    title: it.roomName,
                    img: it.roomSrc,
                    desc: '👁' + it.hn + '  🆙' + it.nickname,
                })
            });
        });
        setResult(d);
    `,
    一级: `js:
        let d = [];
        let jo = JSON.parse(request(input)).data.list;
        jo.forEach(it => {
            d.push({
                url: it.rid,
                title: it.roomName,
                img: it.roomSrc,
                desc: '👁' + it.hn + '  🆙' + it.nickname,
            })
        });
        setResult(d);
    `,
    二级: `js:
    try {
        if (typeof play_url === "undefined") {
            var play_url = ""
        }
        var jo = JSON.parse(request(input)).data;
        VOD = {
            vod_id: jo.roomId,
            vod_name: jo.roomName,
            vod_pic: jo.roomPic,
            type_name: "斗鱼." + jo.categoryName,
            vod_director: '🆙 ' + jo.ownerName,
            vod_content: "🏷分区：斗鱼" + "·" + jo.categoryName + " 🏷UP主：" + jo.ownerName + " 🏷人气：" + jo.online + (jo.isLive === 1 ? " 🏷状态：正在直播" : "状态：未开播")
        };
        let episodes = JSON.parse(request("http://live.yj1211.work/api/live/getRealUrlMultiSource?platform=" + jo.platForm + "&roomId=" + jo.roomId)).data; //多线路
        if (Object.keys(episodes).length !== 0) {
            let playFrom = [];
            let playList = [];
            let kplayList = [];
            Object.keys(episodes).forEach(function(key) {
                playFrom.append(key);
                kplayList = episodes[key].map(function(it) {
                    let title = it.qualityName;
                    let playUrl = it.playUrl
                    return title + "$" + play_url + urlencode(playUrl)
                }).join("#")
                playList.append(kplayList);
            });
            let vod_play_from = playFrom.join("$$$");
            let vod_play_url = playList.join("$$$");
            VOD["vod_play_from"] = vod_play_from;
            VOD["vod_play_url"] = vod_play_url;
        } else {
            var d = [];
            episodes = JSON.parse(request("http://live.yj1211.work/api/live/getRealUrl?platform=" + jo.platForm + "&roomId=" + jo.roomId)).data; //单线路
            var name = {
                "OD": "原画",
                "FD": "流畅",
                "LD": "标清",
                "SD": "高清",
                "HD": "超清",
                "2K": "2K",
                "4K": "4K",
                "FHD": "全高清",
                "XLD": "极速",
                "SQ": "普通音质",
                "HQ": "高音质"
            };
            Object.keys(episodes).forEach(function(key) {
                if (!/ayyuid|to/.test(key)) {
                    d.push({
                        title: name[key],
                        url: episodes[key]
                    })
                }
            });
            d.push(
                {
                    title: "解析1",
                    url: "http://epg.112114.xyz/huya/" + jo.roomId
                },
                {
                    title: "解析2",
                    url: "https://www.aois.eu.org/live/huya/" + jo.roomId
                },
                {
                    title: "解析3",
                    url: "https://www.goodiptv.club/huya/" + jo.roomId
                },
                {
                    title: "解析4",
                    url: "http://maomao.kandiantv.cn/huya1.php?id=" + jo.roomId
                },
                {
                    title: "解析5",
                    url: "http://43.138.170.29:35455/huya/" + jo.roomId
                },
                {
                    title: "解析6",
                    url: "http://8.210.232.168/php/huya.php?id=" + jo.roomId
                },
            );
            VOD["vod_play_from"] = "播放源";
            VOD["vod_play_url"] = d.map(function(it) {
                return it.title + "$" + it.url
            }).join("#");
            setResult(d);
        }
    } catch (e) {
        log("获取二级详情页发生错误:" + e.message);
    }
    `,
    // 搜索:'json:data.list;roomName;roomSrc;nickname;roomId',
    搜索: `js:
        var d = [];
        let rurls = input.split(';')[0].split('#');
        let rurl = rurls[0];
        let params = rurls.length > 1 ?rurls[1]:'';
        let _fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
        let postData = {body:params};
        Object.assign(_fetch_params,postData);
        let jo = JSON.parse(post(rurl,_fetch_params)).data.list;
        jo.forEach(it => {
            d.push({
                url: it.roomId,
                title: it.roomName,
                img: it.roomSrc,
                desc: '👁' + it.hn + '  🆙' + it.nickname,
            })
        });
        setResult(d);
    `,

    //是否启用辅助嗅探: 1,0
    sniffer: 1,
    // 辅助嗅探规则js写法
    isVideo: `js:
        log(input);
        if(/\\/huya/.test(input)) {
            input = true
        } else if(/\\.flv?|\\.m3u8?|\\.mp4?/.test(input)){
            input = true
        }else{
            input = false
        }
    `,
}
