vodSpider.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. vodDetail.vod_play_from = vod_data["vod_play_from"]
  66. vodDetail.vod_play_url = vod_data["vod_play_url"]
  67. vodDetail.type_name = vod_data["type_name"]
  68. return vodDetail
  69. }
  70. async parseVodDetailfromJson(obj) {
  71. let vodDetail;
  72. let vod_data_list = obj["list"]
  73. if (vod_data_list.length > 0) {
  74. let vod_data = vod_data_list[0]
  75. vodDetail = this.parseVodDetail(vod_data)
  76. }
  77. return vodDetail
  78. }
  79. async setClasses() {
  80. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod/from", {"ac": "list"}, this.getHeader())
  81. let content_json = JSON.parse(content)
  82. for (const class_dic of content_json["class"]) {
  83. if (class_dic["type_pid"] !== 0) {
  84. this.classes.push(this.getTypeDic(class_dic["type_name"], class_dic["type_id"]))
  85. }
  86. }
  87. }
  88. async setFilterObj() {
  89. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod/from", {"ac": "list"}, this.getHeader())
  90. let content_json = JSON.parse(content)
  91. for (const root_class_dic of this.classes) {
  92. let type_id = root_class_dic["type_id"].toString()
  93. if (type_id !== "最近更新") {
  94. let extend_dic = {"key": "1", "name": "分类", "value": [{"n": "全部", "v": type_id}]}
  95. for (const class_dic of content_json["class"]) {
  96. let type_name = class_dic["type_name"]
  97. if (type_name === this.type_name_18) {
  98. this.type_id_18 = class_dic["type_id"].toString()
  99. }
  100. if (this.remove18) {
  101. if (class_dic["type_pid"] === root_class_dic["type_id"] && type_name !== this.type_name_18) {
  102. extend_dic["value"].push({"n": type_name, "v": class_dic["type_id"].toString()})
  103. }
  104. } else {
  105. if (class_dic["type_pid"] === root_class_dic["type_id"] && type_name === this.type_name_18) {
  106. extend_dic["value"].push({"n": type_name, "v": class_dic["type_id"].toString()})
  107. }
  108. }
  109. }
  110. if (!this.remove18) {
  111. this.classes = [this.getTypeDic("最近更新", "最近更新"), this.getTypeDic(this.type_name_18, this.type_id_18)]
  112. } else {
  113. this.filterObj[type_id] = [extend_dic]
  114. }
  115. }
  116. }
  117. }
  118. async setHomeVod() {
  119. let content = await this.fetch(this.siteUrl + "/index.php/ajax/data", {
  120. "mid": "1"
  121. }, this.getHeader())
  122. this.homeVodList = await this.parseVodShortListFromJson(JSON.parse(content))
  123. }
  124. async setDetail(id) {
  125. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod", {
  126. "ac": "detail", "ids": id
  127. }, this.getHeader())
  128. this.vodDetail = await this.parseVodDetailfromJson(JSON.parse(content))
  129. }
  130. async setCategory(tid, pg, filter, extend) {
  131. tid = extend["1"] ?? tid
  132. let url = this.siteUrl + `/index.php/ajax/data?mid=1&tid=${tid}&page=${pg}&limit=20`
  133. await this.jadeLog.debug(`分类URL:${url}`)
  134. let content = await this.fetch(url, null, this.getHeader())
  135. await this.jadeLog.debug(`分类内容为:${content}`)
  136. this.vodList = await this.parseVodShortListFromJson(JSON.parse(content))
  137. }
  138. async setSearch(wd, quick) {
  139. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod/", {"wd": wd}, this.getHeader())
  140. this.vodList = await this.parseVodShortListFromJson(JSON.parse(content), true)
  141. }
  142. async proxy(segments, headers) {
  143. await this.jadeLog.debug(`正在设置反向代理 segments = ${segments.join(",")},headers = ${JSON.stringify(headers)}`)
  144. let what = segments[0];
  145. let url = Utils.base64Decode(segments[1]);
  146. await this.jadeLog.debug(`反向代理参数为:${url}`)
  147. if (what === 'detail') {
  148. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod", {
  149. "ac": "detail", "ids": url
  150. }, this.getHeader())
  151. let vod_detail = await this.parseVodDetailfromJson(JSON.parse(content))
  152. let pic_content = await this.fetch(vod_detail.vod_pic, null, this.getHeader(), false, false, 2)
  153. if (!_.isEmpty(pic_content)) {
  154. return JSON.stringify({
  155. code: 200, buffer: 2, content: pic_content, headers: {},
  156. });
  157. } else {
  158. return JSON.stringify({
  159. code: 500, buffer: 2, content: "", headers: {},
  160. });
  161. }
  162. }
  163. }
  164. }
  165. export {VodSpider}