采集之王.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /**
  2. * 强烈推荐静态分类。可以加快速度!!!
  3. * 传参 ?type=url&params=../json/采集.json
  4. * 传参 ?type=url&params=../json/采集静态.json
  5. * [{"name":"暴风资源","url":"https://bfzyapi.com","parse_url":""},{"name":"飞刀资源","url":"http://www.feidaozy.com","parse_url":""},{"name":"黑木耳资源","url":"https://www.heimuer.tv","parse_url":""}]
  6. */
  7. var rule = {
  8. title: '采集之王[合]',
  9. author: '道长',
  10. version: '20240621 beta4',
  11. host: '',
  12. homeTid: '', // 首页推荐。一般填写第一个资源站的想要的推荐分类的id.可以空
  13. homeUrl: '/api.php/provide/vod/?ac=detail&t={{rule.homeTid}}',
  14. detailUrl: '/api.php/provide/vod/?ac=detail&ids=fyid',
  15. searchUrl: '/api.php/provide/vod/?wd=**&pg=fypage',
  16. classUrl: '/api.php/provide/vod/',
  17. url: '/api.php/provide/vod/?ac=detail&pg=fypage&t=fyfilter',
  18. filter_url: '{{fl.类型}}',
  19. headers: {'User-Agent': 'MOBILE_UA'},
  20. timeout: 5000, // class_name: '电影&电视剧&综艺&动漫',
  21. limit: 20,
  22. search_limit: 5, // 搜索限制取前5个,可以注释掉,就不限制搜索
  23. searchable: 1,//是否启用全局搜索,
  24. quickSearch: 0,//是否启用快速搜索,
  25. filterable: 1,//是否启用分类筛选,
  26. play_parse: true,
  27. parse_url: '', // 这个参数暂时不起作用。聚合类的每个资源应该有自己独立的解析口
  28. // params: 'http://127.0.0.1:5707/files/json/%E9%87%87%E9%9B%86.json',
  29. // params: 'http://127.0.0.1:5707/files/json/采集静态.json',
  30. 预处理: $js.toString(() => {
  31. function getClasses(homeObj) {
  32. let classes = [];
  33. if (homeObj.class_name && homeObj.class_url) {
  34. if (!/&|电影|电视剧|综艺|动漫[\u4E00-\u9FA5]+/.test(homeObj.class_name)) {
  35. try {
  36. homeObj.class_name = ungzip(homeObj.class_name)
  37. } catch (e) {
  38. log(`不识别的class_name导致gzip解码失败:${e}`)
  39. return classes
  40. }
  41. }
  42. let names = homeObj.class_name.split('&');
  43. let urls = homeObj.class_url.split('&');
  44. let cnt = Math.min(names.length, urls.length);
  45. for (let i = 0; i < cnt; i++) {
  46. classes.push({
  47. 'type_id': urls[i],
  48. 'type_name': names[i]
  49. });
  50. }
  51. }
  52. return classes
  53. }
  54. let _url = rule.params;
  55. if (_url && typeof (_url) === 'string' && /^(http|file)/.test(_url)) {
  56. let html = request(_url);
  57. let json = JSON.parse(html);
  58. let _classes = [];
  59. rule.filter = {};
  60. rule.filter_def = {};
  61. json.forEach(it => {
  62. let _obj = {
  63. type_name: it.name,
  64. type_id: it.url,
  65. parse_url: it.parse_url || '',
  66. cate_exclude: it.cate_exclude || '',
  67. // class_name: it.class_name || '',
  68. // class_url: it.class_url || '',
  69. };
  70. _classes.push(_obj);
  71. try {
  72. let json1 = [];
  73. if (it.class_name && it.class_url) {
  74. json1 = getClasses(it);
  75. } else {
  76. json1 = JSON.parse(request(urljoin(_obj.type_id, rule.classUrl))).class;
  77. }
  78. if (_obj.cate_exclude) {
  79. json1 = json1.filter(cl => !new RegExp(_obj.cate_exclude, 'i').test(cl.type_name));
  80. }
  81. rule.filter[_obj.type_id] = [{
  82. "key": "类型", "name": "类型", "value": json1.map(i => {
  83. return {"n": i.type_name, 'v': i.type_id}
  84. })
  85. }];
  86. if (json1.length > 0) {
  87. rule.filter_def[it.url] = {"类型": json1[0].type_id};
  88. }
  89. } catch (e) {
  90. rule.filter[it.url] = [{"key": "类型", "name": "类型", "value": [{"n": "全部", "v": ""}]}];
  91. }
  92. });
  93. rule.classes = _classes;
  94. }
  95. }),
  96. // class_parse: $js.toString(() => {
  97. // let _url = rule.params;
  98. // if (_url && typeof (_url) === 'string' && _url.startsWith('http')) {
  99. // let html = request(_url);
  100. // let json = JSON.parse(html);
  101. // let _classes = [];
  102. // homeObj.filter = {};
  103. // rule.filter_def = {};
  104. // json.forEach(it => {
  105. // let _obj = {
  106. // type_name: it.name,
  107. // type_id: it.url,
  108. // parse_url: it.parse_url || '',
  109. // cate_exclude: it.cate_exclude || '',
  110. // };
  111. // _classes.push(_obj);
  112. // try {
  113. // let json1 = JSON.parse(request(urljoin(_obj.type_id, rule.classUrl))).class;
  114. // if (_obj.cate_exclude) {
  115. // json1 = json1.filter(cl => !new RegExp(_obj.cate_exclude, 'i').test(cl.type_name));
  116. // }
  117. // homeObj.filter[_obj.type_id] = [{
  118. // "key": "类型", "name": "类型", "value": json1.map(i => {
  119. // return {"n": i.type_name, 'v': i.type_id}
  120. // })
  121. // }];
  122. // if (json1.length > 0) {
  123. // rule.filter_def[it.url] = {"类型": json1[0].type_id};
  124. // }
  125. // } catch (e) {
  126. // homeObj.filter[it.url] = [{"key": "类型", "name": "类型", "value": [{"n": "全部", "v": ""}]}];
  127. // }
  128. // });
  129. // rule.classes = _classes;
  130. // input = _classes;
  131. // }
  132. // }),
  133. class_parse: $js.toString(() => {
  134. input = rule.classes;
  135. }),
  136. 推荐: $js.toString(() => {
  137. VODS = [];
  138. if (rule.classes) {
  139. let _url = urljoin(rule.classes[0].type_id, input);
  140. try {
  141. let html = request(_url);
  142. let json = JSON.parse(html);
  143. VODS = json.list;
  144. VODS.forEach(it => {
  145. it.vod_id = rule.classes[0].type_id + '$' + it.vod_id
  146. });
  147. } catch (e) {
  148. }
  149. }
  150. }),
  151. 一级: $js.toString(() => {
  152. VODS = [];
  153. if (rule.classes) {
  154. // log(input);
  155. let _url = urljoin(MY_CATE, input);
  156. let html = request(_url);
  157. let json = JSON.parse(html);
  158. VODS = json.list;
  159. VODS.forEach(it => {
  160. it.vod_id = MY_CATE + '$' + it.vod_id
  161. });
  162. }
  163. }),
  164. // 一级: 'json:list;vod_name;vod_pic;vod_remarks;vod_id;vod_play_from',
  165. 二级: $js.toString(() => {
  166. VOD = [];
  167. if (rule.classes) {
  168. let _url = urljoin(fyclass, input);
  169. let html = request(_url);
  170. let json = JSON.parse(html);
  171. let data = json.list;
  172. VOD = data[0];
  173. }
  174. }),
  175. 搜索: $js.toString(() => {
  176. VODS = [];
  177. if (rule.classes) {
  178. if (rule.search_limit) {
  179. rule.classes = rule.classes.slice(0, rule.search_limit);
  180. }
  181. rule.classes.forEach(it => {
  182. let _url = urljoin(it.type_id, input);
  183. // log(_url);
  184. try {
  185. let html = request(_url);
  186. let json = JSON.parse(html);
  187. let data = json.list;
  188. data.forEach(i => {
  189. i.vod_id = it.type_id + '$' + i.vod_id;
  190. i.vod_remarks = i.vod_remarks + '|' + it.type_name;
  191. });
  192. VODS = VODS.concat(data);
  193. } catch (e) {
  194. log(`请求:${it.type_id}发生错误:${e.message}`)
  195. }
  196. });
  197. }
  198. }),
  199. lazy: $js.toString(() => {
  200. // lazy想办法用对应的parse_url,但是有难度,暂未实现
  201. if (/\.(m3u8|mp4)/.test(input)) {
  202. input = {parse: 0, url: input}
  203. } else {
  204. if (rule.parse_url.startsWith('json:')) {
  205. let purl = rule.parse_url.replace('json:', '') + input;
  206. let html = request(purl);
  207. input = {parse: 0, url: JSON.parse(html).url}
  208. } else {
  209. input = rule.parse_url + input;
  210. }
  211. }
  212. }),
  213. }