forked from nondanee/UnblockNeteaseMusic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const cache = require('../cache') | ||
const insure = require('./insure') | ||
const select = require('./select') | ||
const request = require('../request') | ||
|
||
const format = song => { | ||
return { | ||
id: song.id, | ||
name: song.title, | ||
// album: {id: song.album_id, name: song.album_title}, | ||
artists: {id: song.mid, name: song.author} | ||
} | ||
} | ||
|
||
const search = info => { | ||
const url = | ||
'https://api.bilibili.com/audio/music-service-c/s?' + | ||
'search_type=music&page=1&pagesize=30&' + | ||
`keyword=${encodeURIComponent(info.keyword)}` | ||
return request('GET', url) | ||
.then(response => response.json()) | ||
.then(jsonBody => { | ||
const list = jsonBody.data.result.map(format) | ||
const matched = select(list, info) | ||
return matched ? matched.id : Promise.reject() | ||
}) | ||
} | ||
|
||
const track = id => { | ||
// weburl | ||
const url = | ||
'https://www.bilibili.com/audio/music-service-c/web/url?rivilege=2&quality=2&' + | ||
'sid=' + id | ||
|
||
return request('GET', url) | ||
.then(response => response.json()) | ||
.then(jsonBody => { | ||
if (jsonBody.code === 0) { | ||
// bb music require referer, connect do not support referer, so change to http | ||
return jsonBody.data.cdns[0].replace("https","http") | ||
} else { | ||
return Promise.reject() | ||
} | ||
}) | ||
.catch(() => insure().bilibili.track(id)) | ||
} | ||
|
||
const check = info => cache(search, info).then(track) | ||
|
||
module.exports = {check, track} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters