czzy_open.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import { Crypto, load, _ } from './lib/cat.js';
  2. let key = 'czzy';
  3. let url = 'https://cz4k.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. 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_pic: $('div.dyimg img:first').attr('src'),
  127. vod_remarks: '',
  128. vod_content: stripHtmlTag($('div.yp_context').html()).trim(),
  129. };
  130. for (const info of detail) {
  131. const i = $(info).text().trim();
  132. if (i.startsWith('地区:')) {
  133. vod.vod_area = i.substring(3);
  134. } else if (i.startsWith('年份:')) {
  135. vod.vod_year = i.substring(3);
  136. } else if (i.startsWith('导演:')) {
  137. vod.vod_director = _.map($(info).find('a'), (a) => {
  138. return a.children[0].data;
  139. }).join('/');
  140. } else if (i.startsWith('主演:')) {
  141. vod.vod_actor = _.map($(info).find('a'), (a) => {
  142. return a.children[0].data;
  143. }).join('/');
  144. } else if (i.startsWith('语言:')) {
  145. vod.vod_lang = i.substring(3);
  146. }
  147. }
  148. const playlist = _.map($('div.paly_list_btn > a'), (a) => {
  149. return a.children[0].data + '$' + a.attribs.href.replace(/.*?\/v_play\/(.*).html/g, '$1');
  150. });
  151. vod.vod_play_from = key;
  152. vod.vod_play_url = playlist.join('#');
  153. return JSON.stringify({
  154. list: [vod],
  155. });
  156. }
  157. async function play(flag, id, flags) {
  158. const link = url + '/v_play/' + id + '.html';
  159. const html = await request(link);
  160. const $ = load(html);
  161. const iframe = $('body iframe[src*=Cloud]');
  162. if (iframe.length > 0) {
  163. const iframeHtml = (
  164. await req(iframe[0].attribs.src, {
  165. headers: {
  166. Referer: link,
  167. 'User-Agent': UA,
  168. },
  169. })
  170. ).content;
  171. let code = iframeHtml
  172. .match(/var url = '(.*?)'/)[1]
  173. .split('')
  174. .reverse()
  175. .join('');
  176. let temp = '';
  177. for (let i = 0x0; i < code.length; i = i + 0x2) {
  178. temp += String.fromCharCode(parseInt(code[i] + code[i + 0x1], 0x10));
  179. }
  180. const playUrl = temp.substring(0x0, (temp.length - 0x7) / 0x2) + temp.substring((temp.length - 0x7) / 0x2 + 0x7);
  181. return JSON.stringify({
  182. parse: 0,
  183. url: playUrl,
  184. });
  185. } else {
  186. const js = $('script:contains(window.wp_nonce)').html();
  187. const group = js.match(/(var.*)eval\((\w*\(\w*\))\)/);
  188. const md5 = Crypto;
  189. const result = eval(group[1] + group[2]);
  190. const playUrl = result.match(/url:.*?['"](.*?)['"]/)[1];
  191. return JSON.stringify({
  192. parse: 0,
  193. url: playUrl,
  194. });
  195. }
  196. }
  197. async function search(wd, quick) {
  198. const html = await request(url + '/?s=' + wd);
  199. const $ = load(html);
  200. const items = $('div.search_list > ul > li');
  201. let videos = _.map(items, (item) => {
  202. const img = $(item).find('img:first')[0];
  203. const a = $(item).find('a:first')[0];
  204. const hdinfo = $($(item).find('div.hdinfo')[0]).text().trim();
  205. const jidi = $($(item).find('div.jidi')[0]).text().trim();
  206. return {
  207. vod_id: a.attribs.href.replace(/.*?\/movie\/(.*).html/g, '$1'),
  208. vod_name: img.attribs.alt,
  209. vod_pic: img.attribs['data-original'],
  210. vod_remarks: jidi || hdinfo || '',
  211. };
  212. });
  213. return JSON.stringify({
  214. list: videos,
  215. });
  216. }
  217. export function __jsEvalReturn() {
  218. return {
  219. init: init,
  220. home: home,
  221. homeVod: homeVod,
  222. category: category,
  223. detail: detail,
  224. play: play,
  225. search: search,
  226. };
  227. }