新增网易云源歌曲搜索

This commit is contained in:
lyswhut
2019-10-16 10:38:42 +08:00
parent e675f7ac06
commit 1cbafc9750
6 changed files with 160 additions and 62 deletions
+2
View File
@@ -2,9 +2,11 @@ import leaderboard from './leaderboard'
import api_source from '../api-source'
import getLyric from './lyric'
import getMusicInfo from './musicInfo'
import musicSearch from './musicSearch'
const wy = {
leaderboard,
musicSearch,
getMusicUrl(songInfo, type) {
return api_source('wy').getMusicUrl(songInfo, type)
},
+3 -9
View File
@@ -1,22 +1,16 @@
// https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/module/lyric.js
import { httpFetch } from '../../request'
import { linuxapi } from './utils/crypto'
import { weapi } from './utils/crypto'
export default songmid => {
const requestObj = httpFetch('https://music.163.com/api/linux/forward', {
const requestObj = httpFetch('http://music.163.com/weapi/song/lyric?csrf_token=', {
method: 'post',
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
Referer: 'https://music.163.com/song?id=' + songmid,
origin: 'https://music.163.com',
},
form: linuxapi({
method: 'POST',
url: 'https://music.163.com/api/song/lyric?lv=-1&kv=-1&tv=-1',
params: {
id: songmid,
},
}),
form: weapi({ id: songmid, lv: -1, tv: -1, csrf_token: '' }),
})
requestObj.promise = requestObj.promise.then(({ body }) => {
// console.log(body)
@@ -0,0 +1,98 @@
import { httpFetch } from '../../request'
import { weapi } from './utils/crypto'
import { sizeFormate, formatPlayTime } from '../../index'
let searchRequest
export default {
limit: 30,
total: 0,
page: 0,
allPage: 1,
musicSearch(str, page) {
if (searchRequest && searchRequest.cancelHttp) searchRequest.cancelHttp()
searchRequest = httpFetch('http://music.163.com/weapi/cloudsearch/get/web?csrf_token=', {
method: 'post',
form: weapi({
s: str,
type: 1, // 1: 单曲, 10: 专辑, 100: 歌手, 1000: 歌单, 1002: 用户, 1004: MV, 1006: 歌词, 1009: 电台, 1014: 视频
limit: this.limit,
offset: this.limit * (page - 1),
}),
})
return searchRequest.promise.then(({ body }) => body)
},
getSinger(singers) {
let arr = []
singers.forEach(singer => {
arr.push(singer.name)
})
return arr.join('、')
},
handleResult(rawList) {
// console.log(rawList)
return rawList.map(item => {
const types = []
const _types = {}
let size
switch (item.privilege.maxbr) {
case 999000:
size = null
types.push({ type: 'flac', size })
_types.flac = {
size,
}
case 320000:
size = sizeFormate(item.h.size)
types.push({ type: '320k', size })
_types['320k'] = {
size,
}
case 128000:
size = sizeFormate(item.l.size)
types.push({ type: '128k', size })
_types['128k'] = {
size,
}
}
types.reverse()
return {
singer: this.getSinger(item.ar),
name: item.name,
albumName: item.al.name,
albumId: item.al.id,
source: 'wy',
interval: formatPlayTime(item.dt / 1000),
songmid: item.id,
img: item.al.picUrl,
lrc: null,
types,
_types,
typeUrl: {},
}
})
},
search(str, page = 1, { limit } = {}) {
if (limit != null) this.limit = limit
return this.musicSearch(str, page).then(result => {
// console.log(JSON.stringify(result))
if (!result || result.code !== 200) return this.search(str, page, { limit })
let list = this.handleResult(result.result.songs)
if (list == null) return this.search(str, page, { limit })
this.total = result.result.songCount
this.page = page
this.allPage = Math.ceil(this.total / this.limit)
return Promise.resolve({
list,
allPage: this.allPage,
limit: this.limit,
total: this.total,
source: 'wy',
})
})
},
}