ikanbot_open.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import { Crypto, load, _ } from './lib/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_pic: jsBase + base64Encode(img.attribs['data-src']),
  65. vod_remarks: '',
  66. };
  67. });
  68. const hasMore = $('div.page-more > a:contains(下一页)').length > 0;
  69. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  70. return JSON.stringify({
  71. page: parseInt(pg),
  72. pagecount: pgCount,
  73. limit: 24,
  74. total: 24 * pgCount,
  75. list: videos,
  76. });
  77. }
  78. async function detail(id) {
  79. const html = await request(url + id);
  80. const $ = load(html);
  81. var jsBase = await js2Proxy(true, siteType, siteKey, 'img/', {});
  82. const detail = $('div.detail > .meta');
  83. let vod = {
  84. vod_id: id,
  85. vod_pic: jsBase + base64Encode($('div.item-root > img')[0].attribs['data-src']),
  86. vod_remarks: '',
  87. };
  88. for (const info of detail) {
  89. if ($(info).hasClass('title')) {
  90. vod.vod_name = info.children[0].data;
  91. } else if ($(info).hasClass('year')) {
  92. vod.vod_area = info.children[0].data;
  93. } else if ($(info).hasClass('country')) {
  94. vod.vod_area = info.children[0].data;
  95. } else if ($(info).hasClass('celebrity')) {
  96. vod.vod_actor = info.children[0].data;
  97. }
  98. }
  99. const res = await req(url + '/api/getResN?videoId=' + id.substring(id.lastIndexOf('/') + 1) + '&mtype=2', {
  100. headers: {
  101. Referer: url,
  102. 'User-Agent': UA,
  103. },
  104. });
  105. const list = JSON.parse(res.content).data.list;
  106. let playlist = {};
  107. for (const l of list) {
  108. const flagData = JSON.parse(l.resData);
  109. for (const f of flagData) {
  110. const from = f.flag;
  111. const urls = f.url;
  112. if (!from || !urls) continue;
  113. if (playlist[from]) continue;
  114. playlist[from] = urls;
  115. }
  116. }
  117. vod.vod_play_from = _.keys(playlist).join('$$$');
  118. vod.vod_play_url = _.values(playlist).join('$$$');
  119. return JSON.stringify({
  120. list: [vod],
  121. });
  122. }
  123. function base64Encode(text) {
  124. return Crypto.enc.Base64.stringify(Crypto.enc.Utf8.parse(text));
  125. }
  126. function base64Decode(text) {
  127. return Crypto.enc.Utf8.stringify(Crypto.enc.Base64.parse(text));
  128. }
  129. async function proxy(segments, headers) {
  130. let what = segments[0];
  131. let url = base64Decode(segments[1]);
  132. if (what == 'img') {
  133. var resp = await req(url, {
  134. buffer: 2,
  135. headers: {
  136. Referer: url,
  137. 'User-Agent': UA,
  138. },
  139. });
  140. return JSON.stringify({
  141. code: resp.code,
  142. buffer: 2,
  143. content: resp.content,
  144. headers: resp.headers,
  145. });
  146. }
  147. return JSON.stringify({
  148. code: 500,
  149. content: '',
  150. });
  151. }
  152. async function play(flag, id, flags) {
  153. return JSON.stringify({
  154. parse: 0,
  155. url: id,
  156. });
  157. }
  158. async function search(wd, quick) {
  159. const html = await request(url + '/search?q=' + wd);
  160. const $ = load(html);
  161. const items = $('div.media > div.media-left > a');
  162. var jsBase = await js2Proxy(true, siteType, siteKey, 'img/', {});
  163. let videos = _.map(items, (item) => {
  164. const img = $(item).find('img:first')[0];
  165. return {
  166. vod_id: item.attribs.href,
  167. vod_name: img.attribs.alt,
  168. vod_pic: jsBase + base64Encode(img.attribs['data-src']),
  169. vod_remarks: '',
  170. };
  171. });
  172. return JSON.stringify({
  173. list: videos,
  174. });
  175. }
  176. export function __jsEvalReturn() {
  177. return {
  178. init: init,
  179. home: home,
  180. homeVod: homeVod,
  181. category: category,
  182. detail: detail,
  183. play: play,
  184. proxy: proxy,
  185. search: search,
  186. };
  187. }