index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const axios_1 = require("axios");
  4. const pageSize = 20;
  5. function formatMusicItem(it) {
  6. return {
  7. id: it.photo.id,
  8. title: it.photo.caption,
  9. artist: it.author.name,
  10. artwork: it.photo.coverUrl || it.photo.photoUrl,
  11. manifest: it.photo.manifest
  12. };
  13. }
  14. async function searchMusic(query, page) {
  15. var _a, _b;
  16. const body = {
  17. query: `fragment photoContent on PhotoEntity {
  18. __typename
  19. id
  20. duration
  21. caption
  22. originCaption
  23. likeCount
  24. viewCount
  25. commentCount
  26. realLikeCount
  27. coverUrl
  28. photoUrl
  29. photoH265Url
  30. manifest
  31. manifestH265
  32. videoResource
  33. coverUrls {
  34. url
  35. __typename
  36. }
  37. timestamp
  38. expTag
  39. animatedCoverUrl
  40. distance
  41. videoRatio
  42. liked
  43. stereoType
  44. profileUserTopPhoto
  45. musicBlocked
  46. riskTagContent
  47. riskTagUrl
  48. }
  49. fragment recoPhotoFragment on recoPhotoEntity {
  50. __typename
  51. id
  52. duration
  53. caption
  54. originCaption
  55. likeCount
  56. viewCount
  57. commentCount
  58. realLikeCount
  59. coverUrl
  60. photoUrl
  61. photoH265Url
  62. manifest
  63. manifestH265
  64. videoResource
  65. coverUrls {
  66. url
  67. __typename
  68. }
  69. timestamp
  70. expTag
  71. animatedCoverUrl
  72. distance
  73. videoRatio
  74. liked
  75. stereoType
  76. profileUserTopPhoto
  77. musicBlocked
  78. riskTagContent
  79. riskTagUrl
  80. }
  81. fragment feedContent on Feed {
  82. type
  83. author {
  84. id
  85. name
  86. headerUrl
  87. following
  88. headerUrls {
  89. url
  90. __typename
  91. }
  92. __typename
  93. }
  94. photo {
  95. ...photoContent
  96. ...recoPhotoFragment
  97. __typename
  98. }
  99. canAddComment
  100. llsid
  101. status
  102. currentPcursor
  103. tags {
  104. type
  105. name
  106. __typename
  107. }
  108. __typename
  109. }
  110. query visionSearchPhoto($keyword: String, $pcursor: String, $searchSessionId: String, $page: String, $webPageArea: String) {
  111. visionSearchPhoto(keyword: $keyword, pcursor: $pcursor, searchSessionId: $searchSessionId, page: $page, webPageArea: $webPageArea) {
  112. result
  113. llsid
  114. webPageArea
  115. feeds {
  116. ...feedContent
  117. __typename
  118. }
  119. searchSessionId
  120. pcursor
  121. aladdinBanner {
  122. imgUrl
  123. link
  124. __typename
  125. }
  126. __typename
  127. }
  128. }`,
  129. variables: {
  130. keyword: query,
  131. page: "search",
  132. pcursor: `${page - 1}`,
  133. },
  134. };
  135. const result = (await axios_1.default.post("https://www.kuaishou.com/graphql", body, {
  136. headers: {
  137. 'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
  138. host: 'www.kuaishou.com',
  139. origin: 'https://www.kuaishou.com',
  140. referer: `https://www.kuaishou.com/search/video?searchKey=${encodeURIComponent((query))}`,
  141. }
  142. })).data.data.visionSearchPhoto;
  143. return {
  144. isEnd: !(result === null || result === void 0 ? void 0 : result.pcursor) || (result === null || result === void 0 ? void 0 : result.pcursor) === 'no_more',
  145. data: (_b = (_a = result === null || result === void 0 ? void 0 : result.feeds) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, formatMusicItem)
  146. };
  147. }
  148. module.exports = {
  149. platform: "快手",
  150. version: "0.0.2",
  151. author: '猫头猫',
  152. srcUrl: "https://gitee.com/maotoumao/MusicFreePlugins/raw/v0.1/dist/kuaishou/index.js",
  153. cacheControl: "no-cache",
  154. supportedSearchType: ["music"],
  155. async search(query, page, type) {
  156. if (type === "music") {
  157. return await searchMusic(query, page);
  158. }
  159. },
  160. async getMediaSource(musicItem, quality) {
  161. if (!musicItem.manifest) {
  162. return;
  163. }
  164. const adaptationSet = musicItem.manifest.adaptationSet;
  165. const representation = adaptationSet[0].representation;
  166. return {
  167. url: representation[0].url
  168. };
  169. },
  170. };