alipansou.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * @File : alipansou.js
  3. * @Author : jade
  4. * @Date : 2024/1/18 13:20
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc : 猫狸盘搜
  8. */
  9. import {_, load} from "../lib/cat.js";
  10. import {Spider} from "./spider.js";
  11. import { detailContent,initCloud,playContent,getHeaders } from "../lib/cloud.js";
  12. import {VodDetail, VodShort} from "../lib/vod.js";
  13. import * as Utils from "../lib/utils.js";
  14. class GitCafeSpider extends Spider {
  15. constructor() {
  16. super();
  17. this.siteUrl = "https://www.alipansou.com"
  18. }
  19. getHeaders(id) {
  20. let headers = this.getHeader()
  21. headers["Referer"] = this.siteUrl + id
  22. headers["_bid"] = "6d14a5dd6c07980d9dc089a693805ad8"
  23. headers["Cookie"] = "_egg=70463dec0ec843b682ce18c36ec9ce91e"
  24. return headers
  25. }
  26. getName() {
  27. return "😸┃阿里猫狸┃😸"
  28. }
  29. getAppName() {
  30. return "阿里猫狸"
  31. }
  32. getJSName() {
  33. return "alipansou"
  34. }
  35. getType() {
  36. return 3
  37. }
  38. getHeader() {
  39. return {
  40. "User-Agent":Utils.CHROME,
  41. "Connection": "keep-alive"
  42. }
  43. }
  44. async getContentHtml() {
  45. let html = await this.fetch(this.siteUrl, null, this.getHeader())
  46. if (!_.isEmpty(html)) {
  47. return load(html)
  48. }
  49. }
  50. async spiderInit() {
  51. this.content_html = await this.getContentHtml()
  52. }
  53. async init(cfg) {
  54. await this.spiderInit()
  55. await super.init(cfg);
  56. await initCloud(this.cfgObj);
  57. }
  58. async parseClassFromDoc($) {
  59. let tap_elemets = $($("[id=\"app\"]")[0]).find("van-tab")
  60. let index = 0
  61. for (const tap_element of tap_elemets) {
  62. let type_name = tap_element.attribs["title"]
  63. if (type_name.indexOf("热搜") === -1 && type_name !== "游戏" && type_name !== "小说") {
  64. this.classes.push({"type_name": type_name, "type_id": index})
  65. }
  66. index = index + 1
  67. }
  68. }
  69. async parseVodShortListFromDoc(doc) {
  70. let vod_list = []
  71. let elements = this.content_html(doc).find("a")
  72. for (const element of elements) {
  73. let vodShort = new VodShort()
  74. vodShort.vod_id = element.attribs["href"]
  75. vodShort.vod_name = this.content_html(element).text().split(".").slice(-1)[0]
  76. vod_list.push(vodShort)
  77. }
  78. return vod_list
  79. }
  80. async getAliUrl(id) {
  81. let url = this.siteUrl + id.replace("/s/", "/cv/")
  82. let headers = this.getHeaders(id)
  83. let content = await req(url,{postType:"get",headers:headers,redirect:2})
  84. await this.jadeLog.debug(`回复内容为:${JSON.stringify(content)}`)
  85. // let url = await this.fetch(this.siteUrl + id.replace("/s/", "/cv/"), null, headers, true)
  86. return content.headers.location
  87. }
  88. async parseVodDetailfromJson(obj) {
  89. let vodDetail = new VodDetail();
  90. vodDetail.vod_name = obj["name"]
  91. vodDetail.vod_remarks = obj["remarks"]
  92. let ali_url = await this.getAliUrl(obj["id"])
  93. await this.jadeLog.debug(`阿里分享链接为:${ali_url}`)
  94. if (!_.isEmpty(ali_url)) {
  95. let playVod = await detailContent([ali_url],vodDetail.type_name)
  96. vodDetail.vod_play_from = _.keys(playVod).join('$$$');
  97. vodDetail.vod_play_url = _.values(playVod).join('$$$');
  98. }
  99. return vodDetail
  100. }
  101. async parseVodShortListFromDocBySearch($) {
  102. let elements = $($($("[id=\"app\"]")[0]).find("van-row")).find("a")
  103. let vod_list = []
  104. for (const element of elements) {
  105. let id = element.attribs["href"]
  106. let matches = id.match(/(\/s\/[^"])/);
  107. if (!_.isEmpty(matches) && id.indexOf("https") === -1) {
  108. let text = $(element).text().replaceAll("\n", "").replaceAll(" ", "")
  109. if (text.indexOf("时间") > -1 && text.indexOf("文件夹") > -1) {
  110. let textList = text.split("时间")
  111. let vodShort = new VodShort()
  112. vodShort.vod_name = textList[0]
  113. vodShort.vod_remarks = textList[1].split("格式")[0].replaceAll(":", "").replaceAll(" ", "").replaceAll("", "").replaceAll(" ", "")
  114. vodShort.vod_id = JSON.stringify({
  115. "name": vodShort.vod_name, "remarks": vodShort.vod_remarks, "id": id
  116. })
  117. vod_list.push(vodShort)
  118. }
  119. }
  120. }
  121. return vod_list
  122. }
  123. async setClasses() {
  124. await this.parseClassFromDoc(this.content_html)
  125. }
  126. async setHomeVod() {
  127. let tap_elemets = this.content_html(this.content_html("[id=\"app\"]")[0]).find("van-tab")
  128. this.homeVodList = await this.parseVodShortListFromDoc(tap_elemets[0])
  129. }
  130. async setDetail(id) {
  131. if (id.indexOf("search") > -1) {
  132. let url = this.siteUrl + "/search"
  133. let params = {"k":decodeURIComponent(id.split("search?k=").slice(-1)[0]) }
  134. let html = await this.fetch(url, params, this.getHeader())
  135. if (!_.isEmpty(html)) {
  136. let $ = load(html)
  137. let vod_list = await this.parseVodShortListFromDocBySearch($)
  138. if (vod_list.length > 0) {
  139. id = vod_list[0]["vod_id"]
  140. } else {
  141. id = ""
  142. }
  143. }
  144. }
  145. if (!_.isEmpty(id)) {
  146. let json_content = JSON.parse(id)
  147. this.vodDetail = await this.parseVodDetailfromJson(json_content)
  148. }
  149. }
  150. async setCategory(tid, pg, filter, extend) {
  151. let tap_elemets = this.content_html(this.content_html("[id=\"app\"]")[0]).find("van-tab")
  152. this.vodList = await this.parseVodShortListFromDoc(tap_elemets[parseInt(tid)])
  153. }
  154. async setSearch(wd, quick) {
  155. let url = this.siteUrl + "/search"
  156. let params = {"k": wd}
  157. let html = await this.fetch(url, params, this.getHeader())
  158. if (!_.isEmpty(html)) {
  159. let $ = load(html)
  160. this.vodList = await this.parseVodShortListFromDocBySearch($)
  161. }
  162. }
  163. async setPlay(flag, id, flags) {
  164. this.playUrl = await playContent(flag, id, flags);
  165. this.result.setHeader(getHeaders(flag))
  166. }
  167. }
  168. let spider = new GitCafeSpider()
  169. async function init(cfg) {
  170. await spider.init(cfg)
  171. }
  172. async function home(filter) {
  173. return await spider.home(filter)
  174. }
  175. async function homeVod() {
  176. return await spider.homeVod()
  177. }
  178. async function category(tid, pg, filter, extend) {
  179. return await spider.category(tid, pg, filter, extend)
  180. }
  181. async function detail(id) {
  182. return await spider.detail(id)
  183. }
  184. async function play(flag, id, flags) {
  185. return await spider.play(flag, id, flags)
  186. }
  187. async function search(wd, quick) {
  188. return await spider.search(wd, quick)
  189. }
  190. export function __jsEvalReturn() {
  191. return {
  192. init: init, home: home, homeVod: homeVod, category: category, detail: detail, play: play, search: search,
  193. };
  194. }
  195. export {spider}