MyCatBookan.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { _ } from './lib/cat.js';
  2. let key = 'bookan';
  3. let url = 'https://api.bookan.com.cn';
  4. let siteKey = '';
  5. let siteType = 0;
  6. async function request(reqUrl, agentSp) {
  7. let res = await req(reqUrl, {
  8. method: 'get',
  9. });
  10. return res.content;
  11. }
  12. // cfg = {skey: siteKey, ext: extend}
  13. async function init(cfg) {
  14. siteKey = cfg.skey;
  15. siteType = cfg.stype;
  16. }
  17. async function home(filter) {
  18. return JSON.stringify({
  19. class: [
  20. { type_id: '1305', type_name: '少年读物' },
  21. { type_id: '1304', type_name: '儿童文学' },
  22. { type_id: '1320', type_name: '国学经典' },
  23. { type_id: '1306', type_name: '文艺少年' },
  24. { type_id: '1309', type_name: '育儿心经' },
  25. { type_id: '1310', type_name: '心理哲学' },
  26. { type_id: '1307', type_name: '青春励志' },
  27. { type_id: '1312', type_name: '历史小说' },
  28. { type_id: '1303', type_name: '故事会' },
  29. { type_id: '1317', type_name: '音乐戏剧' },
  30. { type_id: '1319', type_name: '相声评书' },
  31. ],
  32. });
  33. }
  34. async function homeVod() {
  35. return JSON.stringify({
  36. list: [],
  37. });
  38. }
  39. async function category(tid, pg, filter, extend) {
  40. pg = pg || 1;
  41. if (pg == 0) pg = 1;
  42. let content = await request(`${url}/voice/book/list?instance_id=25304&page=${pg}&category_id=${tid}&num=24`);
  43. let data = JSON.parse(content).data;
  44. let books = [];
  45. for (const book of data.list) {
  46. books.push({
  47. vod_id: book.id,
  48. vod_name: book.name,
  49. vod_pic: book.cover,
  50. vod_remarks: book.extra.author,
  51. });
  52. }
  53. return JSON.stringify({
  54. page: data.current_page,
  55. pagecount: data.last_page,
  56. limit: 24,
  57. total: data.total,
  58. list: books,
  59. });
  60. }
  61. async function detail(id) {
  62. let content = await request(`${url}/voice/album/units?album_id=${id}&page=1&num=200&order=1`);
  63. let data = JSON.parse(content).data;
  64. console.log(JSON.stringify(data));
  65. let book = {
  66. vod_id: id,
  67. type_name: '',
  68. vod_year: '',
  69. vod_area: '',
  70. vod_remarks: '',
  71. vod_actor: '',
  72. vod_director: '',
  73. vod_content: '',
  74. };
  75. let us = _.map(data.list, function (b) {
  76. return formatPlayUrl(b.title) + '$' + b.file;
  77. }).join('#');
  78. book.vod_play_from = '书卷';
  79. book.vod_play_url = us;
  80. return JSON.stringify({
  81. list: [book],
  82. });
  83. }
  84. function formatPlayUrl(name) {
  85. return name
  86. .trim()
  87. .replace(/<|>|\.《.*?》/g, '. ')
  88. .replace(/\$|#/g, ' ')
  89. .trim();
  90. }
  91. async function proxy(segments, headers) {}
  92. async function play(flag, id, flags) {
  93. return JSON.stringify({
  94. parse: 0,
  95. url: id,
  96. });
  97. }
  98. async function search(wd, quick, pg) {
  99. pg = pg || 1;
  100. if (pg == 0) pg = 1;
  101. let content = await request(`https://es.bookan.com.cn/api/v3/voice/book?instanceId=25304&keyword=${wd}&pageNum=${pg}&limitNum=20`);
  102. let data = JSON.parse(content).data;
  103. let books = [];
  104. for (const book of data.list) {
  105. books.push({
  106. vod_id: book.id,
  107. vod_name: book.name,
  108. vod_pic: book.cover,
  109. vod_remarks: book.extra.author,
  110. });
  111. }
  112. return JSON.stringify({
  113. page: data.current_page,
  114. pagecount: data.last_page,
  115. limit: 20,
  116. total: data.total,
  117. list: books,
  118. });
  119. }
  120. export function __jsEvalReturn() {
  121. return {
  122. init: init,
  123. home: home,
  124. homeVod: homeVod,
  125. category: category,
  126. detail: detail,
  127. play: play,
  128. search: search,
  129. };
  130. }