mhdq.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * @File : mhdq.js
  3. * @Author : jade
  4. * @Date : 2024/1/24 9:15
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc : 18+韩漫
  8. */
  9. import {Spider} from "./spider.js";
  10. import {BookDetail, BookShort} from "../lib/book.js";
  11. class MHDQSpider extends Spider {
  12. constructor() {
  13. super();
  14. this.siteUrl = 'https://www.18hanman.com';
  15. }
  16. getName() {
  17. return "🔞|韩漫18|🔞"
  18. }
  19. getAppName() {
  20. return "韩漫18"
  21. }
  22. getJSName() {
  23. return "mhdq"
  24. }
  25. getType() {
  26. return 20
  27. }
  28. async setClasses() {
  29. this.classes = []
  30. let $ = await this.getHtml(this.siteUrl + "/category/")
  31. for (const a of $('div.classopen ul.duzhe a[href!="/"]')) {
  32. this.classes.push({
  33. type_id: a.attribs.href,
  34. type_name: a.children[0].data.trim()
  35. });
  36. }
  37. }
  38. async parseVodShortListFromDocByCategory($) {
  39. const list = eval($('div[class="row exemptComic-box"]')[0].attribs.list);
  40. let books = [];
  41. for (const book of list) {
  42. let bookShort = this.parseVodShortFromJson(book)
  43. books.push(bookShort)
  44. }
  45. return books
  46. }
  47. parseVodShortFromElement($, element) {
  48. let bookShort = new BookShort()
  49. const a = $(element).find('a:first')[0];
  50. const img = $(element).find('img:first-child')[0];
  51. bookShort.book_id = a.attribs.href
  52. bookShort.book_name = $($(element).find("a").slice(-1)[0]).html()
  53. bookShort.book_pic = img.attribs.src
  54. bookShort.book_remarks = $($(element).find("span")).text()
  55. return bookShort
  56. }
  57. async parseVodShortListFromDoc($) {
  58. let vodElements = $('ul.catagory-list li')
  59. let books = []
  60. for (const vodElement of vodElements) {
  61. let bookShort = await this.parseVodShortFromElement($, vodElement)
  62. books.push(bookShort)
  63. }
  64. return books
  65. }
  66. async parseVodShortListFromDocBySearch($) {
  67. let vodElements = $('ul.u_list')
  68. let books = []
  69. for (const vodElement of vodElements) {
  70. let bookShort = await this.parseVodShortFromElement($, vodElement)
  71. books.push(bookShort)
  72. }
  73. return books
  74. }
  75. async parseVodDetailFromDoc($, id) {
  76. let html = $.html()
  77. let bookDetail = new BookDetail()
  78. bookDetail.book_id = id
  79. bookDetail.book_name = $('div.title:first').text().trim()
  80. bookDetail.pic = $($('div.img:first-child')).find("img")[0].attribs.src
  81. let contentElements = $('div.info ').find("p")
  82. for (const contentElelent of contentElements) {
  83. if ($(contentElelent).text().indexOf("更新至")) {
  84. bookDetail.book_remarks = $(contentElelent).text().replaceAll("更新至:","")
  85. }
  86. if ($(contentElelent).text().indexOf("作者")) {
  87. bookDetail.book_director = $(contentElelent).text().replaceAll("作者:","")
  88. }
  89. }
  90. bookDetail.book_content = $("[class=\"text\"]").text()
  91. let urls = [];
  92. const links = $('ul.list a[href!="/"]');
  93. for (const l of links) {
  94. let name = l.children[0].data;
  95. let link = l.attribs.href;
  96. urls.push(name + '$' + link);
  97. }
  98. bookDetail.volumes = '全卷';
  99. bookDetail.urls = urls.join('#');
  100. return bookDetail
  101. }
  102. async setCategory(tid, pg, filter, extend) {
  103. const $ = await this.getHtml(this.siteUrl + `${tid}/page/${pg}`)
  104. this.vodList = await this.parseVodShortListFromDoc($)
  105. }
  106. async setDetail(id) {
  107. let $ = await this.getHtml(this.siteUrl + `${id}`)
  108. this.vodDetail = await this.parseVodDetailFromDoc($, id)
  109. }
  110. async setPlay(flag, id, flags) {
  111. const $ = await this.getHtml(this.siteUrl + id);
  112. let content = [];
  113. for (const l of $('div.chapterbox img')) {
  114. const img = $(l).attr('src');
  115. content.push(img);
  116. }
  117. this.playUrl = {
  118. "content": content,
  119. }
  120. }
  121. async setSearch(wd, quick) {
  122. const $ = await this.getHtml(this.siteUrl + `/index.php/search?key=${wd}`);
  123. this.vodList = await this.parseVodShortListFromDocBySearch($)
  124. }
  125. }
  126. let spider = new MHDQSpider()
  127. async function init(cfg) {
  128. await spider.init(cfg)
  129. }
  130. async function home(filter) {
  131. return await spider.home(filter)
  132. }
  133. async function homeVod() {
  134. return await spider.homeVod()
  135. }
  136. async function category(tid, pg, filter, extend) {
  137. return await spider.category(tid, pg, filter, extend)
  138. }
  139. async function detail(id) {
  140. return await spider.detail(id)
  141. }
  142. async function play(flag, id, flags) {
  143. return await spider.play(flag, id, flags)
  144. }
  145. async function search(wd, quick) {
  146. return await spider.search(wd, quick)
  147. }
  148. export function __jsEvalReturn() {
  149. return {
  150. init: init, home: home, homeVod: homeVod, category: category, detail: detail, play: play, search: search,
  151. };
  152. }
  153. export {spider}