zhaozy_open.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import { load, _ } from 'assets://js/lib/cat.js';
  2. import { log } from './lib/utils.js';
  3. import { initAli, detailContent, playContent } from './lib/ali.js';
  4. let siteKey = 'zhaozy';
  5. let siteType = 0;
  6. let siteUrl = 'https://zhaoziyuan.pw';
  7. let patternAli = /(https:\/\/www\.(aliyundrive|alipan)\.com\/s\/[^"]+)/;
  8. let patternVid = /(\\S+)/;
  9. let username = '';
  10. let password = '';
  11. let cookie = '';
  12. 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';
  13. async function requestRaw(reqUrl, headers, method, data) {
  14. let res = await req(reqUrl, {
  15. method: method || 'get',
  16. headers: headers,
  17. data: data,
  18. postType: method === 'post' ? 'form' : '',
  19. });
  20. return res;
  21. }
  22. async function request(reqUrl, headers) {
  23. let resRaw = await requestRaw(reqUrl, headers);
  24. return resRaw.content;
  25. }
  26. // cfg = {skey: siteKey, ext: extend}
  27. async function init(cfg) {
  28. try {
  29. siteKey = _.isEmpty(cfg.skey) ? '' : cfg.skey;
  30. siteType = _.isEmpty(cfg.stype) ? '' : cfg.stype;
  31. const ext = _.isEmpty(cfg.ext) ? '' : cfg.ext;
  32. const configs = ext.split('$$$');
  33. if (configs.length == 3) {
  34. username = configs[1];
  35. password = configs[2];
  36. }
  37. await initAli(configs[0]);
  38. } catch (e) {
  39. await log('init:' + e.message + ' line:' + e.lineNumber);
  40. }
  41. }
  42. async function home(filter) {
  43. return '{}';
  44. }
  45. async function homeVod() {}
  46. async function category(tid, pg, filter, extend) {
  47. return '{}';
  48. }
  49. async function detail(id) {
  50. try {
  51. let matches = id.match(patternAli);
  52. if (!_.isEmpty(matches)) return await detailContent(matches[1]);
  53. const headers = await getHeaders();
  54. const data = await request(siteUrl + '/' + id, headers);
  55. matches = data.match(patternAli);
  56. if (!_.isEmpty(matches)) return await detailContent(matches[1]);
  57. return '';
  58. } catch (e) {
  59. await log('detail:' + e.message + ' line:' + e.lineNumber);
  60. }
  61. }
  62. async function play(flag, id, flags) {
  63. try {
  64. return await playContent(flag, id, flags);
  65. } catch (e) {
  66. await log('play:' + e.message + ' line:' + e.lineNumber);
  67. }
  68. }
  69. async function search(wd, quick, pg) {
  70. if (pg <= 0) pg = 1;
  71. const limit = 15;
  72. const headers = await getHeaders();
  73. const html = await request(siteUrl + '/so?filename=' + encodeURIComponent(wd) + '&page=' + pg, headers);
  74. const $ = load(html);
  75. const elements = $('div.li_con div.news_text');
  76. const videos = _.map(elements, (item) => {
  77. const element = $(item);
  78. const href = element.find('div.news_text a').attr('href');
  79. if (!href) return undefined;
  80. const matches = href.match(patternVid);
  81. if (!_.isEmpty(matches)) return undefined;
  82. const name = element.find("div.news_text a h3").text();
  83. const remark = element.find("div.news_text a p").text().split("|")[1].split(":")[1];
  84. return {
  85. vod_id: href,
  86. vod_name: name,
  87. vod_pic: "https://inews.gtimg.com/newsapp_bt/0/13263837859/1000",
  88. vod_remarks: remark
  89. };
  90. });
  91. const nextPage = $('.page a li:contains(下一页)');
  92. const hasMore = _.isEmpty(nextPage) ? false : nextPage.attr('class') != 'disabled';
  93. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  94. return JSON.stringify({
  95. page: parseInt(pg),
  96. pagecount: pgCount,
  97. limit: limit,
  98. total: limit * pgCount,
  99. list: videos.filter(item => item !== undefined),
  100. });
  101. }
  102. async function getHeaders() {
  103. if (!cookie) {
  104. cookie = await getCookie();
  105. }
  106. return {
  107. 'User-Agent': UA,
  108. 'Referer': siteUrl,
  109. 'Cookie': cookie,
  110. };
  111. }
  112. async function getCookie() {
  113. const params = {
  114. "username": username,
  115. "password": password,
  116. };
  117. const headers = {
  118. "User-Agent": UA,
  119. "Referer": siteUrl + "/stop.html",
  120. "Origin": siteUrl,
  121. };
  122. const res = await requestRaw(siteUrl + "/logiu.html", headers, 'post', params);
  123. let result = '';
  124. for (const cookie of res.headers['set-cookie']) {
  125. result += cookie.split(";")[0] + ";";
  126. }
  127. return result;
  128. }
  129. export function __jsEvalReturn() {
  130. return {
  131. init: init,
  132. home: home,
  133. homeVod: homeVod,
  134. category: category,
  135. detail: detail,
  136. play: play,
  137. search: search,
  138. };
  139. }