bookan.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * @File : bookan.js
  3. * @Author : jade
  4. * @Date : 2024/1/31 13:44
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc :
  8. */
  9. import {_} from '../lib/cat.js';
  10. import {Spider} from "./spider.js";
  11. function formatPlayUrl(name) {
  12. return name
  13. .trim()
  14. .replace(/<|>|《|》/g, '')
  15. .replace(/\$|#/g, ' ')
  16. .trim();
  17. }
  18. class BooKanSpider extends Spider {
  19. constructor() {
  20. super();
  21. this.siteUrl = "https://api.bookan.com.cn";
  22. }
  23. getName() {
  24. return "🎵┃看书┃🎵"
  25. }
  26. getAppName() {
  27. return "看书"
  28. }
  29. getJSName() {
  30. return "bookan"
  31. }
  32. getType() {
  33. return 10
  34. }
  35. async parseVodShortListFromJson(obj) {
  36. let books = [];
  37. for (const book of obj.list) {
  38. books.push({
  39. book_id: book.id, book_name: book.name, book_pic: book.cover, book_remarks: book.extra.author,
  40. });
  41. }
  42. return books
  43. }
  44. async setClasses() {
  45. {
  46. this.classes = [{type_id: '1305', type_name: '少年读物'}, {
  47. type_id: '1304', type_name: '儿童文学'
  48. }, {type_id: '1320', type_name: '国学经典'}, {type_id: '1306', type_name: '文艺少年'}, {
  49. type_id: '1309', type_name: '育儿心经'
  50. }, {type_id: '1310', type_name: '心理哲学'}, {type_id: '1307', type_name: '青春励志'}, {
  51. type_id: '1312', type_name: '历史小说'
  52. }, {type_id: '1303', type_name: '故事会'}, {type_id: '1317', type_name: '音乐戏剧'}, {
  53. type_id: '1319', type_name: '相声评书'
  54. },]
  55. }
  56. }
  57. async setCategory(tid, pg, filter, extend) {
  58. let content = await this.fetch(`${this.siteUrl}/voice/book/list?instance_id=25304&page=${pg}&category_id=${tid}&num=24`, null, this.getHeader());
  59. let data = JSON.parse(content).data;
  60. this.vodList = await this.parseVodShortListFromJson(data)
  61. }
  62. async parseVodDetailfromJson(obj) {
  63. let book = {
  64. audio: 1,
  65. type_name: '',
  66. book_year: '',
  67. book_area: '',
  68. book_remarks: '',
  69. book_actor: '',
  70. book_director: '',
  71. book_content: '',
  72. };
  73. let us = _.map(obj.list, function (b) {
  74. return formatPlayUrl(b.title) + '$' + b.file;
  75. }).join('#');
  76. book.volumes = '书卷';
  77. book.urls = us;
  78. return book
  79. }
  80. async setDetail(id) {
  81. let content = await this.fetch(`${this.siteUrl}/voice/album/units?album_id=${id}&page=1&num=200&order=1`, null, this.getHeader());
  82. let data = JSON.parse(content).data;
  83. this.vodDetail = await this.parseVodDetailfromJson(data)
  84. this.vodDetail.book_id = id
  85. }
  86. async play(flag, id, flags) {
  87. return JSON.stringify({
  88. parse: 0, url: id,
  89. });
  90. }
  91. async setSearch(wd, quick) {
  92. let content = await this.fetch(`https://es.bookan.com.cn/api/v3/voice/book?instanceId=25304&keyword=${wd}&pageNum=1&limitNum=20`,null,this.getHeader());
  93. let data = JSON.parse(content).data;
  94. this.vodList = await this.parseVodShortListFromJson(data)
  95. }
  96. }
  97. let spider = new BooKanSpider()
  98. async function init(cfg) {
  99. await spider.init(cfg)
  100. }
  101. async function home(filter) {
  102. return await spider.home(filter)
  103. }
  104. async function homeVod() {
  105. return await spider.homeVod()
  106. }
  107. async function category(tid, pg, filter, extend) {
  108. return await spider.category(tid, pg, filter, extend)
  109. }
  110. async function detail(id) {
  111. return await spider.detail(id)
  112. }
  113. async function play(flag, id, flags) {
  114. return await spider.play(flag, id, flags)
  115. }
  116. async function search(wd, quick) {
  117. return await spider.search(wd, quick)
  118. }
  119. export function __jsEvalReturn() {
  120. return {
  121. init: init,
  122. home: home,
  123. homeVod: homeVod,
  124. category: category,
  125. detail: detail,
  126. play: play,
  127. search: search,
  128. };
  129. }
  130. export {spider}