index.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import axios from "axios";
  2. const pageNum = 20;
  3. function formatMusicItem(item) {
  4. return {
  5. id: item.id,
  6. title: item.title,
  7. artist:
  8. item?.allArtistNames ||
  9. item.artists?.map?.((s) => s.name).join(", ") ||
  10. item.user?.niceName,
  11. artwork: item?.headImg,
  12. urls: item?.fullClip?.urls,
  13. };
  14. }
  15. function formatArtistItem(item) {
  16. return {
  17. id: item.id,
  18. name: item.name,
  19. avatar: item.headImg,
  20. };
  21. }
  22. let lastQuery;
  23. let lastMusicId;
  24. async function searchMusic(query, page) {
  25. // 新的搜索
  26. if (query !== lastQuery || page === 1) {
  27. lastMusicId = 0;
  28. }
  29. lastQuery = query;
  30. let data = JSON.stringify({
  31. searchType: "MV",
  32. key: query,
  33. sinceId: lastMusicId,
  34. size: pageNum,
  35. requestTagRows: [
  36. {
  37. key: "sortType",
  38. chosenTags: ["HOTTEST"],
  39. },
  40. {
  41. key: "source",
  42. chosenTags: ["-1"],
  43. },
  44. {
  45. key: "duration",
  46. chosenTags: ["-1"],
  47. },
  48. ],
  49. });
  50. let config = {
  51. method: "post",
  52. maxBodyLength: Infinity,
  53. url: "https://search-api.yinyuetai.com/search/get_search_result.json",
  54. headers: {
  55. referrer: "https://www.yinyuetai.com/",
  56. accept: "application/json",
  57. "content-type": "application/json",
  58. wua: "YYT/1.0.0 (WEB;web;11;zh-CN;kADiV2jNJFy2ryvuyB5Ne)",
  59. },
  60. data: data,
  61. };
  62. const response = (await axios.request(config)).data.data;
  63. lastMusicId = response[response.length - 1].id;
  64. return {
  65. isEnd: pageNum > response.length,
  66. data: response.map(formatMusicItem),
  67. };
  68. }
  69. // async function searchArtist(query, page) {
  70. // let data = JSON.stringify({
  71. // searchType: "ARTIST",
  72. // key: query,
  73. // sinceId: 0,
  74. // size: 2 * pageNum,
  75. // });
  76. // let config = {
  77. // method: "post",
  78. // maxBodyLength: Infinity,
  79. // url: "https://search-api.yinyuetai.com/search/get_search_result.json",
  80. // headers: {
  81. // referrer: "https://www.yinyuetai.com/",
  82. // accept: "application/json",
  83. // "content-type": "application/json",
  84. // wua: "YYT/1.0.0 (WEB;web;11;zh-CN;kADiV2jNJFy2ryvuyB5Ne)",
  85. // },
  86. // data: data,
  87. // };
  88. // const response = (await axios.request(config)).data.data;
  89. // return {
  90. // isEnd: true,
  91. // data: response.map(formatArtistItem),
  92. // };
  93. // }
  94. async function search(query, page, type) {
  95. if (type === "music") {
  96. return await searchMusic(query, page);
  97. }
  98. // else if (type === "artist") {
  99. // return await searchArtist(query, page);
  100. // }
  101. }
  102. async function getMediaSource(musicItem, quality) {
  103. let url;
  104. if (quality === "standard") {
  105. url = musicItem.urls.find((it) => it.streamType === 5).url;
  106. } else if (quality === "high") {
  107. url = musicItem.urls.find((it) => it.streamType === 1).url;
  108. }
  109. return {
  110. url,
  111. };
  112. }
  113. // let lastArtistId;
  114. // let lastArtistSinceId = 0;
  115. // let cacheExtendId;
  116. // async function getArtistWorks(artistItem, page, type) {
  117. // if (type === "music") {
  118. // let sinceId =
  119. // page === 1 || artistItem.id !== lastArtistId ? 0 : lastArtistSinceId;
  120. // lastArtistId = artistItem.id;
  121. // if (sinceId === 0) {
  122. // const personBaseInfo = (
  123. // await axios.get("https://person-api.yinyuetai.com/person/getBase", {
  124. // params: {
  125. // id: artistItem.id,
  126. // },
  127. // headers: {
  128. // referrer: "https://www.yinyuetai.com/",
  129. // accept: "application/json",
  130. // "content-type": "application/json",
  131. // wua: "YYT/1.0.0 (WEB;web;11;zh-CN;kADiV2jNJFy2ryvuyB5Ne)",
  132. // },
  133. // })
  134. // ).data;
  135. // console.log(personBaseInfo)
  136. // cacheExtendId = personBaseInfo.extendId;
  137. // }
  138. // const medias = (
  139. // await axios.get("https://video-api.yinyuetai.com/video/listByArtist", {
  140. // params: {
  141. // artistId: cacheExtendId,
  142. // size: pageNum,
  143. // sinceId,
  144. // },
  145. // })
  146. // ).data.data;
  147. // lastArtistSinceId = medias[medias.length - 1].id;
  148. // return {
  149. // isEnd: medias.length < pageNum,
  150. // data: medias.map(formatMusicItem),
  151. // };
  152. // }
  153. // }
  154. module.exports = {
  155. platform: "音悦台",
  156. version: "0.0.0",
  157. supportedSearchType: ["music"],
  158. srcUrl:
  159. "https://gitee.com/maotoumao/MusicFreePlugins/raw/v0.1/dist/yinyuetai/index.js",
  160. cacheControl: "no-cache",
  161. search,
  162. getMediaSource,
  163. // getArtistWorks,
  164. };