lovemovie.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * @File : lovemovie.js
  3. * @Author : jade
  4. * @Date : 2024/4/29 09:36
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc : 爱情电影网
  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. import {gbk_us} from "../lib/gbk_us.js";
  14. class LoveMovieSpider extends Spider {
  15. constructor() {
  16. super();
  17. this.siteUrl = "https://b.aqdyje.com"
  18. this.removeKey = "骑兵营"
  19. }
  20. getName() {
  21. return "💕┃爱情电影网┃💕"
  22. }
  23. getAppName() {
  24. return "爱情电影网"
  25. }
  26. getJSName() {
  27. return "lovemovie"
  28. }
  29. getType() {
  30. return 3
  31. }
  32. async init(cfg) {
  33. await super.init(cfg);
  34. }
  35. async getHtml(url = this.siteUrl, proxy = false, headers = this.getHeader()) {
  36. let buffer = await this.fetch(url, null, headers, false, false, 1, proxy)
  37. let html = Utils.decode(buffer, "gb2312")
  38. await this.jadeLog.debug(`html content:${html}`)
  39. if (!_.isEmpty(html)) {
  40. return load(html)
  41. } else {
  42. return load(gbkDecode(buffer))
  43. }
  44. }
  45. async getFilter($, navElements) {
  46. let extend_list = []
  47. let extend_dic = {"key": "class", "name": "类型", "value": [this.getFliterDic("全部", "全部")]}
  48. for (const navElement of $(navElements).find("li")) {
  49. let element = $(navElement).find("a")[0]
  50. let type_name = $(element).text()
  51. let type_id = element.attribs.href
  52. extend_dic["value"].push(this.getFliterDic(type_name, type_id))
  53. }
  54. if (extend_dic["value"].length > 1) {
  55. extend_list.push(extend_dic)
  56. }
  57. return extend_list
  58. }
  59. async setClasses() {
  60. let $ = await this.getHtml()
  61. let navElements = $("[class=\"nav-item drop-down \"]")
  62. for (const navElement of navElements) {
  63. let elemenet = $(navElement).find("a")[0]
  64. let type_name = $(elemenet).text()
  65. let type_id = elemenet.attribs.href
  66. if (type_name !== this.removeKey) {
  67. this.classes.push(this.getTypeDic(type_name, type_id))
  68. this.filterObj[type_id] = await this.getFilter($, navElement)
  69. }
  70. }
  71. }
  72. async parseVodShortListFromDoc($) {
  73. let vod_list = []
  74. let vodElements = $("[class=\"play-img\"]")
  75. if (vodElements.length === 0) {
  76. vodElements = $("[class=\"show-list list-mode fn-clear\"]").find("li")
  77. }
  78. for (const vodElement of vodElements) {
  79. let vodShort = new VodShort()
  80. vodShort.vod_id = vodElement.attribs.href
  81. if (_.isEmpty(vodShort.vod_id)) {
  82. vodShort.vod_id = $(vodElement).find("a")[0].attribs.href
  83. }
  84. let imgElement = $(vodElement).find("img")[0]
  85. vodShort.vod_pic = imgElement.attribs.src
  86. vodShort.vod_name = imgElement.attribs.alt
  87. for (const element of $(vodElement).find("label")) {
  88. let text = $(element).text().trim()
  89. if (!_.isEmpty(text)) {
  90. vodShort.vod_remarks = text
  91. break
  92. }
  93. }
  94. if (_.isEmpty(vodShort.vod_remarks)) {
  95. vodShort.vod_remarks = $($(vodElement).find("p")[0]).text().replace("\n")
  96. }
  97. vod_list.push(vodShort)
  98. }
  99. return vod_list
  100. }
  101. async parseVodShortListFromDocBySearch($) {
  102. let vodElements = $("[class=\"show-list\"]").find("li")
  103. let vod_list = []
  104. for (const vodElement of vodElements) {
  105. let vodShort = new VodShort()
  106. vodShort.vod_id = $(vodElement).find("a")[0].attribs.href
  107. let imgElement = $(vodElement).find("img")[0]
  108. vodShort.vod_pic = imgElement.attribs.src
  109. vodShort.vod_name = imgElement.attribs.alt
  110. vodShort.vod_remarks = $($(vodElement).find("[class=\"type fn-left\"]")).text().replace("类型:", "")
  111. if (vodShort.vod_remarks !== "社处片" && vodShort.vod_remarks !== "社保片" && vodShort.vod_remarks !== "撸丝片" && vodShort.vod_remarks !== "撸丝动漫") {
  112. vod_list.push(vodShort)
  113. }
  114. }
  115. return vod_list
  116. }
  117. async parseVodDetailFromDoc($) {
  118. let vodDetail = new VodDetail()
  119. let imgElement = $("[class=\"detail-pic fn-left\"]").find("img")[0]
  120. vodDetail.vod_pic = imgElement.attribs.src
  121. vodDetail.vod_name = imgElement.attribs.alt
  122. let vodInfoElement = $("[class=\"info fn-clear\"]")
  123. for (const vodDlElement of $(vodInfoElement).find("dl")) {
  124. let text = $(vodDlElement).text()
  125. if (text.indexOf("主演") > -1) {
  126. vodDetail.vod_actor = text.replaceAll("主演:", "").replaceAll("\n", "")
  127. }
  128. if (text.indexOf("状态") > -1) {
  129. vodDetail.vod_remarks = text.replaceAll("状态:", "").replaceAll("\n", "")
  130. }
  131. if (text.indexOf("类型") > -1) {
  132. vodDetail.type_name = text.replaceAll("类型:", "").replaceAll("\n", "")
  133. }
  134. if (text.indexOf("地区") > -1) {
  135. vodDetail.vod_area = text.replaceAll("地区:", "").replaceAll("\n", "")
  136. }
  137. if (text.indexOf("导演") > -1) {
  138. vodDetail.vod_director = text.replaceAll("导演:", "").replaceAll("\n", "")
  139. }
  140. if (text.indexOf("年份") > -1) {
  141. vodDetail.vod_year = text.replaceAll("年份:", "").replaceAll("\n", "")
  142. }
  143. if (text.indexOf("剧情") > -1) {
  144. vodDetail.vod_content = text.replaceAll("剧情:", "").replaceAll("\n", "")
  145. }
  146. }
  147. let playList = {}
  148. let html = $.html()
  149. let playListElements = $("[class=\"play-list\"]")
  150. let index = 1
  151. for (const playListElement of playListElements) {
  152. let playName = `播放连接-${index}`
  153. let vodItems = []
  154. for (const playUrlElement of $(playListElement).find("a")) {
  155. let playUrlName = playUrlElement.attribs.title
  156. let playUrl = playUrlElement.attribs.href
  157. vodItems.push(playUrlName + "$" + playUrl)
  158. }
  159. playList[playName] = vodItems.join("#")
  160. index = index + 1
  161. }
  162. index = 1
  163. let ciliListElements = $("[class=\"con4\"]")
  164. for (const ciliListElement of ciliListElements) {
  165. let playName = `磁力链接-${index}`
  166. let vodItems = []
  167. let playUrlName = playName
  168. let playUrl = $($(ciliListElement).find("div")).find("a")[0].attribs.href
  169. if (playUrl !== "javascript:void(0);") {
  170. vodItems.push(playUrlName + "$" + playUrl)
  171. playList[playName] = vodItems.join("#")
  172. index = index + 1
  173. }
  174. }
  175. vodDetail.vod_play_url = _.values(playList).join('$$$');
  176. vodDetail.vod_play_from = _.keys(playList).join('$$$');
  177. return vodDetail
  178. }
  179. async setHomeVod() {
  180. let $ = await this.getHtml()
  181. this.homeVodList = await this.parseVodShortListFromDoc($)
  182. }
  183. async setDetail(id) {
  184. let $ = await this.getHtml(this.siteUrl + id)
  185. this.vodDetail = await this.parseVodDetailFromDoc($)
  186. }
  187. getExtend(extend) {
  188. if (extend["class"] !== undefined) {
  189. if (extend["class"] !== "全部") {
  190. return extend["class"]
  191. }
  192. }
  193. return undefined
  194. }
  195. async setCategory(tid, pg, filter, extend) {
  196. let classes = this.getExtend(extend) ?? tid
  197. let url
  198. if (classes === tid) {
  199. url = this.siteUrl + classes
  200. } else {
  201. if (parseInt(pg) === 1) {
  202. url = this.siteUrl + classes
  203. } else {
  204. url = this.siteUrl + classes + `index${pg}.html`
  205. }
  206. }
  207. let $ = await this.getHtml(url)
  208. this.vodList = await this.parseVodShortListFromDoc($)
  209. }
  210. async setPlay(flag, id, flags) {
  211. if (flag.indexOf("磁力") > -1) {
  212. this.playUrl = id
  213. } else {
  214. let idSplitList = id.split("-")
  215. let flag_id = parseInt(idSplitList[1])
  216. let episode = parseInt(idSplitList[2].split(".")[0])
  217. let $ = await this.getHtml(this.siteUrl + id)
  218. let playJsUrl = Utils.getStrByRegex(/<script type="text\/javascript" src="(.*?)">/, $.html())
  219. let playJsContent = await this.fetch(this.siteUrl + playJsUrl, null, this.getHeader())
  220. let playUrlListStr = Utils.getStrByRegex(/var VideoListJson=(.*?),urlinfo=/, playJsContent)
  221. let playDic = eval(playUrlListStr)
  222. this.playUrl = playDic[flag_id][1][episode].split("$")[1]
  223. if (this.playUrl.indexOf("m3u8") === -1) {
  224. let html = await this.fetch(this.playUrl, null, this.getHeader())
  225. this.playUrl = Utils.getStrByRegex(/url: '(.*?)'/, html)
  226. }
  227. }
  228. }
  229. GBKEncode(str) {
  230. var arr_index = 0x8140; //33088;
  231. str += '';
  232. var gbk = [];
  233. var wh = '?'.charCodeAt(0); //gbk中没有的字符的替换符
  234. for (var i = 0; i < str.length; i++) {
  235. var charcode = str.charCodeAt(i);
  236. if (charcode < 0x80) gbk.push(charcode);
  237. else {
  238. var gcode = gbk_us.indexOf(charcode);
  239. if (~gcode) {
  240. gcode += arr_index;
  241. gbk.push(0xFF & (gcode >> 8), 0xFF & gcode);
  242. } else {
  243. gbk.push(wh);
  244. }
  245. }
  246. }
  247. return gbk;
  248. }
  249. encode(str) {
  250. let encodeStr = ""
  251. for (const ch of str) {
  252. let bitArr = this.GBKEncode(ch);
  253. for (let i = 0; i < bitArr.length; i++) {
  254. bitArr[i] = '%' + ('0' + bitArr[i].toString(16)).substr(-2).toUpperCase();
  255. }
  256. encodeStr = encodeStr + bitArr.join('');
  257. }
  258. return encodeStr
  259. }
  260. async setSearch(wd, quick) {
  261. let params = {"searchword": this.encode(wd)}
  262. let buffer = await this.post(this.siteUrl + "/search.asp", params, this.getHeader(), "form", 1)
  263. let $ = load(Utils.decode(buffer, "gb2312"))
  264. this.vodList = await this.parseVodShortListFromDocBySearch($)
  265. }
  266. }
  267. let spider = new LoveMovieSpider()
  268. async function init(cfg) {
  269. await spider.init(cfg)
  270. }
  271. async function home(filter) {
  272. return await spider.home(filter)
  273. }
  274. async function homeVod() {
  275. return await spider.homeVod()
  276. }
  277. async function category(tid, pg, filter, extend) {
  278. return await spider.category(tid, pg, filter, extend)
  279. }
  280. async function detail(id) {
  281. return await spider.detail(id)
  282. }
  283. async function play(flag, id, flags) {
  284. return await spider.play(flag, id, flags)
  285. }
  286. async function search(wd, quick) {
  287. return await spider.search(wd, quick)
  288. }
  289. export function __jsEvalReturn() {
  290. return {
  291. init: init, home: home, homeVod: homeVod, category: category, detail: detail, play: play, search: search,
  292. };
  293. }
  294. export {spider, LoveMovieSpider}