pansou_open.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 = 'pansou';
  5. let siteType = 0;
  6. let siteUrl = 'https://www.alipansou.com';
  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, redirect) {
  10. let res = await req(reqUrl, {
  11. method: 'get',
  12. headers: headers || {
  13. 'User-Agent': UA,
  14. 'Referer': siteUrl,
  15. },
  16. redirect: redirect,
  17. });
  18. return res;
  19. }
  20. async function request(reqUrl) {
  21. let resRaw = await requestRaw(reqUrl);
  22. return resRaw.content;
  23. }
  24. // cfg = {skey: siteKey, ext: extend}
  25. async function init(cfg) {
  26. try {
  27. siteKey = _.isEmpty(cfg.skey) ? '' : cfg.skey;
  28. siteType = _.isEmpty(cfg.stype) ? '' : cfg.stype;
  29. await initAli(cfg);
  30. } catch (e) {
  31. await log('init:' + e.message + ' line:' + e.lineNumber);
  32. }
  33. }
  34. async function home(filter) {
  35. return '{}';
  36. }
  37. async function homeVod() {}
  38. async function category(tid, pg, filter, extend) {
  39. return '{}';
  40. }
  41. async function detail(id) {
  42. try {
  43. let matches = id.match(patternAli);
  44. if (!_.isEmpty(matches)) return await detailContent(matches[0]);
  45. let url = siteUrl + id.replace("/s/", "/cv/");
  46. const data = await requestRaw(url, getHeaders(id), 0);
  47. const headers = data.headers;
  48. const resp = data.content;
  49. if (headers.hasOwnProperty('location')) {
  50. url = headers['location'].replace('/redirect?visit=', 'https://www.aliyundrive.com/s/');
  51. return await detailContent(url);
  52. } else if (!_.isEmpty(resp)) {
  53. const $ = load(resp);
  54. url = $('a:first').attr('href').replace('/redirect?visit=', 'https://www.aliyundrive.com/s/');
  55. return await detailContent(url);
  56. }
  57. return '';
  58. } catch (e) {
  59. await log('detail:' + e.message + ' line:' + e.lineNumber);
  60. }
  61. }
  62. function getHeaders(id) {
  63. return {
  64. "User-Agent": UA,
  65. "Referer": siteUrl + id,
  66. "_bid": "6d14a5dd6c07980d9dc089a693805ad8",
  67. };
  68. }
  69. async function play(flag, id, flags) {
  70. try {
  71. return await playContent(flag, id, flags);
  72. } catch (e) {
  73. await log('play:' + e.message + ' line:' + e.lineNumber);
  74. }
  75. }
  76. async function search(wd, quick, pg) {
  77. if (pg <= 0) pg = 1;
  78. const limit = 10;
  79. const html = await request(siteUrl + "/search?k=" + encodeURIComponent(wd) + "&page=" + pg + "&s=0&t=-1");
  80. const $ = load(html);
  81. const items = $('van-row > a');
  82. const videos = _.map(items, (item) => {
  83. let title = $(item).find('template:first').text().trim();
  84. return {
  85. vod_id: item.attribs.href,
  86. vod_name: title,
  87. vod_pic: 'https://inews.gtimg.com/newsapp_bt/0/13263837859/1000',
  88. };
  89. });
  90. const pageCount = $('van-pagination').attr('page-count') || pg;
  91. const pgCount = parseInt(pageCount);
  92. return JSON.stringify({
  93. page: parseInt(pg),
  94. pagecount: pgCount,
  95. limit: limit,
  96. total: limit * pgCount,
  97. list: videos,
  98. });
  99. }
  100. export function __jsEvalReturn() {
  101. return {
  102. init: init,
  103. home: home,
  104. homeVod: homeVod,
  105. category: category,
  106. detail: detail,
  107. play: play,
  108. search: search,
  109. };
  110. }