pansearch_open.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 = 'pansearch';
  5. let siteType = 0;
  6. let siteUrl = 'https://www.pansearch.me';
  7. let patternAli = /(https:\/\/www\.(aliyundrive|alipan)\.com\/s\/[^"]+)/
  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. async function requestRaw(reqUrl, headers) {
  10. let res = await req(reqUrl, {
  11. method: 'get',
  12. headers: headers || {
  13. 'User-Agent': UA,
  14. 'Referer': siteUrl,
  15. },
  16. });
  17. return res;
  18. }
  19. async function request(reqUrl) {
  20. let resRaw = await requestRaw(reqUrl)
  21. return resRaw.content;
  22. }
  23. // cfg = {skey: siteKey, ext: extend}
  24. async function init(cfg) {
  25. try {
  26. siteKey = _.isEmpty(cfg.skey) ? '' : cfg.skey;
  27. siteType = _.isEmpty(cfg.stype) ? '' : cfg.stype;
  28. await initAli(cfg);
  29. } catch (e) {
  30. await log('init:' + e.message + ' line:' + e.lineNumber);
  31. }
  32. }
  33. async function home(filter) {
  34. return '{}';
  35. }
  36. async function homeVod() {}
  37. async function category(tid, pg, filter, extend) {
  38. return '{}';
  39. }
  40. async function detail(id) {
  41. try {
  42. let matches = id.match(patternAli);
  43. if (!_.isEmpty(matches)) return await detailContent(matches[0]);
  44. return '';
  45. } catch (e) {
  46. await log('detail:' + e.message + ' line:' + e.lineNumber);
  47. }
  48. }
  49. async function play(flag, id, flags) {
  50. try {
  51. return await playContent(flag, id, flags);
  52. } catch (e) {
  53. await log('play:' + e.message + ' line:' + e.lineNumber);
  54. }
  55. }
  56. async function search(wd, quick, pg) {
  57. if (pg <= 0) pg = 1;
  58. const limit = 10;
  59. let offsetParam = '';
  60. const offset = (pg - 1) * limit;
  61. if (offset > 0) {
  62. offsetParam = '&offset=' + offset;
  63. }
  64. const html = await request(siteUrl);
  65. const $ = load(html);
  66. const script = $('script#__NEXT_DATA__')[0];
  67. const data = script.children[0].data;
  68. const buildId = JSON.parse(data).buildId;
  69. const url = siteUrl + "/_next/data/" + buildId + "/search.json?keyword=" + encodeURIComponent(wd) + offsetParam + "&pan=aliyundrive";
  70. const result = await requestRaw(url, getSearchHeader());
  71. const json = JSON.parse(result.content).pageProps.data;
  72. const total = json.total;
  73. const videoIdSet = new Set();
  74. const videos = [];
  75. for (const item of json.data) {
  76. const content = item.content;
  77. const img = item.image || siteUrl + "/favicon.png";
  78. const splits = content.split('\n');
  79. if (_.isEmpty(splits)) continue;
  80. if (content.includes('1、')) {
  81. for (const line of splits) {
  82. if (_.isEmpty(line)) continue;
  83. const vodId = parseVideo(line, videoIdSet);
  84. if (!vodId) continue;
  85. videos.push({
  86. vod_id: vodId,
  87. vod_name: line.replaceAll(/<\/?[^>]+>/g, "").replace(/[0-9]*、/g, '').replace(/:http.*/g, ''),
  88. vod_pic: img,
  89. vod_remarks: item.time
  90. });
  91. }
  92. } else {
  93. const vodId = parseVideo(content, videoIdSet);
  94. if (!vodId) continue;
  95. videos.push({
  96. vod_id: vodId,
  97. vod_name: splits[0].replaceAll(/<\/?[^>]+>/g, "").replace('名称:', ''),
  98. vod_pic: img,
  99. vod_remarks: item.time
  100. });
  101. }
  102. }
  103. const pgCount = parseInt(total / limit) + 1;
  104. return JSON.stringify({
  105. page: parseInt(pg),
  106. pagecount: pgCount,
  107. limit: limit,
  108. total: total,
  109. list: videos,
  110. });
  111. }
  112. function parseVideo(content, videoIdSet) {
  113. const matches = content.match(patternAli);
  114. if (_.isEmpty(matches)) return;
  115. const vodId = matches[1];
  116. if (videoIdSet.has(vodId)) return;
  117. videoIdSet.add(vodId);
  118. return vodId;
  119. }
  120. function getSearchHeader() {
  121. return {
  122. "x-nextjs-data": "1",
  123. "Referer": siteUrl,
  124. };
  125. }
  126. export function __jsEvalReturn() {
  127. return {
  128. init: init,
  129. home: home,
  130. homeVod: homeVod,
  131. category: category,
  132. detail: detail,
  133. play: play,
  134. search: search,
  135. };
  136. }