You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
8.3 KiB

  1. import { Crypto, load, _ } from './lib/cat.js';
  2. let key = 'czzy';
  3. let url = 'https://cz01.cc';
  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. const cookie = {};
  8. async function request(reqUrl, referer, mth, data, hd) {
  9. const headers = {
  10. 'User-Agent': UA,
  11. Cookie: _.map(cookie, (value, key) => {
  12. return `${key}=${value}`;
  13. }).join(';'),
  14. };
  15. if (referer) headers.referer = encodeURIComponent(referer);
  16. let res = await req(reqUrl, {
  17. method: mth || 'get',
  18. headers: headers,
  19. data: data,
  20. postType: mth === 'post' ? 'form' : '',
  21. });
  22. if (res.headers['set-cookie']) {
  23. const set_cookie = _.isArray(res.headers['set-cookie']) ? res.headers['set-cookie'].join(';') : res.headers['set-cookie'];
  24. const cks = set_cookie.split(';');
  25. for (const c of cks) {
  26. const tmp = c.trim();
  27. if (tmp.startsWith('result=')) {
  28. cookie.result = tmp.substring(7);
  29. return await request(reqUrl, reqUrl, 'post', {
  30. result: cookie.result,
  31. });
  32. } else if (tmp.startsWith('esc_search_captcha=1')) {
  33. cookie.esc_search_captcha = 1;
  34. delete cookie.result;
  35. return await request(reqUrl);
  36. }
  37. }
  38. // console.log(res.headers['set-cookie']);
  39. }
  40. return res.content;
  41. }
  42. // cfg = {skey: siteKey, ext: extend}
  43. async function init(cfg) {
  44. siteKey = cfg.skey;
  45. siteType = cfg.stype;
  46. }
  47. async function home(filter) {
  48. let filterObj = {};
  49. const html = await request(url + '/movie_bt');
  50. const $ = load(html);
  51. const series = $('div#beautiful-taxonomy-filters-tax-movie_bt_series > a[cat-url*=movie_bt_series]');
  52. const tags = $('div#beautiful-taxonomy-filters-tax-movie_bt_tags > a');
  53. let tag = {
  54. key: 'tag',
  55. name: '类型',
  56. value: _.map(tags, (n) => {
  57. let v = n.attribs['cat-url'] || '';
  58. v = v.substring(v.lastIndexOf('/') + 1);
  59. return { n: n.children[0].data, v: v };
  60. }),
  61. };
  62. tag['init'] = tag.value[0].v;
  63. let classes = _.map(series, (s) => {
  64. let typeId = s.attribs['cat-url'];
  65. typeId = typeId.substring(typeId.lastIndexOf('/') + 1);
  66. filterObj[typeId] = [tag];
  67. return {
  68. type_id: typeId,
  69. type_name: s.children[0].data,
  70. };
  71. });
  72. const sortName = ['电影', '电视剧', '国产剧', '美剧', '韩剧', '日剧', '海外剧(其他)', '华语电影', '印度电影', '日本电影', '欧美电影', '韩国电影', '动画', '俄罗斯电影', '加拿大电影'];
  73. classes = _.sortBy(classes, (c) => {
  74. const index = sortName.indexOf(c.type_name);
  75. return index === -1 ? sortName.length : index;
  76. });
  77. return JSON.stringify({
  78. class: classes,
  79. filters: filterObj,
  80. });
  81. }
  82. async function homeVod() {
  83. return '{}';
  84. }
  85. async function category(tid, pg, filter, extend) {
  86. if (pg <= 0) pg = 1;
  87. const tag = extend.tag || '';
  88. const link = url + '/movie_bt' + (tag.length > 0 ? `/movie_bt_tags/${tag}` : '') + '/movie_bt_series/' + tid + (pg > 1 ? `/page/${pg}` : '');
  89. const html = await request(link);
  90. const $ = load(html);
  91. const items = $('div.mrb > ul > li');
  92. let videos = _.map(items, (item) => {
  93. const img = $(item).find('img:first')[0];
  94. const a = $(item).find('a:first')[0];
  95. const hdinfo = $($(item).find('div.hdinfo')[0]).text().trim();
  96. const jidi = $($(item).find('div.jidi')[0]).text().trim();
  97. return {
  98. vod_id: a.attribs.href.replace(/.*?\/movie\/(.*).html/g, '$1'),
  99. vod_name: img.attribs.alt,
  100. vod_pic: img.attribs['data-original'],
  101. vod_remarks: jidi || hdinfo || '',
  102. };
  103. });
  104. const hasMore = $('div.mrb > div.pagenavi_txt > a:contains(>)').length > 0;
  105. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  106. return JSON.stringify({
  107. page: parseInt(pg),
  108. pagecount: pgCount,
  109. limit: 20,
  110. total: 20 * pgCount,
  111. list: videos,
  112. });
  113. }
  114. function stripHtmlTag(src) {
  115. return src
  116. .replace(/<\/?[^>]+(>|$)/g, '')
  117. .replace(/&.{1,5};/g, '')
  118. .replace(/\s{2,}/g, ' ');
  119. }
  120. async function detail(id) {
  121. const html = await request(url + '/movie/' + id + '.html');
  122. const $ = load(html);
  123. const detail = $('ul.moviedteail_list > li');
  124. let vod = {
  125. vod_id: id,
  126. vod_name: $('div.moviedteail_tt > h1').text().trim(),
  127. vod_pic: $('div.dyimg img:first').attr('src'),
  128. vod_remarks: '',
  129. vod_content: stripHtmlTag($('div.yp_context').html()).trim(),
  130. };
  131. for (const info of detail) {
  132. const i = $(info).text().trim();
  133. if (i.startsWith('地区:')) {
  134. vod.vod_area = i.substring(3);
  135. } else if (i.startsWith('年份:')) {
  136. vod.vod_year = i.substring(3);
  137. } else if (i.startsWith('导演:')) {
  138. vod.vod_director = _.map($(info).find('a'), (a) => {
  139. return a.children[0].data;
  140. }).join('/');
  141. } else if (i.startsWith('主演:')) {
  142. vod.vod_actor = _.map($(info).find('a'), (a) => {
  143. return a.children[0].data;
  144. }).join('/');
  145. } else if (i.startsWith('语言:')) {
  146. vod.vod_lang = i.substring(3);
  147. }
  148. }
  149. const playlist = _.map($('div.paly_list_btn > a'), (a) => {
  150. return a.children[0].data + '$' + a.attribs.href.replace(/.*?\/v_play\/(.*).html/g, '$1');
  151. });
  152. vod.vod_play_from = key;
  153. vod.vod_play_url = playlist.join('#');
  154. return JSON.stringify({
  155. list: [vod],
  156. });
  157. }
  158. async function play(flag, id, flags) {
  159. const link = url + '/v_play/' + id + '.html';
  160. const html = await request(link);
  161. const $ = load(html);
  162. const iframe = $('body iframe[src*=Cloud]');
  163. if (iframe.length > 0) {
  164. const iframeHtml = (
  165. await req(iframe[0].attribs.src, {
  166. headers: {
  167. Referer: link,
  168. 'User-Agent': UA,
  169. },
  170. })
  171. ).content;
  172. let code = iframeHtml
  173. .match(/var url = '(.*?)'/)[1]
  174. .split('')
  175. .reverse()
  176. .join('');
  177. let temp = '';
  178. for (let i = 0x0; i < code.length; i = i + 0x2) {
  179. temp += String.fromCharCode(parseInt(code[i] + code[i + 0x1], 0x10));
  180. }
  181. const playUrl = temp.substring(0x0, (temp.length - 0x7) / 0x2) + temp.substring((temp.length - 0x7) / 0x2 + 0x7);
  182. return JSON.stringify({
  183. parse: 0,
  184. url: playUrl,
  185. });
  186. } else {
  187. const js = $('script:contains(window.wp_nonce)').html();
  188. const group = js.match(/(var.*)eval\((\w*\(\w*\))\)/);
  189. const md5 = Crypto;
  190. const result = eval(group[1] + group[2]);
  191. const playUrl = result.match(/url:.*?['"](.*?)['"]/)[1];
  192. return JSON.stringify({
  193. parse: 0,
  194. url: playUrl,
  195. });
  196. }
  197. }
  198. async function search(wd, quick) {
  199. const html = await request(url + '/?s=' + wd);
  200. const $ = load(html);
  201. const items = $('div.search_list > ul > li');
  202. let videos = _.map(items, (item) => {
  203. const img = $(item).find('img:first')[0];
  204. const a = $(item).find('a:first')[0];
  205. const hdinfo = $($(item).find('div.hdinfo')[0]).text().trim();
  206. const jidi = $($(item).find('div.jidi')[0]).text().trim();
  207. return {
  208. vod_id: a.attribs.href.replace(/.*?\/movie\/(.*).html/g, '$1'),
  209. vod_name: img.attribs.alt,
  210. vod_pic: img.attribs['data-original'],
  211. vod_remarks: jidi || hdinfo || '',
  212. };
  213. });
  214. return JSON.stringify({
  215. list: videos,
  216. });
  217. }
  218. export function __jsEvalReturn() {
  219. return {
  220. init: init,
  221. home: home,
  222. homeVod: homeVod,
  223. category: category,
  224. detail: detail,
  225. play: play,
  226. search: search,
  227. };
  228. }