Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_47285076
NeteaseCloudMusicApi_nicole-n
提交
0d373be6
N
NeteaseCloudMusicApi_nicole-n
项目概览
weixin_47285076
/
NeteaseCloudMusicApi_nicole-n
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
NeteaseCloudMusicApi_nicole-n
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0d373be6
编写于
9月 25, 2018
作者:
N
Nzix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rewrite unit tests
上级
a26ab583
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
123 addition
and
165 deletion
+123
-165
app.js
app.js
+1
-1
app.test.js
app.test.js
+16
-0
package.json
package.json
+1
-1
test/album.test.js
test/album.test.js
+15
-10
test/comment.test.js
test/comment.test.js
+14
-23
test/login.test.js
test/login.test.js
+19
-33
test/lyric.test.js
test/lyric.test.js
+19
-22
test/musicUrl.test.js
test/musicUrl.test.js
+0
-33
test/music_url.test.js
test/music_url.test.js
+23
-0
test/search.test.js
test/search.test.js
+14
-14
util/util.js
util/util.js
+1
-28
未找到文件。
app.js
浏览文件 @
0d373be6
...
@@ -99,7 +99,7 @@ fs.readdirSync(path.resolve(__dirname, 'router'))
...
@@ -99,7 +99,7 @@ fs.readdirSync(path.resolve(__dirname, 'router'))
const
port
=
process
.
env
.
PORT
||
3000
const
port
=
process
.
env
.
PORT
||
3000
app
.
listen
(
port
,
()
=>
{
app
.
server
=
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`server running @ http://localhost:
${
port
}
`
)
console
.
log
(
`server running @ http://localhost:
${
port
}
`
)
})
})
...
...
app.test.js
0 → 100644
浏览文件 @
0d373be6
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
let
app
before
(()
=>
{
app
=
require
(
'
./app.js
'
)
global
.
host
=
'
http://localhost:
'
+
app
.
server
.
address
().
port
})
after
((
done
)
=>
{
app
.
server
.
close
(
done
)
})
fs
.
readdirSync
(
path
.
resolve
(
__dirname
,
'
test
'
))
.
forEach
(
file
=>
{
require
(
'
./test/
'
+
file
)
})
\ No newline at end of file
package.json
浏览文件 @
0d373be6
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
"description"
:
"网易云音乐 NodeJS 版 API"
,
"description"
:
"网易云音乐 NodeJS 版 API"
,
"scripts"
:
{
"scripts"
:
{
"start"
:
"node app.js"
,
"start"
:
"node app.js"
,
"test"
:
"mocha -r intelli-espower-loader -t 20000
tes
t"
"test"
:
"mocha -r intelli-espower-loader -t 20000
app.test.js --exi
t"
},
},
"keywords"
:
[
"keywords"
:
[
"网易云音乐"
,
"网易云音乐"
,
...
...
test/album.test.js
浏览文件 @
0d373be6
const
assert
=
require
(
'
assert
'
)
const
assert
=
require
(
'
assert
'
)
const
crypto
=
require
(
'
crypto
'
)
const
request
=
require
(
'
request
'
)
const
{
createRequest
}
=
require
(
'
../util/util
'
)
host
=
global
.
host
||
'
http://localhost:3000
'
describe
(
'
测试获取歌手专辑列表是否正常
'
,
()
=>
{
describe
(
'
测试获取歌手专辑列表是否正常
'
,
()
=>
{
it
(
'
数据的 code 应该为200
'
,
done
=>
{
it
(
'
数据的 code 应该为200
'
,
done
=>
{
const
id
=
32311
const
qs
=
{
createRequest
(
`/api/album/
${
id
}
`
,
'
GET
'
,
null
)
id
:
32311
.
then
(
result
=>
{
}
const
code
=
JSON
.
parse
(
result
).
code
console
.
log
(
'
code:
'
+
code
)
request
.
get
({
url
:
`
${
host
}
/album`
,
qs
:
qs
},
(
err
,
res
,
body
)
=>
{
assert
(
code
===
200
)
if
(
!
err
&&
res
.
statusCode
==
200
)
{
body
=
JSON
.
parse
(
body
)
assert
(
body
.
code
===
200
)
done
()
done
()
}
else
{
done
(
err
)
}
})
})
.
catch
(
err
=>
done
(
err
))
})
})
})
})
test/comment.test.js
浏览文件 @
0d373be6
const
assert
=
require
(
'
assert
'
)
const
assert
=
require
(
'
assert
'
)
const
crypto
=
require
(
'
crypto
'
)
const
request
=
require
(
'
request
'
)
const
{
createWebAPIRequest
}
=
require
(
'
../util/util
'
)
host
=
global
.
host
||
'
http://localhost:3000
'
describe
(
'
测试获取评论是否正常
'
,
()
=>
{
describe
(
'
测试获取评论是否正常
'
,
()
=>
{
it
(
'
数据的 code 应该为200
'
,
done
=>
{
it
(
'
数据的 code 应该为200
'
,
done
=>
{
const
rid
=
32311
const
qs
=
{
const
cookie
=
''
id
:
32311
const
data
=
{
offset
:
0
,
rid
:
rid
,
limit
:
20
,
csrf_token
:
''
}
}
createWebAPIRequest
(
'
music.163.com
'
,
request
.
get
({
url
:
`
${
host
}
/comment/album`
,
qs
:
qs
},
(
err
,
res
,
body
)
=>
{
`/weapi/v1/resource/comments/R_SO_4_
${
rid
}
/?csrf_token=`
,
if
(
!
err
&&
res
.
statusCode
==
200
)
{
'
POST
'
,
body
=
JSON
.
parse
(
body
)
data
,
assert
(
body
.
code
===
200
)
cookie
,
music_req
=>
{
console
.
log
({
code
:
JSON
.
parse
(
music_req
).
code
})
assert
(
JSON
.
parse
(
music_req
).
code
===
200
)
done
()
done
()
},
}
err
=>
done
(
err
)
else
{
)
done
(
err
)
}
})
})
})
})
})
test/login.test.js
浏览文件 @
0d373be6
const
assert
=
require
(
"
assert
"
);
const
assert
=
require
(
'
assert
'
)
const
crypto
=
require
(
"
crypto
"
);
const
request
=
require
(
'
request
'
)
const
{
createWebAPIRequest
}
=
require
(
"
../util/util
"
);
host
=
global
.
host
||
'
http://localhost:3000
'
console
.
log
(
"
注意:
测试登陆需要替换这里的
账号密码!!!
"
);
console
.
log
(
"
注意:
测试登录需在 test/login.test.js 中填写
账号密码!!!
"
);
describe
(
"
测试登录是否正常
"
,
()
=>
{
describe
(
"
测试登录是否正常
"
,
()
=>
{
it
(
"
手机登录 code 应该等于200
"
,
done
=>
{
it
(
"
手机登录 code 应该等于200
"
,
done
=>
{
const
phone
=
"
换成你的手机号
"
;
const
qs
=
{
const
password
=
"
换成你的密码
"
;
let
cookie
=
""
;
const
md5sum
=
crypto
.
createHash
(
"
md5
"
);
md5sum
.
update
(
password
);
const
data
=
{
phone
:
phone
,
phone
:
phone
,
password
:
md5sum
.
digest
(
"
hex
"
),
password
:
password
rememberLogin
:
"
true
"
}
};
createWebAPIRequest
(
request
.
get
({
url
:
`
${
host
}
/login/cellphone`
,
qs
:
qs
},
(
err
,
res
,
body
)
=>
{
"
music.163.com
"
,
if
(
!
err
&&
res
.
statusCode
==
200
)
{
"
/weapi/login/cellphone
"
,
body
=
JSON
.
parse
(
body
)
"
POST
"
,
assert
(
body
.
code
===
200
)
data
,
done
()
cookie
,
}
(
music_req
,
cookie
)
=>
{
else
{
const
result
=
JSON
.
parse
(
music_req
);
done
(
err
)
console
.
log
({
}
loginType
:
result
.
loginType
,
})
code
:
result
.
code
,
})
account
:
result
.
account
})
});
assert
(
result
.
code
===
200
);
done
();
},
err
=>
done
(
err
)
);
});
});
test/lyric.test.js
浏览文件 @
0d373be6
const
assert
=
require
(
"
assert
"
);
const
assert
=
require
(
'
assert
'
)
const
crypto
=
require
(
"
crypto
"
);
const
request
=
require
(
'
request
'
)
const
{
createWebAPIRequest
}
=
require
(
"
../util/util
"
);
host
=
global
.
host
||
'
http://localhost:3000
'
describe
(
"
测试获取歌词是否正常
"
,
()
=>
{
describe
(
"
测试获取歌词是否正常
"
,
()
=>
{
it
(
"
数据应该有 lrc 字段
"
,
done
=>
{
it
(
"
数据应该有 lrc 字段
"
,
done
=>
{
const
cookie
=
""
;
const
qs
=
{
const
data
=
{};
id
:
347230
const
id
=
347230
;
}
createWebAPIRequest
(
"
music.163.com
"
,
request
.
get
({
url
:
`
${
host
}
/lyric`
,
qs
:
qs
},
(
err
,
res
,
body
)
=>
{
"
/weapi/song/lyric?os=osx&id=
"
+
id
+
"
&lv=-1&kv=-1&tv=-1
"
,
if
(
!
err
&&
res
.
statusCode
==
200
)
{
"
POST
"
,
body
=
JSON
.
parse
(
body
)
data
,
assert
(
typeof
body
.
lrc
!==
"
undefined
"
)
cookie
,
done
()
music_req
=>
{
}
console
.
log
(
music_req
);
else
{
assert
(
typeof
JSON
.
parse
(
music_req
).
lrc
!==
"
undefined
"
);
done
(
err
)
done
();
}
// res.send(music_req)
})
},
})
err
=>
res
.
status
(
502
).
send
(
"
fetch error
"
)
})
);
});
});
test/musicUrl.test.js
已删除
100644 → 0
浏览文件 @
a26ab583
const
assert
=
require
(
"
assert
"
);
const
crypto
=
require
(
"
crypto
"
);
const
{
createWebAPIRequest
}
=
require
(
"
../util/util
"
);
describe
(
"
测试获取歌曲是否正常
"
,
()
=>
{
it
(
"
歌曲的 url 不应该为空
"
,
done
=>
{
const
id
=
462791935
;
const
br
=
999000
;
const
data
=
{
ids
:
[
id
],
br
:
br
,
csrf_token
:
""
};
const
cookie
=
""
;
createWebAPIRequest
(
"
music.163.com
"
,
"
/weapi/song/enhance/player/url
"
,
"
POST
"
,
data
,
cookie
,
music_req
=>
{
console
.
log
(
music_req
);
console
.
log
(
JSON
.
parse
(
music_req
).
data
[
0
].
url
);
assert
(
!!
JSON
.
parse
(
music_req
).
data
[
0
].
url
);
done
();
},
err
=>
{
done
(
err
);
}
);
});
});
test/music_url.test.js
0 → 100644
浏览文件 @
0d373be6
const
assert
=
require
(
'
assert
'
)
const
request
=
require
(
'
request
'
)
host
=
global
.
host
||
'
http://localhost:3000
'
describe
(
"
测试获取歌曲是否正常
"
,
()
=>
{
it
(
"
歌曲的 url 不应该为空
"
,
done
=>
{
const
qs
=
{
id
:
462791935
,
br
:
999000
}
request
.
get
({
url
:
`
${
host
}
/music/url`
,
qs
:
qs
},
(
err
,
res
,
body
)
=>
{
if
(
!
err
&&
res
.
statusCode
==
200
)
{
body
=
JSON
.
parse
(
body
)
assert
(
!!
body
.
data
[
0
].
url
)
done
()
}
else
{
done
(
err
)
}
})
});
});
test/search.test.js
浏览文件 @
0d373be6
const
assert
=
require
(
'
assert
'
)
const
assert
=
require
(
'
assert
'
)
const
crypto
=
require
(
'
crypto
'
)
const
request
=
require
(
'
request
'
)
const
{
createRequest
}
=
require
(
'
../util/util
'
)
host
=
global
.
host
||
'
http://localhost:3000
'
describe
(
'
测试搜索是否正常
'
,
()
=>
{
describe
(
'
测试搜索是否正常
'
,
()
=>
{
it
(
'
获取到的数据的 name 应该和搜索关键词一致
'
,
done
=>
{
it
(
'
获取到的数据的 name 应该和搜索关键词一致
'
,
done
=>
{
const
keywords
=
'
海阔天空
'
const
qs
=
{
const
type
=
1
keywords
:
'
海阔天空
'
,
const
limit
=
30
type
:
1
const
data
=
}
'
s=
'
+
keywords
+
'
&limit=
'
+
limit
+
'
&type=
'
+
type
+
'
&offset=0
'
request
.
get
({
url
:
`
${
host
}
/search`
,
qs
:
qs
},
(
err
,
res
,
body
)
=>
{
createRequest
(
'
/api/search/pc/
'
,
'
POST
'
,
data
)
if
(
!
err
&&
res
.
statusCode
==
200
)
{
.
then
(
result
=>
{
body
=
JSON
.
parse
(
body
)
console
.
log
(
JSON
.
parse
(
result
).
result
.
songs
[
0
].
mp3Url
)
assert
(
body
.
result
.
songs
[
0
].
name
===
'
海阔天空
'
)
assert
(
JSON
.
parse
(
result
).
result
.
songs
[
0
].
name
===
'
海阔天空
'
)
done
()
done
()
}
)
}
.
catch
(
err
=>
{
else
{
done
(
err
)
done
(
err
)
}
})
})
})
})
})
})
util/util.js
浏览文件 @
0d373be6
...
@@ -84,34 +84,7 @@ function createWebAPIRequest(
...
@@ -84,34 +84,7 @@ function createWebAPIRequest(
});
});
}
}
function
createRequest
(
path
,
method
,
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
options
=
{
url
:
`http://music.163.com
${
path
}
`
,
method
:
method
,
headers
:
{
"
Referer
"
:
"
http://music.163.com
"
,
"
Cookie
"
:
"
appver=1.5.2
"
,
"
Content-Type
"
:
"
application/x-www-form-urlencoded
"
,
"
User-Agent
"
:
randomUserAgent
()
}
};
if
(
method
.
toLowerCase
()
===
"
post
"
)
{
options
.
body
=
data
;
}
request
(
options
,
function
(
error
,
res
,
body
)
{
if
(
error
)
{
reject
(
error
);
}
else
{
resolve
(
body
);
}
});
});
}
module
.
exports
=
{
module
.
exports
=
{
request
,
request
,
createWebAPIRequest
,
createWebAPIRequest
createRequest
};
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录