vodSpider.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * @File : vodSpider.js
  3. * @Author : jade
  4. * @Date : 2024/2/6 16:53
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc :
  8. */
  9. import {_, load} from '../lib/cat.js';
  10. import {VodDetail, VodShort} from "../lib/vod.js"
  11. import * as Utils from "../lib/utils.js";
  12. import {Spider} from "./spider.js";
  13. class VodSpider extends Spider {
  14. constructor() {
  15. super();
  16. this.siteUrl = "http://cj.ffzyapi.com"
  17. this.remove18 = false
  18. this.type_id_18 = 34
  19. }
  20. async spiderInit(inReq) {
  21. if (inReq !== null) {
  22. this.detailProxy = await js2Proxy(inReq, "detail", this.getHeader());
  23. } else {
  24. this.detailProxy = await js2Proxy(true, this.siteType, this.siteKey, 'detail/', this.getHeader());
  25. }
  26. }
  27. async init(cfg) {
  28. await super.init(cfg);
  29. await this.spiderInit(null)
  30. }
  31. async parseVodShortListFromJson(obj, isSearch = false) {
  32. let vod_list = []
  33. let vodShort;
  34. for (const vod_data of obj["list"]) {
  35. if (!isSearch) {
  36. vodShort = this.parseVodDetail(vod_data)
  37. } else {
  38. vodShort = new VodShort();
  39. vodShort.vod_pic = this.detailProxy + Utils.base64Encode(vod_data["vod_id"])
  40. vodShort.vod_id = vod_data["vod_id"]
  41. vodShort.vod_name = vod_data["vod_name"]
  42. vodShort.vod_remarks = vod_data["vod_remarks"]
  43. }
  44. if (this.remove18 && vod_data["type_id"] !== this.type_id_18) {
  45. vod_list.push(vodShort)
  46. }
  47. if (!this.remove18 && vod_data["type_id"] === this.type_id_18) {
  48. vod_list.push(vodShort)
  49. }
  50. }
  51. return vod_list
  52. }
  53. parseVodDetail(vod_data) {
  54. let vodDetail = new VodDetail()
  55. vodDetail.vod_id = vod_data["vod_id"]
  56. vodDetail.vod_name = vod_data["vod_name"]
  57. vodDetail.vod_pic = vod_data["vod_pic"]
  58. vodDetail.vod_remarks = vod_data["vod_remarks"]
  59. vodDetail.vod_area = vod_data["vod_area"]
  60. vodDetail.vod_year = vod_data["vod_year"]
  61. vodDetail.vod_actor = vod_data["vod_actor"]
  62. vodDetail.vod_director = vod_data["vod_director"]
  63. let $ = load(vod_data['vod_content'])
  64. vodDetail.vod_content = $.text()
  65. if (vod_data["vod_down_url"] !== undefined) {
  66. if (vod_data["vod_down_url"].length > 0) {
  67. vodDetail.vod_play_from = "直链播放$$$"
  68. vodDetail.vod_play_url = vod_data["vod_down_url"] + "$$$"
  69. }
  70. }
  71. vodDetail.vod_play_from = vodDetail.vod_play_from + vod_data["vod_play_from"]
  72. vodDetail.vod_play_url = vodDetail.vod_play_url + vod_data["vod_play_url"]
  73. vodDetail.type_name = vod_data["type_name"]
  74. return vodDetail
  75. }
  76. async parseVodDetailfromJson(obj) {
  77. let vodDetail;
  78. let vod_data_list = obj["list"]
  79. if (vod_data_list.length > 0) {
  80. let vod_data = vod_data_list[0]
  81. vodDetail = this.parseVodDetail(vod_data)
  82. }
  83. return vodDetail
  84. }
  85. async setClasses() {
  86. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod/from", {"ac": "list"}, this.getHeader())
  87. let content_json = JSON.parse(content)
  88. for (const class_dic of content_json["class"]) {
  89. if (class_dic["type_pid"] !== 0) {
  90. this.classes.push(this.getTypeDic(class_dic["type_name"], class_dic["type_id"]))
  91. }
  92. }
  93. }
  94. async setFilterObj() {
  95. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod/from", {"ac": "list"}, this.getHeader())
  96. let content_json = JSON.parse(content)
  97. for (const root_class_dic of this.classes) {
  98. let type_id = root_class_dic["type_id"].toString()
  99. if (type_id !== "最近更新") {
  100. let extend_dic = {"key": "1", "name": "分类", "value": [{"n": "全部", "v": type_id}]}
  101. for (const class_dic of content_json["class"]) {
  102. let type_name = class_dic["type_name"]
  103. if (type_name === this.type_name_18) {
  104. this.type_id_18 = class_dic["type_id"].toString()
  105. }
  106. if (this.remove18) {
  107. if (class_dic["type_pid"] === root_class_dic["type_id"] && type_name !== this.type_name_18) {
  108. extend_dic["value"].push({"n": type_name, "v": class_dic["type_id"].toString()})
  109. }
  110. } else {
  111. if (class_dic["type_pid"] === root_class_dic["type_id"] && type_name === this.type_name_18) {
  112. extend_dic["value"].push({"n": type_name, "v": class_dic["type_id"].toString()})
  113. }
  114. }
  115. }
  116. if (!this.remove18) {
  117. this.classes = [this.getTypeDic("最近更新", "最近更新"), this.getTypeDic(this.type_name_18, this.type_id_18)]
  118. } else {
  119. this.filterObj[type_id] = [extend_dic]
  120. }
  121. }
  122. }
  123. }
  124. async setHomeVod() {
  125. let content = await this.fetch(this.siteUrl + "/index.php/ajax/data", {
  126. "mid": "1"
  127. }, this.getHeader())
  128. this.homeVodList = await this.parseVodShortListFromJson(JSON.parse(content))
  129. }
  130. async setDetail(id) {
  131. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod", {
  132. "ac": "detail", "ids": id
  133. }, this.getHeader())
  134. this.vodDetail = await this.parseVodDetailfromJson(JSON.parse(content))
  135. }
  136. async setCategory(tid, pg, filter, extend) {
  137. tid = extend["1"] ?? tid
  138. let url = this.siteUrl + `/index.php/ajax/data?mid=1&tid=${tid}&page=${pg}&limit=20`
  139. await this.jadeLog.debug(`分类URL:${url}`)
  140. let content = await this.fetch(url, null, this.getHeader())
  141. await this.jadeLog.debug(`分类内容为:${content}`)
  142. this.vodList = await this.parseVodShortListFromJson(JSON.parse(content))
  143. }
  144. async setSearch(wd, quick) {
  145. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod/", {"wd": wd}, this.getHeader())
  146. this.vodList = await this.parseVodShortListFromJson(JSON.parse(content), true)
  147. }
  148. async proxy(segments, headers) {
  149. await this.jadeLog.debug(`正在设置反向代理 segments = ${segments.join(",")},headers = ${JSON.stringify(headers)}`)
  150. let what = segments[0];
  151. let url = Utils.base64Decode(segments[1]);
  152. await this.jadeLog.debug(`反向代理参数为:${url}`)
  153. if (what === 'detail') {
  154. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod", {
  155. "ac": "detail", "ids": url
  156. }, this.getHeader())
  157. let vod_detail = await this.parseVodDetailfromJson(JSON.parse(content))
  158. let pic_content = await this.fetch(vod_detail.vod_pic, null, this.getHeader(), false, false, 2)
  159. if (!_.isEmpty(pic_content)) {
  160. return JSON.stringify({
  161. code: 200, buffer: 2, content: pic_content, headers: {},
  162. });
  163. } else {
  164. return JSON.stringify({
  165. code: 500, buffer: 2, content: "", headers: {},
  166. });
  167. }
  168. }
  169. }
  170. }
  171. export {VodSpider}