diff --git a/README.md b/README.md index fe8bf51..9e07df4 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,13 @@ Meting后端的基础是一个[接口](https://github.com/metowolf/Meting/blob/m ## 进度 -| | server参数名称 | 图片 | 歌词 | url | 单曲/song | 歌单/playlist | 歌手/artist | -| ------------- | -------------- | ---- | ---- | --- | --------- | ------------- | ----------- | -| 网易云 | netease | √ | √ | √ | √ | √ | √ | -| qq音乐 | tencent | √ | √ | √ | √ | √ | × | -| youtube music | ytmusic | √ | √⁰ | √ | √ | √ | × | -| spotify | spotify | √ | √⁰ | √⁰ | √⁰ | √⁰ | × | -| more.. | | | | | | | | +| | server参数名称 | 图片 | 歌词 | url | 单曲/song | 歌单/playlist | 歌手/artist | 搜索/search | +| ------------- | -------------- | ---- | ---- | --- | --------- | ------------- | ----------- |--------- | +| 网易云 | netease | √ | √ | √ | √ | √ | √ |√ | +| qq音乐 | tencent | √ | √ | √ | √ | √ | × |× | +| youtube music | ytmusic | √ | √⁰ | √ | √ | √ | × |× | +| spotify | spotify | √ | √⁰ | √⁰ | √⁰ | √⁰ | × |× | +| more.. | | | | | | | | | ## 地区限制 diff --git a/src/example.js b/src/example.js index f72f3a9..f86bc94 100644 --- a/src/example.js +++ b/src/example.js @@ -12,6 +12,7 @@ export default { "artist": { "show": true, "value": "12441107" }, "lrc": { "show": false, "value": "2015217630" }, "url": { "show": false, "value": "473403185" }, + "search": { "show": true, "value": "KN33S0XXX" }, }, "ytmusic": { "playlist": { "show": true, "value": "RDCLAK5uy_l12ynH8dyLsBmE11ToAHLm9P04NS2i9ME" }, diff --git a/src/providers/netease/index.js b/src/providers/netease/index.js index 7a5b2f4..6b7c2a9 100644 --- a/src/providers/netease/index.js +++ b/src/providers/netease/index.js @@ -2,8 +2,9 @@ import { get_playlist } from "./playlist.js" import { get_song_url, get_song_info } from "./song.js" import { get_lyric } from "./lyric.js" import { get_artist_songs } from "./artist_songs.js" +import { get_search_songs } from "./search.js" -const support_type = ['url', 'lrc', 'song', 'playlist', 'artist'] +const support_type = ['url', 'lrc', 'song', 'playlist', 'artist', 'search', 'pic'] const handle = async (type, id, cookie = '') => { let result; @@ -14,6 +15,9 @@ const handle = async (type, id, cookie = '') => { case 'url': result = await get_song_url(id) break + case 'pic': + result = (await get_song_info(id))[0].pic + break case 'song': result = await get_song_info(id) break @@ -23,6 +27,9 @@ const handle = async (type, id, cookie = '') => { case 'artist': result = await get_artist_songs(id) break + case 'search': + result = await get_search_songs(id) + break default: return -1; } diff --git a/src/providers/netease/search.js b/src/providers/netease/search.js new file mode 100644 index 0000000..4ebbdcf --- /dev/null +++ b/src/providers/netease/search.js @@ -0,0 +1,25 @@ +import { request } from "./util.js" +import { map_song_list } from "./util.js" + +export const get_search_songs = async (id, cookie) => { + + const data = { + s: id, + type: 1, // 1: 单曲, 10: 专辑, 100: 歌手, 1000: 歌单, 1002: 用户, 1004: MV, 1006: 歌词, 1009: 电台, 1014: 视频 + limit: 30, + offset: 0, + total: true, + } + + const res = await request('POST', `https://interface.music.163.com/eapi/cloudsearch`, data, { + crypto: 'eapi', + cookie: {}, + url: '/api/cloudsearch/pc' + }) + + return map_song_list(res.result) + +} + +// const res = await get_search_songs("KN33S0XXX"); +// console.log(res) diff --git a/src/providers/netease/util.js b/src/providers/netease/util.js index 418baa0..ee2a817 100644 --- a/src/providers/netease/util.js +++ b/src/providers/netease/util.js @@ -182,11 +182,14 @@ export const request = async (method, url, data = {}, options) => { } export const map_song_list = (song_list) => { - return song_list.songs.map(song => ({ - title: song.name, - author: song.ar.reduce((i, v) => ((i ? i + " / " : i) + v.name), ''), - pic: song.al.picUrl, - url: song.id, - lrc: song.id - })) -} \ No newline at end of file + return song_list.songs.map(song => { + const artists = song.ar || song.artists + return { + title: song.name, + author: artists.reduce((i, v) => ((i ? i + " / " : i) + v.name), ''), + pic: song?.al?.picUrl || song.id, + url: song.id, + lrc: song.id + } + }) +}