haoxi.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * @File : haoxi.js
  3. * @Author : jade
  4. * @Date : 2024/2/7 14:24
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc : 好戏追剧 已失效
  8. */
  9. import {VodDetail, VodShort} from "../lib/vod.js"
  10. import * as Utils from "../lib/utils.js";
  11. import {Spider} from "./spider.js";
  12. class HaoXiSpider extends Spider {
  13. constructor() {
  14. super();
  15. this.siteUrl = "https://haoxi.vip"
  16. }
  17. getAppName() {
  18. return `好戏追剧`
  19. }
  20. getName() {
  21. return `🌿┃好戏追剧┃🌿`
  22. }
  23. getJSName() {
  24. return "haoxi"
  25. }
  26. getType() {
  27. return 3
  28. }
  29. parseVodShortFromElement($, element) {
  30. let vodShort = new VodShort();
  31. vodShort.vod_id = $(element).find("a")[0].attribs.href
  32. vodShort.vod_name = $(element).find("a")[0].attribs.title
  33. if (vodShort.vod_name === undefined) {
  34. vodShort.vod_name = $($($(element).find("[class=\"thumb-txt cor4 hide\"]")).find("a")).html()
  35. }
  36. vodShort.vod_pic = $(element).find("img")[0].attribs["data-src"]
  37. vodShort.vod_remarks = $($(element).find("[class=\"public-list-prb hide ft2\"]")).html()
  38. return vodShort
  39. }
  40. async parseVodShortListFromDoc($) {
  41. let vod_list = []
  42. let vodElements = $("[class=\"flex bottom4\"]").find("[class=\"public-list-box public-pic-a [swiper]\"]")
  43. for (const vodElement of vodElements) {
  44. let vodShort = this.parseVodShortFromElement($, vodElement)
  45. vod_list.push(vodShort)
  46. }
  47. return vod_list
  48. }
  49. async parseVodShortListFromDocByCategory($) {
  50. let vod_list = []
  51. let vodElements = $("[class=\"public-list-box public-pic-b [swiper]\"]")
  52. for (const vodElement of vodElements) {
  53. let vodShort = this.parseVodShortFromElement($, vodElement)
  54. vod_list.push(vodShort)
  55. }
  56. return vod_list
  57. }
  58. async parseVodShortListFromDocBySearch($) {
  59. let vod_list = []
  60. let vodElements = $("[class=\"public-list-box search-box flex rel\"]")
  61. for (const vodElement of vodElements) {
  62. let vodShort = this.parseVodShortFromElement($, vodElement)
  63. vod_list.push(vodShort)
  64. }
  65. return vod_list
  66. }
  67. async parseVodDetailFromDoc($) {
  68. let vodDetailElement = $("[class=\"vod-detail style-detail rel cor1 hader0\"]")
  69. let vodDetail = new VodDetail();
  70. vodDetail.vod_pic = $(vodDetailElement).find("img")[0].attribs.src
  71. vodDetail.vod_name = $($(vodDetailElement).find("[class=\"slide-info-title hide\"]")).html()
  72. let elements = $(vodDetailElement).find("[class=\"slide-info hide\"]")
  73. vodDetail.vod_year = $($($(elements[0]).find("[class=\"slide-info-remarks\"]")[0]).find("a")[0]).html()
  74. vodDetail.vod_area = $($($(elements[0]).find("[class=\"slide-info-remarks\"]")[1]).find("a")[0]).html()
  75. vodDetail.type_name = $($($(elements[0]).find("[class=\"slide-info-remarks\"]")[2]).find("a")[0]).html()
  76. vodDetail.vod_remarks = $(elements[1]).text().replaceAll("备注 :", "")
  77. vodDetail.vod_director = $(elements[2]).text().replaceAll("导演 :", "")
  78. vodDetail.vod_actor = $(elements[3]).text().replaceAll("演员 :", "")
  79. vodDetail.vod_content = $($("[class=\"text cor3\"]")).text()
  80. let playElements = $("[class=\"box-width cor5\"]")
  81. let playFormatElements = playElements.find("[class=\"swiper-slide\"]")
  82. let playUrlElements = playElements.find("[class=\"anthology-list-box none\"]")
  83. let vod_play_from_list = []
  84. let vod_play_list = []
  85. for (let i = 0; i < playFormatElements.length; i++) {
  86. let playFormatElement = playFormatElements[i]
  87. let format_name = playFormatElement.children[1].data
  88. format_name = format_name.replaceAll(" ", "")
  89. vod_play_from_list.push(format_name)
  90. let vodItems = []
  91. if (format_name === "http下载") {
  92. for (const playUrlElement of $(playUrlElements[i]).find("a")) {
  93. let episodeName = $(playUrlElement).text()
  94. let episodeUrl = playUrlElement.attribs.href
  95. if (episodeName !== "复制地址") {
  96. vodItems.push(episodeName + "$" + episodeUrl)
  97. }
  98. }
  99. } else {
  100. for (const playUrlElement of $(playUrlElements[i]).find("a")) {
  101. let episodeName = $(playUrlElement).text()
  102. let episodeUrl = playUrlElement.attribs.href
  103. vodItems.push(episodeName + "$" + episodeUrl)
  104. }
  105. }
  106. vod_play_list.push(vodItems.join("#"))
  107. }
  108. vodDetail.vod_play_from = vod_play_from_list.join("$$$")
  109. vodDetail.vod_play_url = vod_play_list.join("$$$")
  110. return vodDetail
  111. }
  112. async setClasses() {
  113. let $ = await this.getHtml()
  114. let navElements = $("[class=\"head flex between no-null header_nav0\"]").find("li")
  115. for (const navElement of navElements) {
  116. let type_name = $($(navElement).find("a")).text()
  117. let type_id = Utils.getStrByRegex(/\/vodtype\/(.*?)\//, $(navElement).find("a")[0].attribs.href)
  118. if (Utils.isNumeric(type_id)) {
  119. this.classes.push(this.getTypeDic(type_name, type_id))
  120. }
  121. }
  122. }
  123. async getFilter($) {
  124. let elements = $("[class=\"nav-swiper rel\"]")
  125. let extend_list = []
  126. for (let i = 0; i < elements.length; i++) {
  127. let extend_dic = {"key": (i + 1).toString(), "name": "", "value": []}
  128. let name = $($($(elements[i]).find("[class=\"filter-text bj cor5\"]")[0]).find("span")).html()
  129. if (name !== "已选" && name !== "频道") {
  130. extend_dic["name"] = name
  131. for (const ele of $(elements[i]).find("li")) {
  132. extend_dic["value"].push({"n": $(ele).text(), "v": $(ele).text()})
  133. }
  134. extend_list.push(extend_dic)
  135. }
  136. }
  137. let sortElments = $("[class=\"site-tabs b-b br\"]")
  138. let extend_dic = {"key": (elements.length + 1).toString(), "name": "排序", "value": []}
  139. extend_dic["value"].push({"n": "全部", "v": "/"})
  140. for (const ele of $(sortElments).find("a")) {
  141. let type_id_list = ele.attribs.href.split("-")
  142. extend_dic["value"].push({"n": $(ele).text(), "v": type_id_list[2]})
  143. }
  144. extend_list.push(extend_dic)
  145. return extend_list
  146. }
  147. async setFilterObj() {
  148. for (const class_dic of this.classes) {
  149. let type_id = class_dic["type_id"]
  150. if (Utils.isNumeric(type_id)) {
  151. let url = this.siteUrl + `/vodshow/${type_id}-----------`
  152. let $ = await this.getHtml(url)
  153. this.filterObj[type_id] = await this.getFilter($)
  154. }
  155. }
  156. }
  157. async setHomeVod() {
  158. let $ = await this.getHtml()
  159. this.homeVodList = await this.parseVodShortListFromDoc($)
  160. }
  161. get_extend_sort_dic(tid) {
  162. return {
  163. "3": 3, "4": 1, "5": 11, "6": 4, "9": 5, "10": 2,
  164. }
  165. }
  166. async setCategory(tid, pg, filter, extend) {
  167. // "1-大陆-hits-Netflix-英语-A----正片--2023/version/4K/"
  168. let urlParams = [tid.toString(), "", "", "", "", "", "", "", pg.toString(), "", "", ""]
  169. let extend_dic = this.get_extend_sort_dic(parseInt(tid))
  170. for (const key of Object.keys(extend_dic)) {
  171. if (extend[key] === "0") {
  172. urlParams[extend_dic[key]] = ""
  173. } else {
  174. if (extend[key] !== "全部") {
  175. urlParams[extend_dic[key]] = extend[key]
  176. }
  177. }
  178. }
  179. let reqUrl = this.siteUrl + '/vodshow/' + urlParams.join("-");
  180. if (extend[7] !== undefined && extend[7] !== "全部") {
  181. reqUrl = reqUrl + `/version/${extend[7]}/`
  182. }
  183. await this.jadeLog.debug(`分类URL:${reqUrl}`)
  184. let $ = await this.getHtml(reqUrl)
  185. this.vodList = await this.parseVodShortListFromDocByCategory($)
  186. }
  187. async setDetail(id) {
  188. let $ = await this.getHtml(this.siteUrl + id)
  189. this.vodDetail = await this.parseVodDetailFromDoc($)
  190. }
  191. async setSearch(wd, quick) {
  192. let $ = await this.getHtml(this.siteUrl + `/vodsearch/-------------/?wd=${wd}`)
  193. this.vodList = await this.parseVodShortListFromDocBySearch($)
  194. }
  195. async setPlay(flag, id, flags) {
  196. if (flag !== "http下载") {
  197. let $ = await this.getHtml(this.siteUrl + id)
  198. let playConfig = JSON.parse(Utils.getStrByRegex(/var player_aaaa=(.*?)<\/script>/, $.html()))
  199. this.playUrl = playConfig['url']
  200. } else {
  201. this.playUrl = id
  202. }
  203. }
  204. }
  205. let spider = new HaoXiSpider()
  206. async function init(cfg) {
  207. await spider.init(cfg)
  208. }
  209. async function home(filter) {
  210. return await spider.home(filter)
  211. }
  212. async function homeVod() {
  213. return await spider.homeVod()
  214. }
  215. async function category(tid, pg, filter, extend) {
  216. return await spider.category(tid, pg, filter, extend)
  217. }
  218. async function detail(id) {
  219. return await spider.detail(id)
  220. }
  221. async function play(flag, id, flags) {
  222. return await spider.play(flag, id, flags)
  223. }
  224. async function search(wd, quick) {
  225. return await spider.search(wd, quick)
  226. }
  227. async function proxy(segments, headers) {
  228. return await spider.proxy(segments, headers)
  229. }
  230. export function __jsEvalReturn() {
  231. return {
  232. init: init,
  233. home: home,
  234. homeVod: homeVod,
  235. category: category,
  236. detail: detail,
  237. play: play,
  238. search: search,
  239. proxy: proxy
  240. };
  241. }
  242. export {spider}