doll.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * @File : doll.js
  3. * @Author : jade
  4. * @Date : 2024/1/4 14:15
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc : doll
  8. */
  9. import {Spider} from "./spider.js";
  10. import {Crypto, load} from "../lib/cat.js";
  11. import {VodDetail, VodShort} from "../lib/vod.js";
  12. import * as Utils from "../lib/utils.js";
  13. class Doll extends Spider {
  14. constructor() {
  15. super();
  16. this.siteUrl = "https://hongkongdollvideo.com"
  17. }
  18. getImgHeader(){
  19. let headers = this.getHeader()
  20. headers["Proxy"] = true
  21. return headers
  22. }
  23. async spiderInit(inReq = null) {
  24. if (inReq !== null) {
  25. this.jsBase = await js2Proxy(inReq, "img", this.getImgHeader());
  26. } else {
  27. this.jsBase = await js2Proxy(true, this.siteType, this.siteKey, 'img/', this.getImgHeader());
  28. }
  29. }
  30. async init(cfg) {
  31. await super.init(cfg);
  32. await this.spiderInit(null)
  33. }
  34. async getHtml(url = this.siteUrl, proxy = false, headers = this.getHeader()) {
  35. return super.getHtml(url, true, headers);
  36. }
  37. getName() {
  38. return "🔞┃玩偶姐姐┃🔞"
  39. }
  40. getAppName() {
  41. return "玩偶姐姐"
  42. }
  43. getJSName() {
  44. return "doll"
  45. }
  46. getType() {
  47. return 3
  48. }
  49. async parseVodShortListFromDoc($) {
  50. let vod_list = []
  51. let vodElements = $("[class=\"row\"]").find("[class=\"video-detail\"]")
  52. for (const vodElement of vodElements) {
  53. let vodShort = new VodShort()
  54. vodShort.vod_id = $(vodElement).find("a")[0].attribs["href"]
  55. let videoInfoElements = $($(vodElement).find("[class=\"video-info\"]")).find("a")
  56. vodShort.vod_name = videoInfoElements[0].attribs["title"]
  57. vodShort.vod_remarks = $(videoInfoElements[1]).text()
  58. let pic = $(vodElement).find("img")[0].attribs["data-src"]
  59. // if (this.catOpenStatus) {
  60. // vodShort.vod_pic = this.jsBase + Utils.base64Encode(pic)
  61. // } else {
  62. // vodShort.vod_pic = pic
  63. // }
  64. vodShort.vod_pic = pic
  65. vod_list.push(vodShort)
  66. }
  67. return vod_list
  68. }
  69. async parseVodDetailFromDoc($, key) {
  70. let vodDetail = new VodDetail()
  71. let vodElement = $("[class=\"container-fluid\"]")
  72. vodDetail.vod_name = $($(vodElement).find("[class=\"page-title\"]")[0]).text()
  73. vodDetail.vod_remarks = $(vodElement).find("[class=\"tag my-1 text-center\"]")[0].attribs["href"].replaceAll("/", "")
  74. let pic = $(vodElement).find("video")[0].attribs["poster"]
  75. // if (this.catOpenStatus) {
  76. // vodDetail.vod_pic = this.jsBase + Utils.base64Encode(pic)
  77. // } else {
  78. // vodDetail.vod_pic = pic
  79. // }
  80. vodDetail.vod_pic = pic
  81. let html = $.html()
  82. let voteTag = Utils.getStrByRegex(/var voteTag="(.*?)";/g, html)
  83. // let videoInfoStr = Utils.getStrByRegex(/<script type="application\/ld\+json">(.*?)<\/script>/g, html)
  84. // let videoInfo = JSON.parse(videoInfoStr)
  85. //
  86. // try {
  87. // let play_url_1 = await this.fetch(videoInfo["contentUrl"], null, this.getHeader())
  88. // await this.jadeLog.debug(`播放链接为:${play_url_1}`)
  89. // } catch (e) {
  90. // await this.jadeLog.error(e)
  91. // }
  92. voteTag = Crypto.enc.Utf8.stringify(Crypto.enc.Base64.parse(voteTag))
  93. let code = []
  94. for (let i = 0; i < voteTag.length; i++) {
  95. let k = i % key.length;
  96. code.push(String.fromCharCode(voteTag.charCodeAt(i) ^ key.charCodeAt(k)))
  97. }
  98. let play_url_2 = decodeURIComponent(Crypto.enc.Utf8.stringify(Crypto.enc.Base64.parse(code.join(""))))
  99. vodDetail.vod_play_from = "玩偶姐姐"
  100. vodDetail.vod_play_url = "玩偶姐姐" + "$" + play_url_2
  101. return vodDetail
  102. }
  103. async setClasses() {
  104. let $ = await this.getHtml(this.siteUrl)
  105. let navElements = $("[class=\"list-unstyled topnav-menu d-flex d-lg-block align-items-center justify-content-center flex-fill topnav-menu-left m-0\"]").find("li")
  106. let index = 1
  107. let class_id = index.toString()
  108. this.classes = []
  109. this.classes.push({"type_name": "首页", "type_id": "1"})
  110. this.filterObj[class_id] = []
  111. for (const navElement of navElements) {
  112. let type_list = $(navElement).text().split("\n")
  113. let valueElements = $(navElement).find("a")
  114. let valueList = [{"n": "全部", "v": class_id}]
  115. let type_id = index.toString()
  116. for (const valueElement of valueElements) {
  117. let title = $(valueElement).text().replaceAll("\n", "")
  118. let href = valueElement.attribs["href"]
  119. if (href !== undefined) {
  120. valueList.push({"n": title, "v": href})
  121. }
  122. }
  123. type_list = type_list.filter(element => element !== "");
  124. this.filterObj[class_id].push({"key": type_id, "name": type_list[0], "value": valueList})
  125. //下面这段是为了切割使用
  126. // let new_value_list = []
  127. // for (let i = 0; i < valueList.length; i++) {
  128. // new_value_list.push(valueList[i])
  129. // if (i % 8 === 0 && i !== 0) {
  130. // this.filterObj[class_id].push({"key": type_id, "name": type_list[0], "value": new_value_list})
  131. // new_value_list = []
  132. // }
  133. // }
  134. // this.filterObj[class_id].push({"key": type_id, "name": type_list[0], "value": new_value_list})
  135. }
  136. let menuElements = $("[id=\"side-menu\"]").find("li")
  137. for (const menuElement of menuElements) {
  138. let type_id = $(menuElement).find("a")[0].attribs["href"]
  139. if (type_id !== undefined && type_id.indexOf(this.siteUrl) > -1) {
  140. let type_dic = {
  141. "type_name": $(menuElement).text(), "type_id": type_id
  142. }
  143. this.classes.push(type_dic)
  144. }
  145. }
  146. }
  147. async setHomeVod() {
  148. let $ = await this.getHtml(this.siteUrl)
  149. this.homeVodList = await this.parseVodShortListFromDoc($)
  150. }
  151. async setCategory(tid, pg, filter, extend) {
  152. if (extend["1"] !== undefined) {
  153. if (extend["1"] !== "1") {
  154. tid = extend[1]
  155. }
  156. }
  157. await this.jadeLog.info(`tid = ${tid}`)
  158. let cateUrl = ""
  159. if (tid.indexOf(this.siteUrl) > -1) {
  160. cateUrl = tid + pg.toString() + ".html"
  161. } else {
  162. cateUrl = this.siteUrl
  163. }
  164. this.limit = 36
  165. let $ = await this.getHtml(cateUrl)
  166. this.vodList = await this.parseVodShortListFromDoc($)
  167. }
  168. async setDetail(id) {
  169. let $ = await this.getHtml(id)
  170. let key = Utils.getStrByRegex(/video\/(\w+).html/, id)
  171. this.vodDetail = await this.parseVodDetailFromDoc($, key)
  172. }
  173. async setPlay(flag, id, flags) {
  174. this.playUrl = id
  175. this.playHeader = {}
  176. }
  177. async setSearch(wd, quick) {
  178. let searchUrl = this.siteUrl + "search/" + encodeURIComponent(wd)
  179. let $ = await this.getHtml(searchUrl)
  180. this.vodList = await this.parseVodShortListFromDoc($)
  181. }
  182. async proxy(segments, headers) {
  183. return super.proxy(segments, headers);
  184. }
  185. }
  186. let spider = new Doll()
  187. async function init(cfg) {
  188. await spider.init(cfg)
  189. }
  190. async function home(filter) {
  191. return await spider.home(filter)
  192. }
  193. async function homeVod() {
  194. return await spider.homeVod()
  195. }
  196. async function category(tid, pg, filter, extend) {
  197. return await spider.category(tid, pg, filter, extend)
  198. }
  199. async function detail(id) {
  200. return await spider.detail(id)
  201. }
  202. async function play(flag, id, flags) {
  203. return await spider.play(flag, id, flags)
  204. }
  205. async function search(wd, quick) {
  206. return await spider.search(wd, quick)
  207. }
  208. export function __jsEvalReturn() {
  209. return {
  210. init: init, home: home, homeVod: homeVod, category: category, detail: detail, play: play, search: search,
  211. };
  212. }
  213. export {spider}