index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const axios_1 = require("axios");
  4. const headers = {
  5. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61",
  6. };
  7. function formatMusicItem(it) {
  8. return {
  9. id: it.id,
  10. artist: it.artist,
  11. title: it.title,
  12. createdAt: it.created_at,
  13. artwork: it.image_path,
  14. url: it.song_path,
  15. duration: it.duration,
  16. mv: it.video_path,
  17. rawLrc: it.lyrics,
  18. };
  19. }
  20. async function searchMusic(query, page) {
  21. const pageSize = 30;
  22. const data = `{"searchQuery":{"sort":"plays","searchTerm":"${query}"},"pageParam":${page - 1},"pageSize":${pageSize},"trendingId":"93de406e-bdc1-40a6-befd-90637a362158"}`;
  23. const config = {
  24. method: "post",
  25. url: "https://www.udio.com/api/songs/search",
  26. headers: {
  27. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.0.0",
  28. host: "www.udio.com",
  29. },
  30. data: data,
  31. };
  32. const result = (await (0, axios_1.default)(config)).data.data;
  33. return {
  34. isEnd: result.length < pageSize,
  35. data: result.map(formatMusicItem),
  36. };
  37. }
  38. async function search(query, page, type) {
  39. if (type === "music") {
  40. return await searchMusic(query, page);
  41. }
  42. }
  43. async function getMediaSource(musicItem, quality) {
  44. if (quality !== "standard") {
  45. return;
  46. }
  47. return musicItem.url;
  48. }
  49. async function getTopLists() {
  50. return [
  51. {
  52. title: "趋势榜",
  53. data: [
  54. {
  55. id: "today",
  56. maxAgeInHours: 24,
  57. type: "search",
  58. title: "趋势榜 - 最近一天",
  59. },
  60. {
  61. id: "1week",
  62. maxAgeInHours: 168,
  63. type: "search",
  64. title: "趋势榜 - 最近一周",
  65. },
  66. {
  67. id: "1month",
  68. maxAgeInHours: 720,
  69. type: "search",
  70. title: "趋势榜 - 最近一月",
  71. },
  72. {
  73. id: "alltime",
  74. type: "search",
  75. title: "趋势榜 - 全部时间",
  76. },
  77. ],
  78. },
  79. {
  80. title: "流派榜单",
  81. data: [
  82. {
  83. id: "89f0089f-1bfe-4713-8070-5830a6161afb",
  84. type: "playlist",
  85. title: "爵士",
  86. },
  87. {
  88. id: "935deb12-dc32-4005-a1fe-3c00c284ca52",
  89. type: "playlist",
  90. title: "乡村",
  91. },
  92. {
  93. id: "6028ad08-68cb-406d-aa35-a4917b6467d6",
  94. type: "playlist",
  95. title: "流行",
  96. },
  97. {
  98. id: "d033aa6e-655e-45d0-8138-dc9a0dc6b3a6",
  99. type: "playlist",
  100. title: "摇滚",
  101. },
  102. ],
  103. },
  104. ];
  105. }
  106. async function getTopListDetail(topListItem) {
  107. if (topListItem.type === "playlist") {
  108. const res = (await axios_1.default.get(`https://www.udio.com/api/playlists?id=${topListItem.id}`, {
  109. headers,
  110. })).data;
  111. const songList = res.playlists[0].song_list.join(",");
  112. const songs = (await axios_1.default.get(`https://www.udio.com/api/songs?songIds=${songList}`, {
  113. headers,
  114. })).data.songs;
  115. return {
  116. isEnd: true,
  117. musicList: songs.map(formatMusicItem),
  118. };
  119. }
  120. else if (topListItem.type === "search") {
  121. const pageSize = 30;
  122. const data = `{"searchQuery":{"sort":"plays","searchTerm":""${topListItem.maxAgeInHours
  123. ? `,"maxAgeInHours": ${topListItem.maxAgeInHours}`
  124. : ""}},"pageParam":0,"pageSize":${pageSize}}`;
  125. const config = {
  126. method: "post",
  127. url: "https://www.udio.com/api/songs/search",
  128. headers: {
  129. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.0.0",
  130. host: "www.udio.com",
  131. },
  132. data: data,
  133. };
  134. const songs = (await (0, axios_1.default)(config)).data.data;
  135. return {
  136. isEnd: true,
  137. musicList: songs.map(formatMusicItem),
  138. };
  139. }
  140. }
  141. async function getLyric(musicItem) {
  142. return {
  143. rawLrc: musicItem.rawLrc
  144. };
  145. }
  146. module.exports = {
  147. platform: "udio",
  148. author: "猫头猫",
  149. version: "0.0.0",
  150. supportedSearchType: ["music"],
  151. srcUrl: "https://gitee.com/maotoumao/MusicFreePlugins/raw/v0.1/dist/udio/index.js",
  152. cacheControl: "no-cache",
  153. search,
  154. getMediaSource,
  155. getTopListDetail,
  156. getTopLists,
  157. getLyric
  158. };