bookan_book_open.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 category(tid, pg, filter, extend) {
  35. pg = pg || 1;
  36. if (pg == 0) pg = 1;
  37. let content = await request(`${url}/voice/book/list?instance_id=25304&page=${pg}&category_id=${tid}&num=24`);
  38. let data = JSON.parse(content).data;
  39. let books = [];
  40. for (const book of data.list) {
  41. books.push({
  42. book_id: book.id,
  43. book_name: book.name,
  44. book_pic: book.cover,
  45. book_remarks: book.extra.author,
  46. });
  47. }
  48. return JSON.stringify({
  49. page: data.current_page,
  50. pagecount: data.last_page,
  51. limit: 24,
  52. total: data.total,
  53. list: books,
  54. });
  55. }
  56. async function detail(id) {
  57. let content = await request(`${url}/voice/album/units?album_id=${id}&page=1&num=200&order=1`);
  58. let data = JSON.parse(content).data;
  59. let book = {
  60. book_id: id,
  61. type_name: '',
  62. book_year: '',
  63. book_area: '',
  64. book_remarks: '',
  65. book_actor: '',
  66. book_director: '',
  67. book_content: '',
  68. };
  69. let us = _.map(data.list, function (b) {
  70. return formatPlayUrl(b.title) + '$' + b.file;
  71. }).join('#');
  72. book.volumes = '书卷';
  73. book.urls = us;
  74. return JSON.stringify({
  75. list: [book],
  76. });
  77. }
  78. function formatPlayUrl(name) {
  79. return name
  80. .trim()
  81. .replace(/<|>|《|》/g, '')
  82. .replace(/\$|#/g, ' ')
  83. .trim();
  84. }
  85. async function proxy(segments, headers) {}
  86. async function play(flag, id, flags) {
  87. return JSON.stringify({
  88. parse: 0,
  89. url: id,
  90. });
  91. }
  92. async function search(wd, quick, pg) {
  93. pg = pg || 1;
  94. if (pg == 0) pg = 1;
  95. let content = await request(`https://es.bookan.com.cn/api/v3/voice/book?instanceId=25304&keyword=${wd}&pageNum=${pg}&limitNum=20`);
  96. let data = JSON.parse(content).data;
  97. let books = [];
  98. for (const book of data.list) {
  99. books.push({
  100. book_id: book.id,
  101. book_name: book.name,
  102. book_pic: book.cover,
  103. book_remarks: book.extra.author,
  104. });
  105. }
  106. return JSON.stringify({
  107. page: data.current_page,
  108. pagecount: data.last_page,
  109. limit: 20,
  110. total: data.total,
  111. list: books,
  112. });
  113. }
  114. export function __jsEvalReturn() {
  115. return {
  116. init: init,
  117. home: home,
  118. category: category,
  119. detail: detail,
  120. play: play,
  121. search: search,
  122. };
  123. }