iBot.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import { Crypto, load, _ } from 'http://alist.xn--z7x900a.love:63/cat.js';
  2. let key = 'ikanbot';
  3. let url = 'https://www.ikanbot.com';
  4. let siteKey = '';
  5. let siteType = 0;
  6. const UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1';
  7. async function request(reqUrl, agentSp) {
  8. let res = await req(reqUrl, {
  9. method: 'get',
  10. headers: {
  11. 'User-Agent': agentSp || UA,
  12. },
  13. });
  14. return res.content;
  15. }
  16. // cfg = {skey: siteKey, ext: extend}
  17. async function init(cfg) {
  18. siteKey = cfg.skey;
  19. siteType = cfg.stype;
  20. }
  21. function getClass($) {
  22. const nav = $('ul.nav-pills:eq(1) > li > a');
  23. let tags = {
  24. key: 'tag',
  25. name: '标签',
  26. value: _.map(nav, (n) => {
  27. return { n: n.children[0].data, v: n.attribs.href };
  28. }),
  29. };
  30. tags['init'] = tags.value[0].v;
  31. const title = $('title:first').text().split('-')[0].substring(2);
  32. return { cls: { type_id: tags.value[0].v, type_name: title }, tags: [tags] };
  33. }
  34. async function home(filter) {
  35. let classes = [];
  36. let filterObj = {};
  37. for (const cate of ['/hot/index-movie-热门.html', '/hot/index-tv-热门.html']) {
  38. const html = await request(url + cate);
  39. const $ = load(html);
  40. const { cls, tags } = getClass($);
  41. classes.push(cls);
  42. filterObj[cls.type_id] = tags;
  43. }
  44. return JSON.stringify({
  45. class: classes,
  46. filters: filterObj,
  47. });
  48. }
  49. async function homeVod() {
  50. return '{}';
  51. }
  52. async function category(tid, pg, filter, extend) {
  53. if (pg <= 0) pg = 1;
  54. const link = url + (extend.tag || tid).replace('.html', pg > 1 ? `-p-${pg}.html` : '.html');
  55. const html = await request(link);
  56. const $ = load(html);
  57. const items = $('div.v-list a.item');
  58. var jsBase = await js2Proxy(true, siteType, siteKey, 'img/', {});
  59. let videos = _.map(items, (item) => {
  60. const img = $(item).find('img:first')[0];
  61. return {
  62. vod_id: item.attribs.href,
  63. vod_name: img.attribs.alt,
  64. vod_pic0: jsBase + base64Encode(img.attribs['data-src']),
  65. vod_pic: img.attribs['data-src'] + "@Referer=" + img.attribs['data-src'] + "@User-Agent=" + UA,
  66. vod_remarks: '',
  67. };
  68. });
  69. const hasMore = $('div.page-more > a:contains(下一页)').length > 0;
  70. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  71. return JSON.stringify({
  72. page: parseInt(pg),
  73. pagecount: pgCount,
  74. limit: 24,
  75. total: 24 * pgCount,
  76. list: videos,
  77. });
  78. }
  79. async function detail(id) {
  80. const html = await request(url + id);
  81. const $ = load(html);
  82. var jsBase = await js2Proxy(true, siteType, siteKey, 'img/', {});
  83. const detail = $('div.detail > .meta');
  84. let vod = {
  85. vod_id: id,
  86. vod_pic: jsBase + base64Encode($('div.item-root > img')[0].attribs['data-src']),
  87. vod_remarks: '',
  88. };
  89. for (const info of detail) {
  90. if ($(info).hasClass('title')) {
  91. vod.vod_name = info.children[0].data;
  92. } else if ($(info).hasClass('year')) {
  93. vod.vod_area = info.children[0].data;
  94. } else if ($(info).hasClass('country')) {
  95. vod.vod_area = info.children[0].data;
  96. } else if ($(info).hasClass('celebrity')) {
  97. vod.vod_actor = info.children[0].data;
  98. }
  99. }
  100. const res = await req(url + '/api/getResN?videoId=' + id.substring(id.lastIndexOf('/') + 1) + '&mtype=2', {
  101. headers: {
  102. Referer: url,
  103. 'User-Agent': UA,
  104. },
  105. });
  106. const list = JSON.parse(res.content).data.list;
  107. let playlist = {};
  108. for (const l of list) {
  109. const flagData = JSON.parse(l.resData);
  110. for (const f of flagData) {
  111. const from = f.flag;
  112. const urls = f.url;
  113. if (!from || !urls) continue;
  114. if (playlist[from]) continue;
  115. playlist[from] = urls;
  116. }
  117. }
  118. vod.vod_play_from = _.keys(playlist).join('$$$');
  119. vod.vod_play_url = _.values(playlist).join('$$$');
  120. return JSON.stringify({
  121. list: [vod],
  122. });
  123. }
  124. function base64Encode(text) {
  125. return Crypto.enc.Base64.stringify(Crypto.enc.Utf8.parse(text));
  126. }
  127. function base64Decode(text) {
  128. return Crypto.enc.Utf8.stringify(Crypto.enc.Base64.parse(text));
  129. }
  130. async function proxy(segments, headers) {
  131. let what = segments[0];
  132. let url = base64Decode(segments[1]);
  133. if (what == 'img') {
  134. var resp = await req(url, {
  135. buffer: 2,
  136. headers: {
  137. Referer: url,
  138. 'User-Agent': UA,
  139. },
  140. });
  141. return JSON.stringify({
  142. code: resp.code,
  143. buffer: 2,
  144. content: resp.content,
  145. headers: resp.headers,
  146. });
  147. }
  148. return JSON.stringify({
  149. code: 500,
  150. content: '',
  151. });
  152. }
  153. async function play(flag, id, flags) {
  154. return JSON.stringify({
  155. parse: 0,
  156. url: id,
  157. });
  158. }
  159. function js2Proxy() {
  160. return "";
  161. }
  162. async function search(wd, quick) {
  163. const html = await request(url + '/search?q=' + wd);
  164. const $ = load(html);
  165. const items = $('div.media > div.media-left > a');
  166. var jsBase = await js2Proxy(true, siteType, siteKey, 'img/', {});
  167. let videos = _.map(items, (item) => {
  168. const img = $(item).find('img:first')[0];
  169. return {
  170. vod_id: item.attribs.href,
  171. vod_name: img.attribs.alt,
  172. vod_pic0: jsBase + base64Encode(img.attribs['data-src']),
  173. vod_pic: img.attribs['data-src'] + "@Referer=" + img.attribs['data-src'] + "@User-Agent=" + UA,
  174. vod_remarks: ''
  175. };
  176. });
  177. return JSON.stringify({
  178. list: videos,
  179. });
  180. }
  181. export function __jsEvalReturn() {
  182. return {
  183. init: init,
  184. home: home,
  185. homeVod: homeVod,
  186. category: category,
  187. detail: detail,
  188. play: play,
  189. proxy: proxy,
  190. search: search,
  191. };
  192. }