230ts_book_open.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. audio:1,
  100. book_id: id,
  101. type_name: $('h1:first').text().trim().replace('有声小说',''),
  102. // vod_pic: HOST + $('div.myui-content__thumb img:first').attr('data-original'),
  103. // vod_content: $('div.ellipsis').text().trim(),
  104. book_year: '',
  105. book_area: '',
  106. book_remarks: '',
  107. book_actor: '',
  108. book_director: '',
  109. book_content: '',
  110. };
  111. // for (const info of detail) {
  112. // const i = $(info).text().trim();
  113. // if (i.startsWith('类型:')) {
  114. // vod.vod_type = _.map($(info).find('a'), (a) => {
  115. // return a.children[0].data;
  116. // }).join('/');
  117. // } else if (i.startsWith('作者:')) {
  118. // vod.vod_director = _.map($(info).find('a'), (a) => {
  119. // return a.children[0].data;
  120. // }).join('/');
  121. // } else if (i.startsWith('演播:')) {
  122. // vod.vod_actor = _.map($(info).find('a'), (a) => {
  123. // return a.children[0].data;
  124. // }).join('/');
  125. // } else if (i.startsWith('连载中')) {
  126. // vod.vod_remarks = i.substring(3);
  127. // }
  128. // }
  129. const playlist = _.map($('#playlist > ul > li > a'), (it) => {
  130. return it.children[0].data + '$' + it.attribs.href.replace(/\/mp3\/(.*).html/g, '$1');
  131. }).join("#");
  132. vod.volumes = '道长在线';
  133. vod.urls = playlist;
  134. // vod.vod_play_from = '道长在线';
  135. // vod.vod_play_url = playlist.join('#');
  136. return JSON.stringify({
  137. list: [vod],
  138. });
  139. }
  140. async function play(flag, id, flags) {
  141. const link = HOST + '/mp3/' + id + '.html';
  142. const html = await request(link);
  143. const $ = load(html);
  144. const iframe = $('body iframe[src*=player]');
  145. const iframeHtml = (
  146. await req(HOST + iframe[0].attribs.src, {
  147. headers: {
  148. 'Referer': link,
  149. 'User-Agent': MOBILE_UA,
  150. },
  151. })
  152. ).content;
  153. const playUrl = iframeHtml.match(/mp3:'(.*?)'/)[1];
  154. if (playUrl.indexOf('m4a') >= 0 || playUrl.indexOf('mp3') >= 0 ) {
  155. return JSON.stringify({
  156. parse: 0,
  157. url: playUrl,
  158. });
  159. } else {
  160. try {
  161. const iframeHtml = (
  162. await req(HOST + iframe[0].attribs.src, {
  163. headers: {
  164. 'Referer': link,
  165. 'User-Agent': MOBILE_UA,
  166. },
  167. })
  168. ).content;
  169. const playUrl = playUrl + '.m4a' + iframeHtml.match(/(\?.*?)'/)[1];
  170. if (playUrl.indexOf('http') >= 0) {
  171. return JSON.stringify({
  172. parse: 0,
  173. url: playUrl,
  174. });
  175. } else {
  176. const iframeHtml = (
  177. await req(HOST + iframe[0].attribs.src, {
  178. headers: {
  179. 'Referer': link,
  180. 'User-Agent': MOBILE_UA,
  181. },
  182. })
  183. ).content;
  184. const playUrl2 = iframeHtml.match(/url[\s\S]*?(http.*?)'/)[1];
  185. if (playUrl2.indexOf('\?') >= 0) {
  186. return JSON.stringify({
  187. parse: 0,
  188. url: playUrl2,
  189. });
  190. } else {
  191. const playUrl3 = playUrl2 + playUrl
  192. return JSON.stringify({
  193. parse: 0,
  194. url: playUrl3,
  195. });
  196. }
  197. }
  198. } catch (e) {}
  199. if (playUrl.indexOf('http') >= 0) {
  200. const playUrl = playUrl + '.m4a';
  201. return JSON.stringify({
  202. parse: 0,
  203. url: playUrl,
  204. });
  205. } else {
  206. const iframeHtml = (
  207. await req(HOST + iframe[0].attribs.src, {
  208. headers: {
  209. 'Referer': link,
  210. 'User-Agent': MOBILE_UA,
  211. },
  212. })
  213. ).content;
  214. const playUrl4 = iframeHtml.match(/url[\s\S]*?(http.*?)'/)[1];
  215. return JSON.stringify({
  216. parse: 0,
  217. url: playUrl4 + '.m4a',
  218. });
  219. }
  220. }
  221. }
  222. async function search(wd, quick) {
  223. const link = HOST + '/search.html?searchtype=name&searchword=' + wd +'&page=1';
  224. const html = await request(link);
  225. const $ = load(html);
  226. const items = $('ul.book-ol > li');
  227. let videos = _.map(items, (item) => {
  228. const it = $(item).find('a:first')[0];
  229. const img = $(item).find('img:first')[0];
  230. const remarks = $($(item).find('div.book-meta')[0]).text().trim();
  231. return {
  232. book_id: it.attribs.href.replace(/.*?\/tingshu\/(.*)/g, '$1'),
  233. book_name: it.attribs.title.replace('有声小说',''),
  234. book_pic: img.attribs['data-original'],
  235. book_remarks: remarks.replace('佚名(著)','').replace('佚名(播)','').replace('未知(著)','').replace('未知(播)','') || '',
  236. };
  237. });
  238. return JSON.stringify({
  239. list: videos,
  240. });
  241. }
  242. export function __jsEvalReturn() {
  243. return {
  244. init: init,
  245. home: home,
  246. homeVod: homeVod,
  247. category: category,
  248. detail: detail,
  249. play: play,
  250. search: search,
  251. };
  252. }