aiyingshi.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * @Author: samples jadehh@live.com
  3. * @Date: 2023-12-14 11:03:04
  4. * @LastEditors: samples jadehh@live.com
  5. * @LastEditTime: 2023-12-14 11:03:04
  6. * @FilePath: js/aiyingshi.js
  7. * @Description: 爱影视爬虫类
  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 AiYingShiSpider extends Spider {
  14. constructor() {
  15. super();
  16. this.siteUrl = 'https://aiyingshis.com';
  17. }
  18. getName() {
  19. return "🚀‍┃爱影视┃🚀"
  20. }
  21. getAppName() {
  22. return "爱影视"
  23. }
  24. getJSName() {
  25. return "aiyingshi"
  26. }
  27. getType() {
  28. return 3
  29. }
  30. async parseVodShortListFromDoc($) {
  31. let items = $('.module-item');
  32. let vod_list = [];
  33. for (const item of items) {
  34. let vodShort = new VodShort()
  35. let oneA = $(item).find('.module-item-cover .module-item-pic a').first();
  36. vodShort.vod_id = oneA.attr('href');
  37. vodShort.vod_name = oneA.attr('title');
  38. let pic = $(item).find('.module-item-cover .module-item-pic img').first().attr('data-src')
  39. if (pic.indexOf("img.php?url=") > 0) {
  40. pic = pic.split("img.php?url=")[1]
  41. }else if (pic.indexOf("https:") === -1 && pic.indexOf("http:") === -1){
  42. pic = "https:" + pic
  43. }
  44. vodShort.vod_pic = pic
  45. vodShort.vod_remarks = $(item).find('.module-item-text').first().text();
  46. if (vodShort.vod_name !== undefined){
  47. vod_list.push(vodShort)
  48. }
  49. }
  50. return vod_list
  51. }
  52. async parseVodDetailFromDoc($) {
  53. let vodDetail = new VodDetail()
  54. vodDetail.vod_name = $('.page-title')[0].children[0].data
  55. vodDetail.vod_pic = $($("[class=\"video-cover\"]")).find(".lazyload")[0].attribs["data-src"]
  56. let video_info_list = $($(".video-info-aux")).text().replaceAll("\t","").split("\n")
  57. let type_list = []
  58. for (const video_info of video_info_list){
  59. if (!_.isEmpty(video_info.replaceAll(" ","").replaceAll("/",""))){
  60. type_list.push(video_info.replaceAll(" ","").replaceAll("/",""))
  61. }
  62. }
  63. vodDetail.type_name = type_list.slice(0,2).join("*")
  64. let video_items = $("[class=\"video-info-items\"]")
  65. vodDetail.vod_director = $(video_items[0]).find("a")[0].children[0].data
  66. let vidoe_info_actor_list = $(video_items[1]).find("a")
  67. let actor_list = []
  68. for (const vidoe_info_actor of vidoe_info_actor_list) {
  69. actor_list.push(vidoe_info_actor.children[0].data)
  70. }
  71. vodDetail.vod_actor = actor_list.join(" * ")
  72. vodDetail.vod_year = type_list[2]
  73. vodDetail.vod_remarks = $($(video_items[3]).find(".video-info-item")).text()
  74. vodDetail.vod_content = $($(video_items[5]).find(".video-info-item")).text()
  75. vodDetail.vod_area = type_list[3]
  76. vodDetail.vod_content = vodDetail.vod_content.replace("[收起部分]", "").replace("[展开全部]", "").replaceAll("\t","").replaceAll("\n","")
  77. let playElements = $($("[class=\"module-tab-content\"]")[0]).find("span")
  78. let urlElements = $("[class=\"module-list module-player-list tab-list sort-list \"]")
  79. let form_list = []
  80. for (const playerElement of playElements){
  81. form_list.push($(playerElement).text())
  82. }
  83. let play_url_list = []
  84. for (const urlElement of urlElements){
  85. let playUrlElements = $($(urlElement).find("[class=\"sort-item\"]")).find("a")
  86. let vodItems = []
  87. for (const playUrlElement of playUrlElements){
  88. let name = $(playUrlElement).text()
  89. let url = playUrlElement.attribs["href"]
  90. let play_url = name + "$" + url
  91. vodItems.push(play_url)
  92. }
  93. play_url_list.push(vodItems.join("#"))
  94. }
  95. vodDetail.vod_play_from = form_list.join('$$$');
  96. vodDetail.vod_play_url = _.values(play_url_list).join('$$$');
  97. return vodDetail
  98. }
  99. async parseVodShortListFromDocBySearch($) {
  100. let items = $('.module-search-item');
  101. let vod_list = [];
  102. for (const item of items) {
  103. let vodShort = new VodShort()
  104. vodShort.vod_id = $(item).find(".video-serial")[0].attribs.href;
  105. vodShort.vod_name = $(item).find(".video-serial")[0].attribs.title;
  106. vodShort.vod_pic = $(item).find(".module-item-pic > img")[0].attribs['data-src']
  107. vodShort.vod_remarks = $($(item).find(".video-serial")[0]).text();
  108. vod_list.push(vodShort);
  109. }
  110. return vod_list
  111. }
  112. async setClasses() {
  113. let con = await this.fetch(this.siteUrl, null, this.getHeader());
  114. if (!_.isEmpty(con)) {
  115. const $ = load(con);
  116. let elements = $($("[class=\"nav-menu-items\"]")[0]).find("li")
  117. for (const element of elements.slice(0,6)) {
  118. let type_name = $($(element).find("span")).text()
  119. if (type_name !== "首页"){
  120. let type_id = $(element).find("a")[0].attribs["href"].split("/").slice(-1)[0].split(".")[0]
  121. let type_dic = {"type_id": type_id, "type_name": type_name}
  122. this.classes.push(type_dic)
  123. }
  124. }
  125. }
  126. }
  127. async getFilter($) {
  128. let elements = $("[class=\"scroll-content\"]").slice(1)
  129. let extend_list = []
  130. for (let i = 0; i < elements.length; i++) {
  131. let extend_dic = {"key": (i + 1).toString(), "name": "", "value": []}
  132. if (i < elements.length - 1) {
  133. extend_dic["name"] = $($(elements[i]).find("a")[0]).text()
  134. extend_dic["value"].push({"n": "全部", "v": "0"})
  135. for (const ele of $(elements[i]).find("a").slice(1)) {
  136. if ($($(elements[i]).find("a")[0]).text() === "全部类型"){
  137. extend_dic["value"].push({"n": $(ele).text(), "v":ele.attribs["href"].split("/").slice(-1)[0].split(".")[0]})
  138. }else{
  139. extend_dic["value"].push({"n": $(ele).text(), "v":$(ele).text()})
  140. }
  141. }
  142. extend_list.push(extend_dic)
  143. } else {
  144. extend_dic["name"] = $($(elements[i]).find("a")[0]).text()
  145. extend_dic["value"] = [{"n": "全部", "v": "0"}, {
  146. "n": $($(elements[i]).find("a")[1]).text(),
  147. "v": "hits"
  148. }, {"n": $($(elements[i]).find("a")[2]).text(), "v": "score"}]
  149. extend_list.push(extend_dic)
  150. }
  151. }
  152. return extend_list
  153. }
  154. async setFilterObj() {
  155. for (const type_dic of this.classes) {
  156. let type_id = type_dic["type_id"]
  157. if (type_id !== "/" && type_id !== "最近更新") {
  158. let url = this.siteUrl + `/vodshow/id/${type_id}.html`
  159. let html = await this.fetch(url, null, this.getHeader())
  160. if (html != null) {
  161. let $ = load(html)
  162. this.filterObj[type_id] = await this.getFilter($)
  163. }
  164. }
  165. }
  166. }
  167. async setHomeVod() {
  168. let con = await this.fetch(this.siteUrl, null, this.getHeader());
  169. if (!_.isEmpty(con)) {
  170. const $ = load(con);
  171. this.homeVodList = await this.parseVodShortListFromDoc($)
  172. }
  173. }
  174. getExtend(value,defaultvalue,key = ""){
  175. if (value !== undefined && value !== "0"){
  176. return key + value
  177. }else{
  178. return defaultvalue
  179. }
  180. }
  181. async getCateUrl(tid,pg,extend){
  182. tid = this.getExtend(extend["1"],tid)
  183. let area = this.getExtend(extend["2"],"","/area/")
  184. let lanuage = this.getExtend(extend["3"],"","/lang/")
  185. let year = this.getExtend(extend["4"],"","/year/")
  186. let letter = this.getExtend(extend["5"],"","/letter/")
  187. let time = this.getExtend(extend['6'],"","/by/")
  188. return this.siteUrl + `/vodshow${time}${area}/id/${tid}${lanuage}${letter}${year}/page/${pg}.html`
  189. }
  190. async setCategory(tid, pg, filter, extend) {
  191. let reqUrl = await this.getCateUrl(tid,pg,extend)
  192. let html = await this.fetch(reqUrl, null, this.getHeader())
  193. if (!_.isEmpty(html)) {
  194. let $ = load(html)
  195. this.vodList = await this.parseVodShortListFromDoc($)
  196. let total = Utils.getStrByRegex(/\$\("\.mac_total"\)\.text\('(\d+)'\)/, html)
  197. this.limit = 72;
  198. if (total.length > 0) {
  199. this.total = parseInt(total)
  200. }
  201. if (this.total <= this.limit) {
  202. this.count = 1
  203. } else {
  204. this.count = Math.ceil(this.total / this.limit)
  205. }
  206. }
  207. }
  208. async setDetail(id) {
  209. let detailUrl = this.siteUrl + id;
  210. let html = await this.fetch(detailUrl, null, this.getHeader());
  211. if (!_.isEmpty(html)) {
  212. let $ = load(html)
  213. this.vodDetail = await this.parseVodDetailFromDoc($)
  214. }
  215. }
  216. async setPlay(flag, id, flags) {
  217. let html = await this.fetch(this.siteUrl + id,null,this.getHeader())
  218. if (!_.isEmpty(html)){
  219. let player_str = Utils.getStrByRegex(/<script type="text\/javascript">var player_aaaa=(.*?)<\/script>/,html)
  220. let play_dic = JSON.parse(player_str)
  221. this.playUrl = play_dic["url"]
  222. }
  223. }
  224. async setSearch(wd, quick) {
  225. let searchUrl = this.siteUrl + `/vodsearch/wd/${wd}.html`
  226. let html = await this.fetch(searchUrl, null, this.getHeader())
  227. if (!_.isEmpty(html)) {
  228. let $ = load(html)
  229. this.vodList = await this.parseVodShortListFromDocBySearch($)
  230. }
  231. }
  232. }
  233. let spider = new AiYingShiSpider()
  234. async function init(cfg) {
  235. await spider.init(cfg)
  236. }
  237. async function home(filter) {
  238. return await spider.home(filter)
  239. }
  240. async function homeVod() {
  241. return await spider.homeVod()
  242. }
  243. async function category(tid, pg, filter, extend) {
  244. return await spider.category(tid, pg, filter, extend)
  245. }
  246. async function detail(id) {
  247. return await spider.detail(id)
  248. }
  249. async function play(flag, id, flags) {
  250. return await spider.play(flag, id, flags)
  251. }
  252. async function search(wd, quick) {
  253. return await spider.search(wd, quick)
  254. }
  255. async function proxy(segments, headers) {
  256. return await spider.proxy(segments, headers)
  257. }
  258. export function __jsEvalReturn() {
  259. return {
  260. init: init, home: home, homeVod: homeVod, category: category, detail: detail, play: play, search: search,proxy:proxy
  261. };
  262. }
  263. export {spider}