提交 82b2e583 编写于 作者: B binaryify

修复文档描述错误,调整歌单详情接口

上级 f26c71ef
......@@ -276,7 +276,7 @@ $ set PORT=4000 && node app.js
`/top/playlist/highquality`
**调用例子:**
`/playlist/detail?id=24381616`
`/top/playlist/highquality?limit=30`
### 获取歌单详情
......
......@@ -23,8 +23,9 @@ router.get("/", (req, res) => {
cookie,
music_req => {
console.log(music_req)
detail = music_req
mergeRes()
// detail = music_req
res.send(music_req)
// mergeRes()
},
err => {
res.status(502).send('fetch error')
......@@ -33,34 +34,34 @@ router.get("/", (req, res) => {
// FIXME:i dont know the api to get coverimgurl
// so i get it by parsing html
const http_client = http.get({
hostname: 'music.163.com',
path: '/playlist?id=' + req.query.id,
headers: {
'Referer': 'http://music.163.com',
},
}, function (res) {
res.setEncoding('utf8')
let html = ''
res.on('data', function (chunk) {
html += chunk
})
res.on('end', function () {
console.log('end', html)
const regImgCover = /\<img src=\"(.*)\" class="j-img"/ig
imgurl = regImgCover.exec(html)[1]
mergeRes()
// const http_client = http.get({
// hostname: 'music.163.com',
// path: '/playlist?id=' + req.query.id,
// headers: {
// 'Referer': 'http://music.163.com',
// },
// }, function (res) {
// res.setEncoding('utf8')
// let html = ''
// res.on('data', function (chunk) {
// html += chunk
// })
// res.on('end', function () {
// console.log('end', html)
// const regImgCover = /\<img src=\"(.*)\" class="j-img"/ig
// imgurl = regImgCover.exec(html)[1]
// mergeRes()
})
})
// })
// })
function mergeRes() {
if (imgurl != undefined && detail != undefined) {
detail = JSON.parse(detail)
detail.playlist.picUrl = imgurl
res.send(detail)
}
}
// function mergeRes() {
// if (imgurl != undefined && detail != undefined) {
// detail = JSON.parse(detail)
// detail.playlist.picUrl = imgurl
// res.send(detail)
// }
// }
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册