jiafeimao.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * @File : jiafeimao.js
  3. * @Author : jade
  4. * @Date : 2024/1/24 9:15
  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 JiaFeiMaoSpider extends Spider {
  14. constructor() {
  15. super();
  16. this.siteUrl = "https://jfmys.app"
  17. }
  18. getAppName() {
  19. return "加菲猫"
  20. }
  21. getName() {
  22. return `🐈┃加菲猫┃🐈`
  23. }
  24. getJSName() {
  25. return "jiafeimao"
  26. }
  27. getType() {
  28. return 3
  29. }
  30. getPic(url){
  31. if (url.indexOf("http:") > -1 || url.indexOf("https:") > -1){
  32. return url
  33. }else{
  34. return this.siteUrl + url
  35. }
  36. }
  37. parseVodShortFromElement($, element) {
  38. let vodShort = new VodShort()
  39. vodShort.vod_id = Utils.getStrByRegex(/id\/(.*?)\//,$(element).find("a")[0].attribs.href)
  40. vodShort.vod_name = $(element).find("a")[0].attribs.title
  41. vodShort.vod_pic = this.getPic($(element).find("img")[0].attribs["data-src"])
  42. vodShort.vod_remarks = $($(element).find("[class=\"v-tips\"]")).html()
  43. return vodShort
  44. }
  45. async parseVodShortListFromDoc($) {
  46. let vod_list = []
  47. let vodElements = $(".icon > .container").find("[class=\"imain clearfix\"]").find("li")
  48. for (const vodElement of vodElements) {
  49. let vodShort = this.parseVodShortFromElement($, vodElement)
  50. vod_list.push(vodShort)
  51. }
  52. return vod_list
  53. }
  54. async parseVodShortListFromDocByCategory($) {
  55. let vod_list = []
  56. let vodElements = $("[class=\"tv-list clearfix\"]").find("li")
  57. for (const vodElement of vodElements) {
  58. let vodShort = this.parseVodShortFromElement($, vodElement)
  59. vod_list.push(vodShort)
  60. }
  61. return vod_list
  62. }
  63. async parseVodDetailFromDoc($) {
  64. let vodDetail = new VodDetail()
  65. vodDetail.vod_name = $($("[class=\"iptit\"]").find("h3")).html().split(" ")[0]
  66. vodDetail.vod_content = $($("[class=\"idetail container\"]").find("[class=\"infor_intro\"]")).text()
  67. let vodPlayElements = $("[class=\"fjcon\"]")
  68. let vod_play_from_list = []
  69. let vod_play_list = []
  70. let playFormatElemets = $($(vodPlayElements).find("[class=\"fjtop clearfix\"]")).find("a")
  71. let playUrlElements = $(vodPlayElements).find("[class=\"xjn_ul play-list\"]")
  72. for (let i = 0; i < playFormatElemets.length; i++) {
  73. let playFormatElement = playFormatElemets[i]
  74. vod_play_from_list.push("线路" +( i+1).toString())
  75. let vodItems = []
  76. for (const playUrlElement of $(playUrlElements[i]).find("a")) {
  77. let episodeName = $(playUrlElement).text()
  78. let episodeUrl = playUrlElement.attribs.href
  79. vodItems.push(episodeName + "$" + episodeUrl)
  80. }
  81. vod_play_list.push(vodItems.join("#"))
  82. }
  83. vodDetail.vod_play_from = vod_play_from_list.join("$$$")
  84. vodDetail.vod_play_url = vod_play_list.join("$$$")
  85. return vodDetail
  86. }
  87. parseVodDetail(vod_data) {
  88. let vodDetail = new VodDetail()
  89. vodDetail.vod_name = vod_data["vod_name"]
  90. vodDetail.vod_pic = this.getPic(vod_data["vod_pic"])
  91. vodDetail.vod_remarks = vod_data["vod_remarks"]
  92. vodDetail.vod_area = vod_data["vod_area"]
  93. vodDetail.vod_year = vod_data["vod_year"]
  94. vodDetail.vod_actor = vod_data["vod_actor"]
  95. vodDetail.vod_director = vod_data["vod_director"]
  96. vodDetail.vod_content = vod_data["vod_content"].replaceAll("<p>","").replaceAll("</p>","")
  97. let vod_play_from = []
  98. for (let i = 0; i < vod_data["vod_play_from"].split("$$$").length; i++) {
  99. vod_play_from.push("线路"+(i+1).toString())
  100. }
  101. vodDetail.vod_play_from = vod_play_from.join("$$$")
  102. vodDetail.vod_play_url = vod_data["vod_play_url"]
  103. vodDetail.type_name = vod_data["type_name"]
  104. return vodDetail
  105. }
  106. async parseVodDetailfromJson(obj) {
  107. let vodDetail;
  108. let vod_data_list = obj["list"]
  109. if (vod_data_list.length > 0) {
  110. let vod_data = vod_data_list[0]
  111. vodDetail = this.parseVodDetail(vod_data)
  112. }
  113. return vodDetail
  114. }
  115. async parseVodShortListFromDocBySearch($) {
  116. let vod_list = []
  117. let vodElements = $("[class=\"tv-bd search-list\"]").find("[class=\"item clearfix\"]")
  118. for (const vodElement of vodElements){
  119. let vodShort = new VodShort()
  120. vodShort.vod_id = Utils.getStrByRegex(/id\/(.*?).html/, $($(vodElement).find("[class=\"s_tit\"]")).find("a")[0].attribs.href)
  121. vodShort.vod_name = $($($(vodElement).find("[class=\"s_tit\"]")).find("a")).text()
  122. vodShort.vod_pic = this.getPic($(vodElement).find("img")[0].attribs.src)
  123. vodShort.vod_remarks = $($(vodElement).find("[class=\"s_score\"]")).text()
  124. vod_list.push(vodShort)
  125. }
  126. return vod_list
  127. }
  128. async setClasses() {
  129. let $ = await this.getHtml()
  130. let content = $($("[class=\"container\"]").find("script")).html()
  131. let navContent = Utils.getStrByRegex(/document.write\('(.*?);/, content)
  132. for (const navElement of $(navContent).find("a")) {
  133. let type_id = navElement.attribs["href"]
  134. let type_name = $(navElement).text()
  135. if (type_id !== "/" && type_name !== "专题" && type_name !== "站长模板") {
  136. this.classes.push(this.getTypeDic(type_name, Utils.getStrByRegex(/id\/(.*?).html/, type_id)))
  137. }
  138. }
  139. }
  140. async getFilter($) {
  141. let elements = $($("[class=\"container\"]").find("[class=\"select_list clearfix\"]")).find("li")
  142. let extend_list = []
  143. let key_value_dic = {
  144. "分类": /id\/(.*?).html/,
  145. "地区": /area\/(.*?)\//,
  146. "年份": /year\/(.*?).html/,
  147. "字母": /letter\/(.*?).html/,
  148. "排序": /by\/(.*?)\//,
  149. }
  150. for (let i = 0; i < elements.length; i++) {
  151. let element = elements[i]
  152. let name = $($($(element).find("[class=\"v-tit\"]"))).text().replaceAll(":", "")
  153. if (name !== "频道") {
  154. let extend_dic = {"key": (i + 1).toString(), "name": name, "value": []}
  155. for (const ele of $(element).find("a")) {
  156. let type_id = Utils.getStrByRegex(key_value_dic[name], ele.attribs.href)
  157. if (_.isEmpty(type_id)) {
  158. type_id = "/"
  159. }
  160. extend_dic["value"].push({"n": $(ele).text(), "v": decodeURIComponent(type_id)})
  161. }
  162. extend_list.push(extend_dic)
  163. }
  164. }
  165. let sortElments = $("[class=\"v-hd clearfix\"]")
  166. let extend_dic = {"key": (elements.length + 1).toString(), "name": "排序", "value": []}
  167. extend_dic["value"].push({"n": "全部", "v": "/"})
  168. for (const ele of $(sortElments).find("a")) {
  169. let type_id = Utils.getStrByRegex(key_value_dic["排序"], ele.attribs.href)
  170. if (_.isEmpty(type_id)) {
  171. type_id = "/"
  172. }
  173. extend_dic["value"].push({"n": $(ele).text(), "v": type_id})
  174. }
  175. extend_list.push(extend_dic)
  176. return extend_list
  177. }
  178. async setFilterObj() {
  179. for (const class_dic of this.classes) {
  180. let type_id = class_dic["type_id"]
  181. if (type_id !== "最近更新") {
  182. let $ = await this.getHtml(this.siteUrl + `/index.php/vod/show/id/${type_id}.html`)
  183. this.filterObj[type_id] = await this.getFilter($)
  184. }
  185. }
  186. }
  187. async setHomeVod() {
  188. let $ = await this.getHtml()
  189. this.homeVodList = await this.parseVodShortListFromDoc($)
  190. }
  191. getExtend(extend, key, value) {
  192. if (extend[key] !== undefined && extend[key] !== "/") {
  193. return value + "/" + extend[key] + "/"
  194. } else {
  195. return ""
  196. }
  197. }
  198. async setCategory(tid, pg, filter, extend) {
  199. let area = this.getExtend(extend, "3", "area")
  200. let sort = this.getExtend(extend, "6", "by")
  201. let id = this.getExtend(extend, "2", "id")
  202. let letter = this.getExtend(extend, "5", "letter")
  203. let year = this.getExtend(extend, "4", "year")
  204. if (_.isEmpty(id)) {
  205. id = "id/" + tid + "/"
  206. }
  207. let url = this.siteUrl + `/index.php/vod/show/${area}${sort}${id}${letter}${year}page/${pg}.html`
  208. let $ = await this.getHtml(url)
  209. this.vodList = await this.parseVodShortListFromDocByCategory($)
  210. }
  211. async setDetail(id) {
  212. let content = await this.fetch(this.siteUrl + "/api.php/provide/vod", {
  213. "ac": "detail", "ids": id
  214. }, this.getHeader())
  215. this.vodDetail = await this.parseVodDetailfromJson(JSON.parse(content))
  216. }
  217. async setSearch(wd, quick) {
  218. let $ = await this.getHtml(this.siteUrl + "/index.php/vod/search.html?wd="+wd)
  219. this.vodList = await this.parseVodShortListFromDocBySearch($)
  220. }
  221. }
  222. let spider = new JiaFeiMaoSpider()
  223. async function init(cfg) {
  224. await spider.init(cfg)
  225. }
  226. async function home(filter) {
  227. return await spider.home(filter)
  228. }
  229. async function homeVod() {
  230. return await spider.homeVod()
  231. }
  232. async function category(tid, pg, filter, extend) {
  233. return await spider.category(tid, pg, filter, extend)
  234. }
  235. async function detail(id) {
  236. return await spider.detail(id)
  237. }
  238. async function play(flag, id, flags) {
  239. return await spider.play(flag, id, flags)
  240. }
  241. async function search(wd, quick) {
  242. return await spider.search(wd, quick)
  243. }
  244. async function proxy(segments, headers) {
  245. return await spider.proxy(segments, headers)
  246. }
  247. export function __jsEvalReturn() {
  248. return {
  249. init: init,
  250. home: home,
  251. homeVod: homeVod,
  252. category: category,
  253. detail: detail,
  254. play: play,
  255. search: search,
  256. proxy: proxy
  257. };
  258. }
  259. export {spider}