xiaozhitiao_open.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 = 'xiaozhitiao';
  5. let siteType = 0;
  6. let siteUrl = 'https://gitcafe.net/tool/alipaper/';
  7. let aliUrl = "https://www.aliyundrive.com/s/";
  8. let token = '';
  9. let date = new Date();
  10. 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';
  11. async function request(reqUrl, data) {
  12. let res = await req(reqUrl, {
  13. method: 'post',
  14. headers: {
  15. 'User-Agent': UA,
  16. 'Content-Type': 'application/x-www-form-urlencoded',
  17. },
  18. data: data,
  19. postType: 'form',
  20. });
  21. return res.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. return await detailContent(id);
  43. } catch (e) {
  44. await log('detail:' + e.message + ' line:' + e.lineNumber);
  45. }
  46. }
  47. async function play(flag, id, flags) {
  48. try {
  49. return await playContent(flag, id, flags);
  50. } catch (e) {
  51. await log('play:' + e.message + ' line:' + e.lineNumber);
  52. }
  53. }
  54. async function search(wd, quick, pg) {
  55. if (pg <= 0) pg = 1;
  56. const params = {
  57. "action": "search",
  58. "from": "web",
  59. "keyword": wd,
  60. "token": await getToken(),
  61. };
  62. const resp = await request(siteUrl, params);
  63. const json = JSON.parse(resp);
  64. if (!json.success) return "";
  65. const videos = _.map(json.data, (item) => {
  66. return {
  67. vod_id: aliUrl + item.alikey,
  68. vod_name: item.title,
  69. vod_pic: "https://www.lgstatic.com/i/image2/M01/15/7E/CgoB5lysLXCADg6ZAABapAHUnQM321.jpg",
  70. vod_remarks: item.creatime
  71. };
  72. });
  73. return JSON.stringify({
  74. list: videos,
  75. });
  76. }
  77. async function getToken() {
  78. const newDate = new Date();
  79. if (_.isEmpty(token) || newDate > date) {
  80. const params = {
  81. "action": "get_token",
  82. };
  83. const resp = await request(siteUrl, params);
  84. const json = JSON.parse(resp);
  85. if (json.success) {
  86. token = json.data;
  87. date = newDate;
  88. }
  89. }
  90. return token;
  91. }
  92. export function __jsEvalReturn() {
  93. return {
  94. init: init,
  95. home: home,
  96. homeVod: homeVod,
  97. category: category,
  98. detail: detail,
  99. play: play,
  100. search: search,
  101. };
  102. }