czzy_open.js 8.5 KB

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