baozimh_open.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { Crypto, _, load } from './lib/cat.js';
  2. let key = 'baozimh';
  3. let url = 'https://cn.baozimh.com';
  4. const img = 'https://static-tw.baozimh.com/cover/';
  5. const img2 = '?w=285&h=375&q=100';
  6. let siteKey = '';
  7. let siteType = 0;
  8. const UA = 'Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36';
  9. async function request(reqUrl) {
  10. let resp = await req(reqUrl, {
  11. headers: {
  12. 'User-Agent': UA,
  13. },
  14. });
  15. return resp.content;
  16. }
  17. // cfg = {skey: siteKey, ext: extend}
  18. async function init(cfg) {
  19. siteKey = cfg.skey;
  20. siteType = cfg.stype;
  21. }
  22. async function home(filter) {
  23. var html = await request(url + '/classify');
  24. const $ = load(html);
  25. let filterObj = { c1: [] };
  26. for (const nav of $('div.classify div.nav')) {
  27. const as = $(nav).find('a.item');
  28. const checkUrl = decodeURIComponent(as[1].attribs.href);
  29. const reg = /type=(.*)&region=(.*)&state=(.*)&filter=(.*)/;
  30. const matchs = checkUrl.match(reg);
  31. let typeKey = '';
  32. let typeIdx = 1;
  33. if (matchs[1] != 'all') {
  34. typeKey = 'type';
  35. typeIdx = 1;
  36. } else if (matchs[2] != 'all') {
  37. typeKey = 'region';
  38. typeIdx = 2;
  39. } else if (matchs[3] != 'all') {
  40. typeKey = 'state';
  41. typeIdx = 3;
  42. } else if (matchs[4] != '*') {
  43. typeKey = 'filter';
  44. typeIdx = 4;
  45. }
  46. const tvals = [];
  47. for (const a of as) {
  48. tvals.push({
  49. n: $(a).text().trim(),
  50. v: decodeURIComponent(a.attribs.href).match(reg)[typeIdx],
  51. });
  52. }
  53. filterObj['c1'].push({
  54. key: typeKey,
  55. name: '',
  56. wrap: typeIdx == 1 ? 1 : 0,
  57. init: typeIdx == 4 ? '*' : 'all',
  58. value: tvals,
  59. });
  60. }
  61. return {
  62. class: [{ type_name: 'all', type_id: 'c1' }],
  63. filters: filterObj,
  64. };
  65. }
  66. async function category(tid, pg, filter, extend) {
  67. if (pg == 0) pg = 1;
  68. let link = `${url}/api/bzmhq/amp_comic_list?type=${extend.type || 'all'}&region=${extend.region || 'all'}&state=${extend.state || 'all'}&filter=${extend.filter || '*'}`;
  69. link += '&page=' + pg + '&limit=36&language=cn';
  70. var html = await request(link);
  71. const data = JSON.parse(html);
  72. let books = [];
  73. for (const book of data.items) {
  74. books.push({
  75. book_id: book.comic_id,
  76. book_name: book.name,
  77. book_pic: img + book.topic_img + img2,
  78. book_remarks: book.author || '',
  79. });
  80. }
  81. return {
  82. page: pg,
  83. pagecount: books.length == 36 ? pg + 1 : pg,
  84. list: books,
  85. };
  86. }
  87. async function detail(id) {
  88. var html = await request(`${url}/comic/${id}`);
  89. const $ = load(html);
  90. let book = {
  91. book_director: $('[data-hid$=og:novel:author]')[0].attribs.content || '',
  92. book_content: $('[data-hid$=og:description]')[0].attribs.content || '',
  93. };
  94. const formatUrl = (a) => {
  95. return $(a).text().replace(/\$|#/g, ' ').trim() + '$' + decodeURIComponent(a.attribs.href);
  96. };
  97. let urls = _.map($('div#chapter-items a.comics-chapters__item'), formatUrl);
  98. urls.push(..._.map($('div#chapters_other_list a.comics-chapters__item'), formatUrl));
  99. if (urls.length == 0) {
  100. urls = _.reverse(_.map($('div.pure-g a.comics-chapters__item'), formatUrl));
  101. }
  102. book.volumes = '默認';
  103. book.urls = urls.join('#');
  104. return {
  105. list: [book],
  106. };
  107. }
  108. async function play(flag, id, flags) {
  109. try {
  110. var html = await request(url + id);
  111. const $ = load(html);
  112. var content = [];
  113. for (const img of $('amp-img')) {
  114. content.push(img.attribs.src);
  115. }
  116. return {
  117. content: content,
  118. };
  119. } catch (e) {}
  120. return {
  121. content: [],
  122. };
  123. }
  124. async function search(wd, quick, pg) {
  125. var html = await request(`${url}/search?q=${wd}`);
  126. const $ = load(html);
  127. const books = [];
  128. for (const a of $('div.classify-items a.comics-card__poster')) {
  129. books.push({
  130. book_id: a.attribs.href.replace('/comic/', ''),
  131. book_name: a.attribs.title,
  132. book_pic: $(a).find('amp-img:first')[0].attribs.src,
  133. book_remarks: '',
  134. });
  135. }
  136. return {
  137. page: 1,
  138. pagecount: 1,
  139. list: books,
  140. };
  141. }
  142. export function __jsEvalReturn() {
  143. return {
  144. init: init,
  145. home: home,
  146. category: category,
  147. detail: detail,
  148. play: play,
  149. search: search,
  150. };
  151. }