pan_search.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * @File : pan_search.js
  3. * @Author : jade
  4. * @Date : 2023/12/25 17:18
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc : 阿里盘搜(仅支持搜搜)
  8. */
  9. import {_, load} from "../lib/cat.js";
  10. import {Spider} from "./spider.js";
  11. import {VodDetail, VodShort} from "../lib/vod.js";
  12. import { detailContent,initCloud,playContent,getHeaders } from "../lib/cloud.js";
  13. class PanSearchSpider extends Spider {
  14. constructor() {
  15. super();
  16. this.siteUrl = "https://www.pansearch.me/"
  17. }
  18. getName() {
  19. return "🗂️┃阿里盘搜┃🗂️"
  20. }
  21. getAppName() {
  22. return "阿里盘搜"
  23. }
  24. getJSName() {
  25. return "pan_search"
  26. }
  27. getType() {
  28. return 3
  29. }
  30. getSearchHeader() {
  31. let headers = this.getHeader();
  32. headers["x-nextjs-data"] = "1";
  33. return headers;
  34. }
  35. async init(cfg) {
  36. await super.init(cfg);
  37. await initCloud(this.cfgObj);
  38. }
  39. async parseVodDetailfromJson(obj) {
  40. let item = JSON.parse(obj)
  41. let vodDetail = new VodDetail();
  42. let splitList = item["content"].split("\n");
  43. vodDetail.vod_name = splitList[0].replaceAll(/<\\?[^>]+>/g, "").replace("名称:", "");
  44. let date = new Date(item["time"])
  45. vodDetail.vod_remarks = date.toLocaleDateString().replace(/\//g, "-") + " " + date.toTimeString().substr(0, 8)
  46. vodDetail.vod_pic = item["image"]
  47. let share_url = ""
  48. for (const content of splitList) {
  49. if (content.indexOf("描述") > -1) {
  50. vodDetail.vod_content = content.replace("描述:", "").replaceAll(/<\\?[^>]+>/g, "")
  51. }
  52. if (content.indexOf("标签:") > -1) {
  53. vodDetail.type_name = content.replace("🏷 标签:", "")
  54. }
  55. if (content.indexOf("链接:") > -1) {
  56. share_url = content.replaceAll(/<\\?[^>]+>/g, "").replace("链接:", "");
  57. }
  58. }
  59. let playVod = await detailContent([share_url])
  60. vodDetail.vod_play_from = _.keys(playVod).join('$$$');
  61. vodDetail.vod_play_url = _.values(playVod).join('$$$');
  62. return vodDetail
  63. }
  64. async parseVodShortListFromDocBySearch($, wd) {
  65. let vod_list = []
  66. let buildId = JSON.parse($("script[id=__NEXT_DATA__]")[0].children[0].data)["buildId"]
  67. let url = this.siteUrl + "_next/data/" + buildId + "/search.json?keyword=" + encodeURIComponent(wd) + "&pan=aliyundrive";
  68. let aliContent = await this.fetch(url, null, this.getSearchHeader())
  69. if (!_.isEmpty(aliContent)) {
  70. let items = JSON.parse(aliContent)["pageProps"]["data"]["data"]
  71. for (const item of items) {
  72. let vodShort = new VodShort()
  73. vodShort.vod_id = JSON.stringify(item)
  74. let splitList = item["content"].split("\n");
  75. vodShort.vod_name = splitList[0].replaceAll(/<\\?[^>]+>/g, "").replace("名称:", "");
  76. let date = new Date(item["time"])
  77. vodShort.vod_remarks = date.toLocaleDateString().replace(/\//g, "-") + " " + date.toTimeString().substr(0, 8)
  78. vodShort.vod_pic = item["image"]
  79. vod_list.push(vodShort)
  80. }
  81. return vod_list
  82. } else {
  83. await this.jadeLog.error("搜索页面解析失败", true)
  84. }
  85. }
  86. async setDetail(id) {
  87. this.vodDetail = await this.parseVodDetailfromJson(id)
  88. }
  89. async setSearch(wd, quick) {
  90. let html = await this.fetch(this.siteUrl, null, this.getHeader())
  91. if (!_.isEmpty(html)) {
  92. let $ = load(html)
  93. this.vodList = await this.parseVodShortListFromDocBySearch($, wd)
  94. }
  95. }
  96. async setPlay(flag, id, flags) {
  97. this.playUrl = await playContent(flag, id, flags);
  98. this.result.setHeader(getHeaders(flag))
  99. }
  100. }
  101. let spider = new PanSearchSpider()
  102. async function init(cfg) {
  103. await spider.init(cfg)
  104. }
  105. async function home(filter) {
  106. return await spider.home(filter)
  107. }
  108. async function homeVod() {
  109. return await spider.homeVod()
  110. }
  111. async function category(tid, pg, filter, extend) {
  112. return await spider.category(tid, pg, filter, extend)
  113. }
  114. async function detail(id) {
  115. return await spider.detail(id)
  116. }
  117. async function play(flag, id, flags) {
  118. return await spider.play(flag, id, flags)
  119. }
  120. async function search(wd, quick) {
  121. return await spider.search(wd, quick)
  122. }
  123. export function __jsEvalReturn() {
  124. return {
  125. init: init, home: home, homeVod: homeVod, category: category, detail: detail, play: play, search: search,
  126. };
  127. }
  128. export {spider}