forked from xlzy520/wx-qq-music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsong.js
54 lines (50 loc) · 1.22 KB
/
song.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function Song({id, mid, singer, name, album, duration, image, musicId}) {
this.id = id
this.mid = mid
this.singer = singer
this.name = name
this.album = album
this.duration = duration
this.image = image
this.musicId = musicId
}
function createSong(musicData) {
return new Song({
id: musicData.songid,
mid: musicData.songmid,
singer: filterSinger(musicData.singer),
name: musicData.songname,
album: musicData.albumname,
duration: musicData.interval,
image: `https://y.gtimg.cn/music/photo_new/T002R300x300M000${musicData.albummid}.jpg?max_age=2592000`,
musicId: musicData.songid
})
}
function filterSinger(singer) {
let ret = []
if (!singer) {
return ''
}
singer.forEach((s) => {
ret.push(s.name)
})
return ret.join('/')
}
function getLyric(musicid) {
return new Promise((resolve, reject)=>{
wx.request({
url: `https://route.showapi.com/213-2?showapi_appid=54411&musicid=${musicid}&showapi_sign=55b7ca99e210452a86269a9f09def34c`,
success: function (res) {
resolve(res)
},
fail: function (res) {
reject(res)
}
})
})
}
module.exports = {
createSong: createSong,
getLyric: getLyric,
filterSinger: filterSinger
}