drpy一级.js 5.7 KB
Newer Older
H
hjdhnx 已提交
1 2
js:
let d = [];
H
hjdhnx 已提交
3 4 5
let douban = input.split("douban=")[1].split("&")[0];
let douban_api_host = "https://frodo.douban.com/api/v2";
let miniapp_apikey = "0ac44ae016490db2204ce0a042db2916";
H
hjdhnx 已提交
6 7
const count = 30;

H
hjdhnx 已提交
8
function miniapp_request(path, query) {
H
hjdhnx 已提交
9 10 11 12
    try {
        let url = douban_api_host + path;
        query.apikey = miniapp_apikey;
        fetch_params.headers = oheaders;
H
hjdhnx 已提交
13 14 15 16 17 18
        url = buildUrl(url, query);
        let html = fetch(url, fetch_params);
        return JSON.parse(html)
    } catch (e) {
        print("发生了错误:" + e.message);
        return {}
H
hjdhnx 已提交
19 20 21
    }
}

H
hjdhnx 已提交
22 23
function cate_filter(d, douban) {
    douban = douban || "";
H
hjdhnx 已提交
24
    try {
H
hjdhnx 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
        let res = {};
        if (MY_CATE === "interests") {
            if (douban) {
                let status = MY_FL.status || "mark";
                let subtype_tag = MY_FL.subtype_tag || "";
                let year_tag = MY_FL.year_tag || "全部";
                let path = "/user/" + douban + "/interests";
                res = miniapp_request(path, {
                    type: "movie",
                    status: status,
                    subtype_tag: subtype_tag,
                    year_tag: year_tag,
                    start: (MY_PAGE - 1) * count,
                    count: count
                })
            } else {
                return {}
H
hjdhnx 已提交
42
            }
H
hjdhnx 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        } else if (MY_CATE === "hot_gaia") {
            let sort = MY_FL.sort || "recommend";
            let area = MY_FL.area || "全部";
            let path = "/movie/" + MY_CATE;
            res = miniapp_request(path, {
                area: area,
                sort: sort,
                start: (MY_PAGE - 1) * count,
                count: count
            })
        } else if (MY_CATE === "tv_hot" || MY_CATE === "show_hot") {
            let stype = MY_FL.type || MY_CATE;
            let path = "/subject_collection/" + stype + "/items";
            res = miniapp_request(path, {
                start: (MY_PAGE - 1) * count,
                count: count
            })
        } else if (MY_CATE.startsWith("rank_list")) {
            let id = MY_CATE === "rank_list_movie" ? "movie_real_time_hotest" : "tv_real_time_hotest";
            id = MY_FL.榜单 || id;
            let path = "/subject_collection/" + id + "/items";
            res = miniapp_request(path, {
                start: (MY_PAGE - 1) * count,
                count: count
            })
        } else {
            let path = "/" + MY_CATE + "/recommend";
H
hjdhnx 已提交
70
            let selected_categories;
H
hjdhnx 已提交
71 72 73 74 75 76
            let tags;
            let sort;
            if (Object.keys(MY_FL).length > 0) {
                sort = MY_FL.sort || "T";
                tags = Object.values(MY_FL).join(",");
                if (MY_CATE === "movie") {
H
hjdhnx 已提交
77
                    selected_categories = {
H
hjdhnx 已提交
78 79
                        "类型": MY_FL.类型 || "",
                        "地区": MY_FL.地区 || ""
H
hjdhnx 已提交
80
                    }
H
hjdhnx 已提交
81
                } else {
H
hjdhnx 已提交
82
                    selected_categories = {
H
hjdhnx 已提交
83 84 85
                        "类型": MY_FL.类型 || "",
                        "形式": MY_FL.类型 ? MY_FL.类型 + "地区" : "",
                        "地区": MY_FL.地区 || ""
H
hjdhnx 已提交
86 87
                    }
                }
H
hjdhnx 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101
            } else {
                sort = "T";
                tags = "";
                if (MY_CATE === "movie") {
                    selected_categories = {
                        "类型": "",
                        "地区": ""
                    }
                } else {
                    selected_categories = {
                        "类型": "",
                        "形式": "",
                        "地区": ""
                    }
H
hjdhnx 已提交
102 103 104
                }
            }
            let params = {
H
hjdhnx 已提交
105 106 107 108 109 110 111
                tags: tags,
                sort: sort,
                refresh: 0,
                selected_categories: stringify(selected_categories),
                start: (MY_PAGE - 1) * count,
                count: count
            };
H
hjdhnx 已提交
112
            // print(params);
H
hjdhnx 已提交
113
            res = miniapp_request(path, params)
H
hjdhnx 已提交
114 115
        }
        let result = {
H
hjdhnx 已提交
116 117 118 119 120
            page: MY_PAGE,
            pagecount: Math.ceil(res.total / count),
            limit: count,
            total: res.total
        };
H
hjdhnx 已提交
121
        let items = [];
H
hjdhnx 已提交
122 123 124 125
        if (/^rank_list|tv_hot|show_hot/.test(MY_CATE)) {
            items = res["subject_collection_items"]
        } else if (MY_CATE === "interests") {
            res["interests"].forEach(function(it) {
H
hjdhnx 已提交
126
                items.push(it.subject)
H
hjdhnx 已提交
127 128
            })
        } else {
H
hjdhnx 已提交
129 130 131
            items = res.items
        }
        let lists = [];
H
hjdhnx 已提交
132 133 134 135
        items.forEach(function(item) {
            if (item.type === "movie" || item.type === "tv") {
                let rating = item.rating ? item.rating.value : "";
                let rat_str = rating || "暂无评分";
H
hjdhnx 已提交
136
                let title = item.title;
H
hjdhnx 已提交
137 138 139 140
                let honor = item.honor_infos || [];
                let honor_str = honor.map(function(it) {
                    return it.title
                }).join("|");
H
hjdhnx 已提交
141
                let vod_obj = {
H
hjdhnx 已提交
142 143 144
                    vod_name: title !== "未知电影" ? title : "暂不支持展示",
                    vod_pic: item.pic.normal,
                    vod_remarks: rat_str + " " + honor_str
H
hjdhnx 已提交
145 146
                };
                let vod_obj_d = {
H
hjdhnx 已提交
147 148
                    url: item.type + "$" + item.id,
                    title: title !== "未知电影" ? title : "暂不支持展示",
H
hjdhnx 已提交
149 150 151 152
                    pic_url: item.pic.normal,
                    desc: rat_str + " " + honor_str
                };
                lists.push(vod_obj);
H
hjdhnx 已提交
153
                d.push(vod_obj_d)
H
hjdhnx 已提交
154 155 156 157
            }
        });
        result.list = lists;
        return result
H
hjdhnx 已提交
158 159
    } catch (e) {
        print(e.message)
H
hjdhnx 已提交
160 161 162 163 164
    }
    return {}
}
let res = cate_filter(d);
setResult2(res);