index.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import axios from "axios";
  2. import he = require("he");
  3. const pageSize = 30;
  4. function validMusicFilter(_) {
  5. return `${_.pay_type}` === "0";
  6. }
  7. function formatMusicItem(_) {
  8. return {
  9. id: _.id,
  10. artwork: _.front_cover,
  11. title: _.soundstr,
  12. artist: _.username,
  13. user_id: _.user_id,
  14. duration: +(_.duration ?? 0),
  15. };
  16. }
  17. function formatAlbumItem(_) {
  18. return {
  19. id: _.id,
  20. artist: _.author,
  21. title: _.name,
  22. artwork: _.cover,
  23. description: _.abstract,
  24. };
  25. }
  26. const searchHeaders = {
  27. "user-agent":
  28. "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",
  29. accept: "application/json",
  30. "accept-encoding": "gzip, deflate, br",
  31. referer: "https://www.missevan.com/sound/search",
  32. };
  33. async function searchMusic(query, page) {
  34. const res = (
  35. await axios.get("https://www.missevan.com/sound/getsearch", {
  36. params: {
  37. s: query,
  38. p: page,
  39. type: 3,
  40. page_size: pageSize,
  41. },
  42. headers: searchHeaders,
  43. })
  44. ).data.info;
  45. return {
  46. isEnd: res.pagination.p >= res.pagination.maxpage,
  47. data: res.Datas.filter(validMusicFilter).map(formatMusicItem),
  48. };
  49. }
  50. async function searchAlbum(query, page) {
  51. const res = (
  52. await axios.get("https://www.missevan.com/dramaapi/search", {
  53. headers: searchHeaders,
  54. params: {
  55. s: query,
  56. page,
  57. },
  58. })
  59. ).data.info;
  60. return {
  61. isEnd: res.pagination.p >= res.pagination.maxpage,
  62. data: res.Datas.filter(validMusicFilter).map(formatAlbumItem),
  63. };
  64. }
  65. async function getAlbumInfo(albumItem) {
  66. const res = (
  67. await axios.get("https://www.missevan.com/dramaapi/getdrama", {
  68. headers: {
  69. "user-agent":
  70. "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",
  71. accept: "application/json",
  72. "accept-encoding": "gzip, deflate, br",
  73. referer: `https://www.missevan.com/mdrama/${albumItem.id}`,
  74. },
  75. params: {
  76. drama_id: albumItem.id,
  77. },
  78. })
  79. ).data;
  80. return {
  81. musicList: res.info.episodes.episode
  82. .filter(validMusicFilter)
  83. .map(_ => {
  84. const r = formatMusicItem(_);
  85. r.artwork = albumItem.artwork;
  86. return r;
  87. }),
  88. };
  89. }
  90. async function getMediaSource(musicItem, quality: IMusic.IQualityKey) {
  91. if (quality === "high" || quality === "super") {
  92. return;
  93. }
  94. const res = (
  95. await axios.get("https://www.missevan.com/sound/getsound", {
  96. headers: {
  97. "user-agent":
  98. "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",
  99. accept: "application/json",
  100. "accept-encoding": "gzip, deflate, br",
  101. referer: `https://www.missevan.com/sound/player?id=${musicItem.id}`,
  102. },
  103. params: {
  104. soundid: musicItem.id,
  105. },
  106. })
  107. ).data.info;
  108. if (quality === "low") {
  109. return {
  110. url: res.sound.soundurl_128,
  111. };
  112. } else {
  113. return {
  114. url: res.sound.soundurl,
  115. };
  116. }
  117. }
  118. async function getRecommendSheetTags() {
  119. const res = (
  120. await axios.get(
  121. `https://www.missevan.com/malbum/recommand`,
  122. {
  123. headers: {
  124. "user-agent":
  125. "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",
  126. accept: "application/json",
  127. "accept-encoding": "gzip, deflate, br",
  128. referer: `https://www.missevan.com`,
  129. }
  130. }
  131. )
  132. ).data.info;
  133. const data = Object.entries(res ?? {}).map(group => ({
  134. title: group[0],
  135. data: (group[1] as any).map(_ => ({
  136. id: _[0],
  137. title: _[1]
  138. }))
  139. }));
  140. return {
  141. data,
  142. };
  143. }
  144. async function getRecommendSheetsByTag(tag, page) {
  145. const res = (
  146. await axios.get(
  147. `https://www.missevan.com/explore/tagalbum`,
  148. {
  149. headers: {
  150. "user-agent":
  151. "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",
  152. accept: "application/json",
  153. "accept-encoding": "gzip, deflate, br",
  154. referer: `https://m.missevan.com`,
  155. },
  156. params: {
  157. order: 0,
  158. tid: tag?.id || 0,
  159. p: page
  160. }
  161. }
  162. )
  163. ).data;
  164. return {
  165. isEnd: res.page >= res.maxpage,
  166. data: res.albums.map(sheet => ({
  167. id: sheet.id,
  168. title: sheet.title,
  169. artwork: sheet.front_cover,
  170. artist: sheet.username,
  171. createUserId: sheet.user_id
  172. }))
  173. }
  174. }
  175. async function getMusicSheetInfo(sheet: IMusicSheet.IMusicSheetItem, page) {
  176. const res = (
  177. await axios.get(
  178. `https://www.missevan.com/sound/soundalllist`,
  179. {
  180. headers: {
  181. "user-agent":
  182. "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",
  183. accept: "application/json",
  184. "accept-encoding": "gzip, deflate, br",
  185. referer: `https://m.missevan.com`,
  186. },
  187. params: {
  188. albumid: sheet.id
  189. }
  190. }
  191. )
  192. ).data.info;
  193. return {
  194. isEnd: true,
  195. musicList: res.sounds.filter(validMusicFilter).map(item => ({
  196. id: item.id,
  197. title: item.soundstr,
  198. artwork: item.front_cover,
  199. url: item.soundurl,
  200. artist: item.username,
  201. }))
  202. }
  203. }
  204. module.exports = {
  205. platform: "猫耳FM",
  206. author: '猫头猫',
  207. version: "0.1.4",
  208. appVersion: ">0.1.0-alpha.0",
  209. srcUrl:
  210. "https://gitee.com/maotoumao/MusicFreePlugins/raw/v0.1/dist/maoerfm/index.js",
  211. cacheControl: "no-cache",
  212. supportedSearchType: ["music", "album", ],
  213. async search(query, page, type) {
  214. if (type === "music") {
  215. return await searchMusic(query, page);
  216. }
  217. if (type === "album") {
  218. return await searchAlbum(query, page);
  219. }
  220. },
  221. getMediaSource,
  222. getAlbumInfo,
  223. getRecommendSheetTags,
  224. getRecommendSheetsByTag,
  225. getMusicSheetInfo
  226. };