aliyunpanshare.js 7.2 KB

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