Skip to content

Commit

Permalink
v4.0,新增云盘上传接口以及二维码登录相关接口和相关demo,升级部分接口加密方法 Binaryify#70 , Binaryify#121
Browse files Browse the repository at this point in the history
  • Loading branch information
Binaryify committed Jan 3, 2021
1 parent 77775b2 commit 75cb79f
Show file tree
Hide file tree
Showing 22 changed files with 543 additions and 195 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
static
docs
node_modules
node_modules
module_example
7 changes: 7 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# 更新日志
### 4.0.0 | 2021.1.03
- 新增云盘上传接口,新增二维码登录相关接口和相关demo(http://localhost:3000/qrlogin.html, http://localhost:3000/cloud.html),更新 d.ts

- 升级部分接口加密方法("linuxapi" 都替换到了"api")

- 更新 `login/status` 接口(返回字段和之前不一样)

### 3.47.5 | 2020.12.20
- 更新appver [#1060](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/1060)

Expand Down
73 changes: 56 additions & 17 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@
195. 关注歌手新歌
196. 关注歌手新MV
197. 歌手详情
198. 云盘上传
199. 二维码登录
200. 话题详情
201. 话题详情热门动态

## 安装

Expand Down Expand Up @@ -359,7 +363,7 @@ $ sudo docker run -d -p 3000:3000 netease-music-api

!> 部分接口如登录接口不能调用太频繁 , 否则可能会触发 503 错误或者 ip 高频错误 ,若需频繁调用 , 需要准备 IP 代理池 (更新:已加入缓存机制,但仍需注意).

!> 本项目仅供学习使用,请尊重版权,请勿利用此项目从事商业行为
!> 本项目仅供学习使用,请尊重版权,请勿利用此项目从事商业行为或进行破坏版权行为

!> 文档可能会有缓存 , 如果文档版本和 github 上的版本不一致,请清除缓存再查看

Expand Down Expand Up @@ -420,22 +424,34 @@ v3.30.0后支持手动传入cookie,登录接口返回内容新增 `cookie` 字
}
```
#### 3. 二维码登录
说明: 二维码登录涉及到3个接口
1. 二维码key生成接口
说明: 调用此接口可生成一个key
说明: 二维码登录涉及到3个接口,调用务必带上时间戳,防止缓存
##### 1. 二维码key生成接口

说明: 调用此接口可生成一个key

**接口地址 :** `/login/qr/key`
##### 2. 二维码生成接口
说明: 调用此接口传入上一个接口生成的key可生成二维码图片的base64和二维码信息,可使用base64展示图片,或者使用二维码信息内容自行使用第三方二维码生产库渲染二维码

必选参数: `key`,由第一个接口生成

可选参数: `qrimg` 传入后会额外返回二维码图片base64编码

**接口地址 :** `/login/qr/create`

**调用例子 :** `/login/qr/create?key=xxx`

2. 二维码生成接口
说明: 调用此接口传入上一个接口生成的key可生成二维码图片的base64和二维码信息,可使用base64展示图片,或者使用二维码信息内容自行使用第三方二维码生产库渲染二维码
可选参数: `qrimg` 传入后
**接口地址 :** `/login/qr/create`

##### 3. 二维码检测扫码状态接口
说明: 轮询此接口可获取二维码扫码状态,800为二维码过期,801为等待扫码,802为待确认,803为授权登录成功(803状态码下会返回cookies)

3. 二维码检测扫码状态接口
说明: 轮询此接口可获取二维码扫码状态,801为等待扫码,802为待确认,803为授权登陆成功
必选参数: `key`,由第一个接口生成

**接口地址 :** `/login/qr/check`

**调用例子 :** `/login/qr/check?key=xxx`

调用可参考项目文件例子`/public/qrlogin.html` (访问地址:http://localhost:3000/qrlogin.html)


#### 注意
Expand Down Expand Up @@ -640,7 +656,7 @@ signature:用户签名
**调用例子 :** `/user/update?gender=0&signature=测试签名&city=440300&nickname=binary&birthday=1525918298004&province=440000`

### 更新头像
说明 : 登录后调用此接口,使用`'Content-Type': 'multipart/form-data'`上传图片formData(name为'imgFile'),可更新头像(参考:https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/public/avatar_update.html)
说明 : 登录后调用此接口,使用`'Content-Type': 'multipart/form-data'`上传图片formData(name为'imgFile'),可更新头像(参考:https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/public/avatar_update.html),支持命令行调用,参考module_example目录下`avatar_upload.js`

**可选参数 :**

Expand Down Expand Up @@ -936,6 +952,21 @@ tags: 歌单标签

**调用例子 :** `/hot/topic?limit=30&offset=30`

### 获取话题详情

说明 : 调用此接口 , 可获取话题详情

**接口地址 :** `/topic/detail`

**调用例子 :** `/topic/detail?actid=111551188`
### 获取话题详情热门动态

说明 : 调用此接口 , 可获取话题详情热门动态

**接口地址 :** `/topic/detail/event/hot`

**调用例子 :** `/topic/detail/event/hot?actid=111551188`


### 云村热评
说明 : 登录后调用此接口 , 可获取云村热评
Expand Down Expand Up @@ -1238,10 +1269,6 @@ mp3url 不能直接用 , 可通过 `/song/url` 接口传入歌曲 id 获取具

**调用例子 :** `/search?keywords= 海阔天空` `/cloudsearch?keywords= 海阔天空`

返回数据如下图 :
![搜索音乐](https://raw.githubusercontent.com/Binaryify/NeteaseCloudMusicApi/master/static/%E6%90%9C%E7%B4%A2.png)


### 默认搜索关键词
说明 : 调用此接口 , 可获取默认搜索关键词

Expand Down Expand Up @@ -1443,8 +1470,7 @@ mp3url 不能直接用 , 可通过 `/song/url` 接口传入歌曲 id 获取具

### 歌曲评论

说明 : 调用此接口 , 传入音乐 id 和 limit 参数 , 可获得该音乐的所有评论 ( 不需要
登录 )
说明 : 调用此接口 , 传入音乐 id 和 limit 参数 , 可获得该音乐的所有评论 ( 不需要登录 )

**必选参数 :** `id`: 音乐 id

Expand Down Expand Up @@ -2553,6 +2579,19 @@ type : 地区

**调用例子 :** `/user/cloud/del`

### 云盘上传
说明 : 登录后调用此接口,使用`'Content-Type': 'multipart/form-data'`上传mp3 formData(name为'songFile'),可上传歌曲到云盘

参考: https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/public/cloud.html

访问地址: http://localhost:3000/qrlogin.html)

支持命令行调用,参考module_example目录下`song_upload.js`

**接口地址 :** `/cloud`

**调用例子 :** `/cloud`

### 电台banner
说明 : 调用此接口,可获取电台banner

Expand Down
29 changes: 29 additions & 0 deletions interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1360,3 +1360,32 @@ export function artist_detail(
id: number | string
} & RequestBaseConfig,
): Promise<Response>

export function cloud(params: RequestBaseConfig): Promise<Response>

export function topic_detail(
params: {
actid?: number | string
} & RequestBaseConfig,
): Promise<Response>

export function topic_detail_event_hot(
params: {
actid?: number | string
} & RequestBaseConfig,
): Promise<Response>

export function login_qr_key(params: RequestBaseConfig): Promise<Response>

export function login_qr_create(
params: {
key?: number | string
qrimg?: boolean | string
} & RequestBaseConfig,
): Promise<Response>

export function login_qr_check(
params: {
key?: number | string
} & RequestBaseConfig,
): Promise<Response>
2 changes: 1 addition & 1 deletion module/banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ module.exports = (query, request) => {
'POST',
`https://music.163.com/api/v2/banner/get`,
{ clientType: type },
{ crypto: 'linuxapi', proxy: query.proxy, realIP: query.realIP },
{ crypto: 'api', proxy: query.proxy, realIP: query.realIP },
)
}
132 changes: 132 additions & 0 deletions module/cloud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
const mm = require('music-metadata')
const uploadPlugin = require('../plugins/songUpload')
const md5 = require('md5')
module.exports = async (query, request) => {
query.cookie.os = 'pc'
query.cookie.appver = '2.7.1.198277'
const bitrate = 999000
if (!query.songFile) {
return Promise.reject({
status: 500,
body: {
msg: '请上传音乐文件',
code: 500,
},
})
}
if (!query.songFile.md5) {
// 命令行上传没有md5和size信息,需要填充
query.songFile.md5 = md5(query.songFile.data)
query.songFile.size = query.songFile.data.byteLength
}
const res = await request(
'POST',
`https://interface.music.163.com/api/cloud/upload/check`,
{
bitrate: String(bitrate),
ext: '',
length: query.songFile.size,
md5: query.songFile.md5,
songId: '0',
version: 1,
},
{
crypto: 'weapi',
cookie: query.cookie,
proxy: query.proxy,
realIP: query.realIP,
},
)
let artist = ''
let album = ''
let songName = ''
try {
const metadata = await mm.parseBuffer(query.songFile.data, 'audio/mpeg')
if (metadata.native.ID3v1) {
metadata.native.ID3v1.forEach((item) => {
// console.log(item.id, item.value)
if (item.id === 'title') {
songName = item.value
}
if (item.id === 'artist') {
artist = item.value
}
if (item.id === 'album') {
album = item.value
}
})
// console.log({
// songName,
// album,
// songName,
// })
}
} catch (error) {
console.log(error)
}
const tokenRes = await request(
'POST',
`https://music.163.com/weapi/nos/token/alloc`,
{
bucket: '',
ext: 'mp3',
filename: query.songFile.name.replace('.mp3', ''),
local: false,
nos_product: 3,
type: 'audio',
md5: query.songFile.md5,
},
{ crypto: 'weapi', cookie: query.cookie, proxy: query.proxy },
)

if (res.body.needUpload) {
const uploadInfo = await uploadPlugin(query, request)
// console.log('uploadInfo', uploadInfo.body.result.resourceId)
}
// console.log(tokenRes.body.result)
const res2 = await request(
'POST',
`https://music.163.com/api/upload/cloud/info/v2`,
{
md5: query.songFile.md5,
songid: res.body.songId,
filename: query.songFile.name,
song: songName || query.songFile.name.replace('.mp3', ''),
album: album || '未知专辑',
artist: artist || '未知艺术家',
bitrate: String(bitrate),
resourceId: tokenRes.body.result.resourceId,
},
{
crypto: 'weapi',
cookie: query.cookie,
proxy: query.proxy,
realIP: query.realIP,
},
)
// console.log({ res2, privateCloud: res2.body.privateCloud })
// console.log(res.body.songId, 'songid')
const res3 = await request(
'POST',
`https://interface.music.163.com/api/cloud/pub/v2`,
{
songid: res2.body.songId,
},
{
crypto: 'weapi',
cookie: query.cookie,
proxy: query.proxy,
realIP: query.realIP,
},
)
// console.log({ res3 })
return {
status: 200,
body: {
...res.body,
...res3.body,
// ...uploadInfo,
},
cookie: res.cookie,
}
}
2 changes: 1 addition & 1 deletion module/hot_topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (query, request) => {
limit: query.limit || 20,
offset: query.offset || 0,
}
return request('POST', `https://music.163.com/weapi/act/hot`, data, {
return request('POST', `https://music.163.com/api/act/hot`, data, {
crypto: 'weapi',
cookie: query.cookie,
proxy: query.proxy,
Expand Down
6 changes: 2 additions & 4 deletions module/login_qr_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ module.exports = async (query, request) => {
return {
status: 200,
body: {
data: {
...result.body,
code: 200,
},
data: result.body,
code: 200,
},
cookie: result.cookie,
}
Expand Down
2 changes: 1 addition & 1 deletion module/lyric.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (query, request) => {
tv: -1,
}
return request('POST', `https://music.163.com/api/song/lyric`, data, {
crypto: 'linuxapi',
crypto: 'api',
cookie: query.cookie,
proxy: query.proxy,
realIP: query.realIP,
Expand Down
2 changes: 1 addition & 1 deletion module/playlist_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (query, request) => {
s: query.s || 8,
}
return request('POST', `https://music.163.com/api/v6/playlist/detail`, data, {
crypto: 'linuxapi',
crypto: 'api',
cookie: query.cookie,
proxy: query.proxy,
realIP: query.realIP,
Expand Down
11 changes: 11 additions & 0 deletions module/topic_detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = (query, request) => {
const data = {
actid: query.actid,
}
return request('POST', `https://music.163.com/api/act/detail`, data, {
crypto: 'weapi',
cookie: query.cookie,
proxy: query.proxy,
realIP: query.realIP,
})
}
11 changes: 11 additions & 0 deletions module/topic_detail_event_hot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = (query, request) => {
const data = {
actid: query.actid,
}
return request('POST', `https://music.163.com/api/act/event/hot`, data, {
crypto: 'weapi',
cookie: query.cookie,
proxy: query.proxy,
realIP: query.realIP,
})
}
Loading

0 comments on commit 75cb79f

Please sign in to comment.