index.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const axios_1 = require("axios");
  4. const pageNum = 20;
  5. function formatMusicItem(item) {
  6. var _a, _b, _c, _d;
  7. return {
  8. id: item.id,
  9. title: item.title,
  10. artist: (item === null || item === void 0 ? void 0 : item.allArtistNames) ||
  11. ((_b = (_a = item.artists) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (s) => s.name).join(", ")) ||
  12. ((_c = item.user) === null || _c === void 0 ? void 0 : _c.niceName),
  13. artwork: item === null || item === void 0 ? void 0 : item.headImg,
  14. urls: (_d = item === null || item === void 0 ? void 0 : item.fullClip) === null || _d === void 0 ? void 0 : _d.urls,
  15. };
  16. }
  17. function formatArtistItem(item) {
  18. return {
  19. id: item.id,
  20. name: item.name,
  21. avatar: item.headImg,
  22. };
  23. }
  24. let lastQuery;
  25. let lastMusicId;
  26. async function searchMusic(query, page) {
  27. if (query !== lastQuery || page === 1) {
  28. lastMusicId = 0;
  29. }
  30. lastQuery = query;
  31. let data = JSON.stringify({
  32. searchType: "MV",
  33. key: query,
  34. sinceId: lastMusicId,
  35. size: pageNum,
  36. requestTagRows: [
  37. {
  38. key: "sortType",
  39. chosenTags: ["HOTTEST"],
  40. },
  41. {
  42. key: "source",
  43. chosenTags: ["-1"],
  44. },
  45. {
  46. key: "duration",
  47. chosenTags: ["-1"],
  48. },
  49. ],
  50. });
  51. let config = {
  52. method: "post",
  53. maxBodyLength: Infinity,
  54. url: "https://search-api.yinyuetai.com/search/get_search_result.json",
  55. headers: {
  56. referrer: "https://www.yinyuetai.com/",
  57. accept: "application/json",
  58. "content-type": "application/json",
  59. wua: "YYT/1.0.0 (WEB;web;11;zh-CN;kADiV2jNJFy2ryvuyB5Ne)",
  60. },
  61. data: data,
  62. };
  63. const response = (await axios_1.default.request(config)).data.data;
  64. lastMusicId = response[response.length - 1].id;
  65. return {
  66. isEnd: pageNum > response.length,
  67. data: response.map(formatMusicItem),
  68. };
  69. }
  70. async function search(query, page, type) {
  71. if (type === "music") {
  72. return await searchMusic(query, page);
  73. }
  74. }
  75. async function getMediaSource(musicItem, quality) {
  76. let url;
  77. if (quality === "standard") {
  78. url = musicItem.urls.find((it) => it.streamType === 5).url;
  79. }
  80. else if (quality === "high") {
  81. url = musicItem.urls.find((it) => it.streamType === 1).url;
  82. }
  83. return {
  84. url,
  85. };
  86. }
  87. module.exports = {
  88. platform: "音悦台",
  89. author: '猫头猫',
  90. version: "0.0.1",
  91. supportedSearchType: ["music"],
  92. srcUrl: "https://gitee.com/maotoumao/MusicFreePlugins/raw/v0.1/dist/yinyuetai/index.js",
  93. cacheControl: "no-cache",
  94. search,
  95. getMediaSource,
  96. };