yunpan4k_open.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 = 'yunpan4k';
  5. let siteType = 0;
  6. let siteUrl = 'https://www.codelicence.cn';
  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, method, data, redirect) {
  10. let res = await req(reqUrl, {
  11. method: method || 'get',
  12. headers: {
  13. 'User-Agent': UA,
  14. 'Referer': siteUrl,
  15. },
  16. data: data,
  17. postType: method === 'post' ? 'form' : '',
  18. redirect: redirect == 0 ? 0 : 1,
  19. });
  20. return res;
  21. }
  22. async function request(reqUrl, method, data) {
  23. let resRaw = await requestRaw(reqUrl, method, data);
  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. await initAli(cfg.ext);
  32. } catch (e) {
  33. await log('init:' + e.message + ' line:' + e.lineNumber);
  34. }
  35. }
  36. async function home(filter) {
  37. return '{}';
  38. }
  39. async function homeVod() {}
  40. async function category(tid, pg, filter, extend) {
  41. return '{}';
  42. }
  43. async function detail(id) {
  44. try {
  45. let matches = id.match(patternAli);
  46. if (!_.isEmpty(matches)) return await detailContent(matches[1]);
  47. const html = await request(siteUrl + id);
  48. const $ = load(html);
  49. const href = $('div.down a:first').attr('href');
  50. const data = await requestRaw(siteUrl + href, 'get', null, 0);
  51. const headers = data.headers;
  52. let url = '';
  53. if (headers.hasOwnProperty('location')) {
  54. url = headers['location'];
  55. }
  56. matches = url.match(patternAli);
  57. if (!_.isEmpty(matches)) return await detailContent(matches[1]);
  58. return '';
  59. } catch (e) {
  60. await log('detail:' + e.message + ' line:' + e.lineNumber);
  61. }
  62. }
  63. async function play(flag, id, flags) {
  64. try {
  65. return await playContent(flag, id, flags);
  66. } catch (e) {
  67. await log('play:' + e.message + ' line:' + e.lineNumber);
  68. }
  69. }
  70. async function search(wd, quick, pg) {
  71. if (pg <= 0) pg = 1;
  72. const limit = 20;
  73. const param = {
  74. keyboard: wd,
  75. };
  76. const data = await requestRaw(siteUrl + '/search', 'post', param);
  77. let html = '';
  78. const headers = data.headers;
  79. if (headers.hasOwnProperty('location')) {
  80. const url = headers['location'] + '?p=' + pg;
  81. html = await request(url);
  82. }
  83. const $ = load(html);
  84. const elements = $('ul#url');
  85. const videos = _.map(elements, (item) => {
  86. const element = $(item);
  87. const href = element.find('a.l').attr('href');
  88. if (!href) return undefined;
  89. const name = element.text().trim();
  90. const remark = element.find('li.r').attr('data_size');
  91. console.debug('vod_id:' + href);
  92. return {
  93. vod_id: href,
  94. vod_name: name,
  95. vod_pic: "https://pic.rmb.bdstatic.com/bjh/6a2278365c10139b5b03229c2ecfeea4.jpeg",
  96. vod_remarks: remark,
  97. };
  98. });
  99. const nextPage = $('.pages_search .nex:contains(下一页)');
  100. const hasMore = !_.isEmpty(nextPage);
  101. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  102. return JSON.stringify({
  103. page: parseInt(pg),
  104. pagecount: pgCount,
  105. limit: limit,
  106. total: limit * pgCount,
  107. list: videos.filter(item => item !== undefined),
  108. });
  109. }
  110. export function __jsEvalReturn() {
  111. return {
  112. init: init,
  113. home: home,
  114. homeVod: homeVod,
  115. category: category,
  116. detail: detail,
  117. play: play,
  118. search: search,
  119. };
  120. }