酷狗.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. function kugou(packages) {
  2. const { axios } = packages;
  3. const pageSize = 20;
  4. function formatMusicItem(_) {
  5. return {
  6. id: _.hash,
  7. title: _.songname,
  8. artist: _.singername,
  9. album: _.album_name,
  10. album_id: _.album_id,
  11. album_audio_id: _.album_audio_id
  12. }
  13. }
  14. const headers = {
  15. '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',
  16. 'Accept': '*/*',
  17. 'Accept-Encoding': 'gzip, deflate',
  18. 'Accept-Language': 'zh-CN,zh;q=0.9',
  19. }
  20. async function searchMusic(query, page) {
  21. const res = (await axios.get('http://mobilecdn.kugou.com/api/v3/search/song', {
  22. headers,
  23. params: {
  24. format: 'json',
  25. keyword: query,
  26. page,
  27. pagesize: pageSize,
  28. showtype: 1,
  29. }
  30. })).data;
  31. const songs = res.data.info.filter(_ => _.privilege === 0 || _.privilege === 8).map(formatMusicItem);
  32. return {
  33. isEnd: page * pageSize >= res.data.total,
  34. data: songs
  35. }
  36. }
  37. async function getMediaSource(musicItem) {
  38. const res = (await axios.get('https://wwwapi.kugou.com/yy/index.php', {
  39. headers,
  40. params: {
  41. r: 'play/getdata',
  42. hash: musicItem.id,
  43. appid: '1014',
  44. mid: '56bbbd2918b95d6975f420f96c5c29bb',
  45. album_id: musicItem.album_id,
  46. album_audio_id: musicItem.album_audio_id,
  47. _: Date.now()
  48. }
  49. })).data.data;
  50. return {
  51. url: res.play_url || res.play_backup_url,
  52. rawLrc: res.lyrics,
  53. artwork: res.img
  54. };
  55. }
  56. return {
  57. platform: '酷狗',
  58. version: '0.0.0',
  59. srcUrl: 'https://gitee.com/maotoumao/MusicFreePlugins/raw/master/kugou.js',
  60. cacheControl: 'no-cache',
  61. primaryKey: ['id', 'album_id', 'album_audio_id'],
  62. async search(query, page, type) {
  63. if (type === 'music') {
  64. return await searchMusic(query, page);
  65. }
  66. },
  67. getMediaSource,
  68. getLyric: getMediaSource,
  69. }
  70. }