aliyunpanshare.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * @File : aliyunpanshare.js
  3. * @Author : jade
  4. * @Date : 2024/1/26 13:06
  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 { detailContent,initCloud,playContent,getHeaders} from "../lib/cloud.js";
  12. import * as Utils from "../lib/utils.js";
  13. import {Spider} from "./spider.js";
  14. let remark_list = ["4k", "4K"]
  15. class AliyunpanShare extends Spider {
  16. constructor() {
  17. super();
  18. this.siteUrl = 'https://www.alypw.com';
  19. }
  20. async init(cfg) {
  21. await super.init(cfg);
  22. await initCloud(this.cfgObj);
  23. }
  24. getName() {
  25. return "🥏‍┃阿里云盘分享┃🥏‍"
  26. }
  27. getAppName() {
  28. return "阿里云盘分享"
  29. }
  30. getJSName() {
  31. return "aliyunpanshare"
  32. }
  33. getType() {
  34. return 3
  35. }
  36. getRemarks(name, title) {
  37. if (_.isEmpty(name)) {
  38. for (const remark of remark_list) {
  39. if (title.indexOf(remark) > -1) {
  40. return remark
  41. }
  42. }
  43. } else {
  44. return name
  45. }
  46. }
  47. parseVodName(name) {
  48. let vod_name = Utils.getStrByRegex(/\[阿里云盘](.*?) /, name)
  49. if (name.indexOf("合集") > -1) {
  50. return ""
  51. }
  52. if (_.isEmpty(vod_name)) {
  53. vod_name = Utils.getStrByRegex(/\[阿里云盘](.*?)(/, name)
  54. }
  55. if (vod_name.indexOf("[") > -1) {
  56. vod_name = vod_name.split("[")[0]
  57. }
  58. if (vod_name.indexOf("【") > -1) {
  59. vod_name = vod_name.split("【")[0]
  60. }
  61. if (vod_name === "4K") {
  62. return ""
  63. }
  64. return vod_name
  65. }
  66. async parseVodShortListFromDoc($) {
  67. let vod_list = []
  68. let vodElements = $($("[class=\"hometab\"]").find("[class=\"box\"]")).find("li")
  69. for (const vodElement of vodElements) {
  70. let ele = $(vodElement).find("[class=\"imgr\"]")[0]
  71. let vodShort = new VodShort();
  72. vodShort.vod_id = $(ele).find("a")[0].attribs["href"]
  73. let name = $(ele).find("a")[0].attribs["title"]
  74. vodShort.vod_name = this.parseVodName(name)
  75. vodShort.vod_pic = $(vodElement).find("img")[0].attribs["src"]
  76. vodShort.vod_remarks = this.getRemarks(Utils.getStrByRegex(/【(.*?)】/, name), name)
  77. vod_list.push(vodShort)
  78. }
  79. return vod_list
  80. }
  81. async parseVodShortListFromDocByCategory($) {
  82. let vod_list = []
  83. let mainElement = $("[class=\"main container\"]")
  84. let vodElements = $($(mainElement).find("[class=\"list\"]")).find("li")
  85. if (vodElements.length === 0) {
  86. vodElements = $(mainElement).find("li")
  87. }
  88. for (const vodElement of vodElements) {
  89. let name = $(vodElement).find("img")[0].attribs["alt"].replaceAll("<strong>", "").replaceAll("</strong>", "")
  90. let vodShort = new VodShort();
  91. vodShort.vod_id = $(vodElement).find("a")[0].attribs["href"]
  92. vodShort.vod_name = this.parseVodName(name)
  93. vodShort.vod_pic = $(vodElement).find("img")[0].attribs["src"]
  94. vodShort.vod_remarks = this.getRemarks(Utils.getStrByRegex(/【(.*?)】/, name), name)
  95. if (!_.isEmpty(vodShort.vod_name)) {
  96. vod_list.push(vodShort)
  97. }
  98. }
  99. return vod_list
  100. }
  101. async parseVodDetailFromDoc($) {
  102. let mainElements = $("[class=\"mainl\"]")
  103. let name = $($(mainElements).find("[class=\"title\"]")[0]).text()
  104. let vodDetail = new VodDetail();
  105. vodDetail.vod_name = Utils.getStrByRegex(/\[阿里云盘](.*?) /, name)
  106. vodDetail.vod_remarks = this.getRemarks(Utils.getStrByRegex(/【(.*?)】/, name), name)
  107. let articleElement = $(mainElements).find("[class=\"article_content\"]")
  108. vodDetail.vod_pic = $(articleElement).find("p>img")[0].attribs["src"]
  109. let articleElements = $(articleElement).find("p")
  110. let articleContent = ""
  111. for (const articleEle of articleElements) {
  112. articleContent = articleContent + $(articleEle).text() + "\n"
  113. }
  114. let share_ali_url_list = []
  115. let share_url_list = Utils.getStrByRegex(Utils.patternAli, articleContent).split("\n")
  116. for (const share_url of share_url_list) {
  117. let matches = share_url.match(Utils.patternAli);
  118. if (!_.isEmpty(matches)) share_ali_url_list.push(matches[1])
  119. let quarkMatches = share_url.match(Utils.patternQuark);
  120. if (!_.isEmpty(quarkMatches)) share_ali_url_list.push(quarkMatches[1])
  121. }
  122. let playVod = await detailContent([share_ali_url_list])
  123. vodDetail.vod_play_from = _.keys(playVod).join('$$$');
  124. vodDetail.vod_play_url = _.values(playVod).join('$$$');
  125. vodDetail.type_name = Utils.getStrByRegex(/标签(.*?)\n/, articleContent).replaceAll(":", "")
  126. vodDetail.vod_content = Utils.getStrByRegex(/描述(.*?)\n/, articleContent).replaceAll(":", "")
  127. return vodDetail
  128. }
  129. async setClasses() {
  130. let $ = await this.getHtml()
  131. let typeElements = $("[id^='navbar-category']").find("a")
  132. let key_list = ["影", "剧", "4K", "视", "音", "演", "动漫"]
  133. for (const typeElement of typeElements) {
  134. let type_name = $(typeElement).text()
  135. let type_id = typeElement.attribs["href"]
  136. let is_show = false
  137. for (const key of key_list) {
  138. if (type_name.indexOf(key) > -1) {
  139. is_show = true
  140. }
  141. }
  142. if (is_show) {
  143. this.classes.push(this.getTypeDic(type_name, type_id))
  144. }
  145. }
  146. }
  147. async setHomeVod() {
  148. let $ = await this.getHtml()
  149. this.homeVodList = await this.parseVodShortListFromDoc($)
  150. }
  151. async setCategory(tid, pg, filter, extend) {
  152. let cateUrl = tid.split(".html")[0] + "_" + pg + ".html"
  153. let $ = await this.getHtml(cateUrl)
  154. this.vodList = await this.parseVodShortListFromDocByCategory($)
  155. }
  156. async setDetail(id) {
  157. let $ = await this.getHtml(id)
  158. this.vodDetail = await this.parseVodDetailFromDoc($)
  159. }
  160. async setPlay(flag, id, flags) {
  161. this.playUrl = await playContent(flag, id, flags);
  162. this.result.setHeader(getHeaders(flag))
  163. }
  164. async setSearch(wd, quick) {
  165. let url = this.siteUrl + `/search.php?q=${wd}`
  166. let $ = await this.getHtml(url)
  167. this.vodList = await this.parseVodShortListFromDocByCategory($)
  168. }
  169. }
  170. let spider = new AliyunpanShare()
  171. async function init(cfg) {
  172. await spider.init(cfg)
  173. }
  174. async function home(filter) {
  175. return await spider.home(filter)
  176. }
  177. async function homeVod() {
  178. return await spider.homeVod()
  179. }
  180. async function category(tid, pg, filter, extend) {
  181. return await spider.category(tid, pg, filter, extend)
  182. }
  183. async function detail(id) {
  184. return await spider.detail(id)
  185. }
  186. async function play(flag, id, flags) {
  187. return await spider.play(flag, id, flags)
  188. }
  189. async function search(wd, quick) {
  190. return await spider.search(wd, quick)
  191. }
  192. export function __jsEvalReturn() {
  193. return {
  194. init: init, home: home, homeVod: homeVod, category: category, detail: detail, play: play, search: search,
  195. };
  196. }
  197. export {spider}