liujiushu.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * @File : liujiushu.js
  3. * @Author : jade
  4. * @Date : 2024/04/23 10:02
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc :
  8. */
  9. import {_, load} from '../lib/cat.js';
  10. import * as Utils from "../lib/utils.js";
  11. import {Spider} from "./spider.js";
  12. import {BookDetail, BookShort} from "../lib/book.js";
  13. import {formatContent} from "../lib/utils.js";
  14. class LiuJiuShuSpider extends Spider {
  15. constructor() {
  16. super();
  17. this.siteUrl = "https://www.diyi69.com"
  18. }
  19. getAppName() {
  20. return "六九书吧"
  21. }
  22. getJSName() {
  23. return "liujiushu"
  24. }
  25. getType() {
  26. return 10
  27. }
  28. getName() {
  29. return "📚︎┃六九书吧┃📚︎"
  30. }
  31. async spiderInit(inReq = null) {
  32. if (inReq !== null) {
  33. this.jsBase = await js2Proxy(inReq, "img", this.getHeader());
  34. } else {
  35. this.jsBase = await js2Proxy(true, this.siteType, this.siteKey, 'img/', this.getHeader());
  36. }
  37. }
  38. async init(cfg) {
  39. await super.init(cfg);
  40. await this.spiderInit(null)
  41. }
  42. parseVodShortFromElement($, element) {
  43. let bookShort = new BookShort()
  44. let bookShortElements = $(element).find("a")
  45. bookShort.book_remarks = $(bookShortElements[2]).text()
  46. bookShort.book_name = $(bookShortElements[1]).text()
  47. bookShort.book_id = bookShortElements[0].attribs.href
  48. bookShort.book_pic = $(element).find("img")[0].attribs["src"]
  49. return bookShort
  50. }
  51. async parseVodShortListFromDoc($) {
  52. let books = []
  53. let bookElements = $($("[class=\"flex\"]")[0]).find("li")
  54. for (const bookElement of bookElements) {
  55. let bookShort = this.parseVodShortFromElement($, bookElement)
  56. books.push(bookShort)
  57. }
  58. return books
  59. }
  60. async parseVodShortListFromDocByCategory($) {
  61. let bookElements = $("ul.flex > li")
  62. let books = [];
  63. for (const item of bookElements) {
  64. let bookShort = new BookShort()
  65. bookShort.book_id = $(item).find('a:first')[0].attribs.href;
  66. const img = $(item).find('img:first')[0];
  67. bookShort.book_name = img.attribs.title
  68. bookShort.book_pic = img.attribs["data-original"]
  69. bookShort.book_remarks = $($(item).find('em:first')).text();
  70. books.push(bookShort)
  71. }
  72. return books
  73. }
  74. async parseVodShortListFromDocBySearch($) {
  75. let books = []
  76. let bookElements = $('li.searchresult')
  77. for (const bookElement of bookElements) {
  78. let bookShort = new BookShort()
  79. let bookShortElements = $(bookElement).find("a")
  80. bookShort.book_remarks = $(bookShortElements[2]).text()
  81. bookShort.book_name = $(bookShortElements[1]).text()
  82. bookShort.book_id = bookShortElements[0].attribs.href
  83. bookShort.book_pic = $(bookShortElements[0]).find("img")[0].attribs["data-original"]
  84. books.push(bookShort)
  85. }
  86. return books
  87. }
  88. async parseVodDetailFromDoc($, id) {
  89. let html = $.html()
  90. let bookDetail = new BookDetail()
  91. bookDetail.book_name = $('[property$=title]')[0].attribs.content
  92. bookDetail.book_year = $('[property$=update_time]')[0].attribs.content
  93. bookDetail.book_director = $('[property$=author]')[0].attribs.content
  94. bookDetail.book_content = $('[property$=description]')[0].attribs.content
  95. bookDetail.book_remarks = $('[property$=category]')[0].attribs.content
  96. bookDetail.book_pic = $('div.novel_info_main>img')[0].attribs.src
  97. bookDetail.book_id = id
  98. const playBook = {};
  99. const sectionsElements = $("[class=\"flex ulcard\"]").find("li")
  100. const urlElements = $("[class=\"section chapter_list\"]")
  101. for (let i = 0; i < sectionsElements.length; i++) {
  102. const sectionElement = sectionsElements[i]
  103. const urlElemnet = urlElements[i]
  104. let vodItems = []
  105. for (const urlEle of $(urlElemnet).find("a")) {
  106. const epName = $(urlEle).text();
  107. const playUrl = epName + "-" + urlEle.attribs.href;
  108. vodItems.push(epName + '$' + playUrl)
  109. }
  110. let name = $($(urlElemnet).find("[class=\"title jcc\"]")).text()
  111. if (_.isEmpty(name)) {
  112. let text = $(sectionElement).text().split("(")[0]
  113. playBook[text] = vodItems.join("#")
  114. } else {
  115. name = name.replaceAll("《","").replaceAll("》","").replaceAll(bookDetail.book_name,"")
  116. playBook[name] = vodItems.reverse().join("#")
  117. }
  118. }
  119. bookDetail.volumes = _.keys(playBook).join('$$$');
  120. bookDetail.urls = _.values(playBook).join('$$$');
  121. return bookDetail
  122. }
  123. async setClasses() {
  124. let $ = await this.getHtml()
  125. for (const a of $('div.navigation > nav > a[href!="/"]')) {
  126. let type_id_list = a.attribs.href.split("/").slice(0, 3)
  127. this.classes.push({
  128. type_id: type_id_list.join("/"), type_name: a.children[0].data.trim(), tline: 2,
  129. });
  130. }
  131. }
  132. async setHomeVod() {
  133. let $ = await this.getHtml()
  134. this.homeVodList = await this.parseVodShortListFromDoc($)
  135. }
  136. async setDetail(id) {
  137. let $ = await this.getHtml(this.siteUrl + id)
  138. this.vodDetail = await this.parseVodDetailFromDoc($, id)
  139. }
  140. async setCategory(tid, pg, filter, extend) {
  141. let $ = await this.getHtml(this.siteUrl + `${tid}/${pg}.html`);
  142. this.vodList = await this.parseVodShortListFromDocByCategory($)
  143. }
  144. async setPlay(flag, id, flags) {
  145. let id_list = id.split("-")
  146. id = id_list[1]
  147. let content = id_list[0] + "\n\n"
  148. while (true) {
  149. let $ = await this.getHtml(this.siteUrl + id)
  150. content += Utils.formatContent($("[class=\"content\"]").html().trim().replaceAll("<p>", " ").replaceAll("</p>", "\n"));
  151. id = $("[id=\"next_url\"]")[0].attribs.href;
  152. if (id.indexOf('_') < 0) break;
  153. }
  154. this.playUrl = {"content": content}
  155. }
  156. async setSearch(wd, quick) {
  157. let params = {"searchkey": wd, "searchtype": "all", "Submit": ""}
  158. let content = await this.fetch(this.siteUrl + "/search/", params, this.getHeader())
  159. let $ = load(content)
  160. this.vodList = await this.parseVodShortListFromDocBySearch($)
  161. }
  162. async proxy(segments, headers) {
  163. await this.jadeLog.debug(`正在设置反向代理 segments = ${segments.join(",")},headers = ${JSON.stringify(headers)}`)
  164. let what = segments[0];
  165. let url = Utils.base64Decode(segments[1]);
  166. if (what === 'img') {
  167. await this.jadeLog.debug(`反向代理ID为:${url}`)
  168. let $ = await this.getHtml(this.siteUrl + url)
  169. let bookDetail = await this.parseVodDetailFromDoc($)
  170. let resp;
  171. if (!_.isEmpty(headers)) {
  172. resp = await req(bookDetail.book_pic, {
  173. buffer: 2, headers: headers
  174. });
  175. } else {
  176. resp = await req(bookDetail.book_pic, {
  177. buffer: 2, headers: {
  178. Referer: url, 'User-Agent': Utils.CHROME,
  179. },
  180. });
  181. }
  182. return JSON.stringify({
  183. code: resp.code, buffer: 2, content: resp.content, headers: resp.headers,
  184. });
  185. }
  186. return JSON.stringify({
  187. code: 500, content: '',
  188. });
  189. }
  190. }
  191. let spider = new LiuJiuShuSpider()
  192. async function init(cfg) {
  193. await spider.init(cfg)
  194. }
  195. async function home(filter) {
  196. return await spider.home(filter)
  197. }
  198. async function homeVod() {
  199. return await spider.homeVod()
  200. }
  201. async function category(tid, pg, filter, extend) {
  202. return await spider.category(tid, pg, filter, extend)
  203. }
  204. async function detail(id) {
  205. return await spider.detail(id)
  206. }
  207. async function play(flag, id, flags) {
  208. return await spider.play(flag, id, flags)
  209. }
  210. async function search(wd, quick) {
  211. return await spider.search(wd, quick)
  212. }
  213. async function proxy(segments, headers) {
  214. return await spider.proxy(segments, headers)
  215. }
  216. export function __jsEvalReturn() {
  217. return {
  218. init: init,
  219. home: home,
  220. homeVod: homeVod,
  221. category: category,
  222. detail: detail,
  223. play: play,
  224. search: search,
  225. proxy: proxy
  226. };
  227. }
  228. export {spider}