forked from nondanee/UnblockNeteaseMusic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetease.js
29 lines (24 loc) · 786 Bytes
/
netease.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
const cache = require('../cache')
const crypto = require('../crypto')
const request = require('../request')
const search = info => {
let url =
'http://music.163.com/api/album/' + info.album.id
return request('GET', url)
.then(response => response.body())
.then(body => {
let jsonBody = JSON.parse(body.replace(/"dfsId":(\d+)/g, '"dfsId":"$1"')) // for js precision
let matched = jsonBody.album.songs.find(song => song.id === info.id)
if(matched)
return matched.hMusic.dfsId || matched.mMusic.dfsId || matched.lMusic.dfsId
else
return Promise.reject()
})
}
const track = id => {
if(!id || id === '0') return Promise.reject()
let songUrl = crypto.uri.retrieve(id)
return songUrl
}
const check = info => cache(search, info).then(track)
module.exports = {check}