230ts_book_open.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. // 网站搜索异常
  2. import { load, _ } from './lib/cat.js';
  3. let key = '爱上你听书网';
  4. let HOST = 'https://wap.230ts.net';
  5. let siteKey = '';
  6. let siteType = 0;
  7. const MOBILE_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';
  8. async function request(reqUrl, agentSp) {
  9. let res = await req(reqUrl, {
  10. method: 'get',
  11. headers: {
  12. 'User-Agent': agentSp || MOBILE_UA,
  13. 'Referer': HOST
  14. },
  15. });
  16. return res.content;
  17. }
  18. // cfg = {skey: siteKey, ext: extend}
  19. async function init(cfg) {
  20. siteKey = cfg.skey;
  21. siteType = cfg.stype;
  22. }
  23. async function home(filter) {
  24. const html = await request(HOST + '/sort/');
  25. const $ = load(html);
  26. let filterObj = {};
  27. const class_parse = $('dl.pd-class:first > dd > a[href*=sort]');
  28. let classes = [];
  29. classes = _.map(class_parse, (cls) => {
  30. let typeId = cls.attribs['href'];
  31. typeId = typeId.replace(/.*?\/sort\/(.*).html/g, '$1');
  32. return {
  33. type_id: typeId,
  34. type_name: cls.children[0].data,
  35. };
  36. });
  37. const sortName = ['玄幻有声', '灵异有声', '综艺娱乐', '长篇评书', '都市有声', '军事有声', '职场有声', '其他有声'];
  38. classes = _.sortBy(classes, (c) => {
  39. const index = sortName.indexOf(c.type_name);
  40. return index === -1 ? sortName.length : index;
  41. });
  42. return JSON.stringify({
  43. class: classes,
  44. filters: filterObj,
  45. });
  46. }
  47. async function homeVod() {
  48. const link = HOST + '/top/lastupdate/1.html';
  49. const html = await request(link);
  50. const $ = load(html);
  51. const items = $('ul.list-ul > li');
  52. let videos = _.map(items, (item) => {
  53. const it = $(item).find('a:first')[0];
  54. const img = $(item).find('img:first')[0];
  55. const remarks = $($(item).find('p.module-slide-author')[0]).text().trim();
  56. return {
  57. vod_id: it.attribs.href.replace(/.*?\/tingshu\/(.*)/g, '$1'),
  58. vod_name: it.attribs.title.replace('有声小说',''),
  59. vod_pic: HOST + img.attribs['data-original'],
  60. vod_remarks: remarks || '',
  61. };
  62. });
  63. return JSON.stringify({
  64. list: videos,
  65. });
  66. }
  67. async function category(tid, pg, filter, extend) {
  68. if (pg <= 0) pg = 1;
  69. const link = HOST + '/sort/' + tid +'/' + (`${pg}`) + '.html';
  70. const html = await request(link);
  71. const $ = load(html);
  72. const items = $('ul.book-ol > li');
  73. let videos = _.map(items, (item) => {
  74. const it = $(item).find('a:first')[0];
  75. const img = $(item).find('img:first')[0];
  76. const remarks = $($(item).find('div.book-meta')[0]).text().trim();
  77. return {
  78. book_id: it.attribs.href.replace(/.*?\/tingshu\/(.*)/g, '$1'),
  79. book_name: it.attribs.title.replace('有声小说',''),
  80. book_pic: HOST + img.attribs['data-original'],
  81. book_remarks: remarks.replace('佚名(著)','').replace('佚名(播)','').replace('未知(著)','').replace('未知(播)','') || '',
  82. };
  83. });
  84. const hasMore = $('div.paging > a:contains(下一页)').length > 0;
  85. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  86. return JSON.stringify({
  87. page: parseInt(pg),
  88. pagecount: pgCount,
  89. limit: 24,
  90. total: 24 * pgCount,
  91. list: videos,
  92. });
  93. }
  94. async function detail(id) {
  95. const html = await request(HOST + '/tingshu/' + id);
  96. const $ = load(html);
  97. const detail = $('div.book-cell:first > div');
  98. let vod = {
  99. book_id: id,
  100. type_name: $('h1:first').text().trim().replace('有声小说',''),
  101. // vod_pic: HOST + $('div.myui-content__thumb img:first').attr('data-original'),
  102. // vod_content: $('div.ellipsis').text().trim(),
  103. book_year: '',
  104. book_area: '',
  105. book_remarks: '',
  106. book_actor: '',
  107. book_director: '',
  108. book_content: '',
  109. };
  110. // for (const info of detail) {
  111. // const i = $(info).text().trim();
  112. // if (i.startsWith('类型:')) {
  113. // vod.vod_type = _.map($(info).find('a'), (a) => {
  114. // return a.children[0].data;
  115. // }).join('/');
  116. // } else if (i.startsWith('作者:')) {
  117. // vod.vod_director = _.map($(info).find('a'), (a) => {
  118. // return a.children[0].data;
  119. // }).join('/');
  120. // } else if (i.startsWith('演播:')) {
  121. // vod.vod_actor = _.map($(info).find('a'), (a) => {
  122. // return a.children[0].data;
  123. // }).join('/');
  124. // } else if (i.startsWith('连载中')) {
  125. // vod.vod_remarks = i.substring(3);
  126. // }
  127. // }
  128. const playlist = _.map($('#playlist > ul > li > a'), (it) => {
  129. return it.children[0].data + '$' + it.attribs.href.replace(/\/mp3\/(.*).html/g, '$1');
  130. }).join("#");
  131. vod.volumes = '道长在线';
  132. vod.urls = playlist;
  133. // vod.vod_play_from = '道长在线';
  134. // vod.vod_play_url = playlist.join('#');
  135. return JSON.stringify({
  136. list: [vod],
  137. });
  138. }
  139. async function play(flag, id, flags) {
  140. const link = HOST + '/mp3/' + id + '.html';
  141. const html = await request(link);
  142. const $ = load(html);
  143. const iframe = $('body iframe[src*=player]');
  144. const iframeHtml = (
  145. await req(HOST + iframe[0].attribs.src, {
  146. headers: {
  147. 'Referer': link,
  148. 'User-Agent': MOBILE_UA,
  149. },
  150. })
  151. ).content;
  152. const playUrl = iframeHtml.match(/mp3:'(.*?)'/)[1];
  153. if (playUrl.indexOf('m4a') >= 0 || playUrl.indexOf('mp3') >= 0 ) {
  154. return JSON.stringify({
  155. parse: 0,
  156. url: playUrl,
  157. });
  158. } else {
  159. try {
  160. const iframeHtml = (
  161. await req(HOST + iframe[0].attribs.src, {
  162. headers: {
  163. 'Referer': link,
  164. 'User-Agent': MOBILE_UA,
  165. },
  166. })
  167. ).content;
  168. const playUrl = playUrl + '.m4a' + iframeHtml.match(/(\?.*?)'/)[1];
  169. if (playUrl.indexOf('http') >= 0) {
  170. return JSON.stringify({
  171. parse: 0,
  172. url: playUrl,
  173. });
  174. } else {
  175. const iframeHtml = (
  176. await req(HOST + iframe[0].attribs.src, {
  177. headers: {
  178. 'Referer': link,
  179. 'User-Agent': MOBILE_UA,
  180. },
  181. })
  182. ).content;
  183. const playUrl2 = iframeHtml.match(/url[\s\S]*?(http.*?)'/)[1];
  184. if (playUrl2.indexOf('\?') >= 0) {
  185. return JSON.stringify({
  186. parse: 0,
  187. url: playUrl2,
  188. });
  189. } else {
  190. const playUrl3 = playUrl2 + playUrl
  191. return JSON.stringify({
  192. parse: 0,
  193. url: playUrl3,
  194. });
  195. }
  196. }
  197. } catch (e) {}
  198. if (playUrl.indexOf('http') >= 0) {
  199. const playUrl = playUrl + '.m4a';
  200. return JSON.stringify({
  201. parse: 0,
  202. url: playUrl,
  203. });
  204. } else {
  205. const iframeHtml = (
  206. await req(HOST + iframe[0].attribs.src, {
  207. headers: {
  208. 'Referer': link,
  209. 'User-Agent': MOBILE_UA,
  210. },
  211. })
  212. ).content;
  213. const playUrl4 = iframeHtml.match(/url[\s\S]*?(http.*?)'/)[1];
  214. return JSON.stringify({
  215. parse: 0,
  216. url: playUrl4 + '.m4a',
  217. });
  218. }
  219. }
  220. }
  221. async function search(wd, quick) {
  222. const link = HOST + '/search.html?searchtype=name&searchword=' + wd +'&page=1';
  223. const html = await request(link);
  224. const $ = load(html);
  225. const items = $('ul.book-ol > li');
  226. let videos = _.map(items, (item) => {
  227. const it = $(item).find('a:first')[0];
  228. const img = $(item).find('img:first')[0];
  229. const remarks = $($(item).find('div.book-meta')[0]).text().trim();
  230. return {
  231. book_id: it.attribs.href.replace(/.*?\/tingshu\/(.*)/g, '$1'),
  232. book_name: it.attribs.title.replace('有声小说',''),
  233. book_pic: img.attribs['data-original'],
  234. book_remarks: remarks.replace('佚名(著)','').replace('佚名(播)','').replace('未知(著)','').replace('未知(播)','') || '',
  235. };
  236. });
  237. return JSON.stringify({
  238. list: videos,
  239. });
  240. }
  241. export function __jsEvalReturn() {
  242. return {
  243. init: init,
  244. home: home,
  245. homeVod: homeVod,
  246. category: category,
  247. detail: detail,
  248. play: play,
  249. search: search,
  250. };
  251. }