drpy一级.js 6.0 KB

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