bookan_open.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import { _ } from './lib/cat.js';
  2. let key = 'bookkan';
  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. audio: 1,
  61. book_id: id,
  62. type_name: '',
  63. book_year: '',
  64. book_area: '',
  65. book_remarks: '',
  66. book_actor: '',
  67. book_director: '',
  68. book_content: '',
  69. };
  70. let us = _.map(data.list, function (b) {
  71. return formatPlayUrl(b.title) + '$' + b.file;
  72. }).join('#');
  73. book.volumes = '书卷';
  74. book.urls = us;
  75. return JSON.stringify({
  76. list: [book],
  77. });
  78. }
  79. function formatPlayUrl(name) {
  80. return name
  81. .trim()
  82. .replace(/<|>|《|》/g, '')
  83. .replace(/\$|#/g, ' ')
  84. .trim();
  85. }
  86. async function proxy(segments, headers) {}
  87. async function play(flag, id, flags) {
  88. return JSON.stringify({
  89. parse: 0,
  90. url: id,
  91. });
  92. }
  93. async function search(wd, quick, pg) {
  94. pg = pg || 1;
  95. if (pg == 0) pg = 1;
  96. let content = await request(`https://es.bookan.com.cn/api/v3/voice/book?instanceId=25304&keyword=${wd}&pageNum=${pg}&limitNum=20`);
  97. let data = JSON.parse(content).data;
  98. let books = [];
  99. for (const book of data.list) {
  100. books.push({
  101. book_id: book.id,
  102. book_name: book.name,
  103. book_pic: book.cover,
  104. book_remarks: book.extra.author,
  105. });
  106. }
  107. return JSON.stringify({
  108. page: data.current_page,
  109. pagecount: data.last_page,
  110. limit: 20,
  111. total: data.total,
  112. list: books,
  113. });
  114. }
  115. export function __jsEvalReturn() {
  116. return {
  117. init: init,
  118. home: home,
  119. category: category,
  120. detail: detail,
  121. play: play,
  122. search: search,
  123. };
  124. }