Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
嗯菜
NeteaseCloudMusicApi
提交
e8b18d03
N
NeteaseCloudMusicApi
项目概览
嗯菜
/
NeteaseCloudMusicApi
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
NeteaseCloudMusicApi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e8b18d03
编写于
1月 04, 2018
作者:
B
binaryify
提交者:
GitHub
1月 04, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #162 from twesix/master
用request重写了请求函数
上级
4dfab517
f12c17ee
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
109 addition
and
140 deletion
+109
-140
app.js
app.js
+1
-2
router/comment_music.js
router/comment_music.js
+15
-15
test/musicUrl.test.js
test/musicUrl.test.js
+21
-20
util/util.js
util/util.js
+72
-103
未找到文件。
app.js
浏览文件 @
e8b18d03
const
express
=
require
(
"
express
"
);
const
http
=
require
(
"
http
"
);
const
apicache
=
require
(
"
apicache
"
);
const
path
=
require
(
"
path
"
);
...
...
@@ -248,7 +247,7 @@ app.use("/user/record", require("./router/user_playrecord"));
const
port
=
process
.
env
.
PORT
||
3000
;
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`server running @
${
port
}
`
);
console
.
log
(
`server running @
http://localhost:
${
port
}
`
);
});
module
.
exports
=
app
;
router/comment_music.js
浏览文件 @
e8b18d03
const
express
=
require
(
'
express
'
)
const
router
=
express
()
const
{
createWebAPIRequest
}
=
require
(
'
../util/util
'
)
const
express
=
require
(
"
express
"
);
const
router
=
express
()
;
const
{
createWebAPIRequest
}
=
require
(
"
../util/util
"
);
router
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
const
rid
=
req
.
query
.
id
const
cookie
=
req
.
get
(
'
Cookie
'
)
?
req
.
get
(
'
Cookie
'
)
:
''
router
.
get
(
"
/
"
,
(
req
,
res
)
=>
{
const
rid
=
req
.
query
.
id
;
const
cookie
=
req
.
get
(
"
Cookie
"
)
?
req
.
get
(
"
Cookie
"
)
:
""
;
const
data
=
{
offset
:
req
.
query
.
offset
||
0
,
rid
:
rid
,
limit
:
req
.
query
.
limit
||
20
,
csrf_token
:
''
}
csrf_token
:
""
}
;
createWebAPIRequest
(
'
music.163.com
'
,
"
music.163.com
"
,
`/weapi/v1/resource/comments/R_SO_4_
${
rid
}
/?csrf_token=`
,
'
POST
'
,
"
POST
"
,
data
,
cookie
,
music_req
=>
{
res
.
send
(
music_req
)
res
.
send
(
music_req
)
;
},
err
=>
res
.
status
(
502
).
send
(
'
fetch error
'
)
)
})
err
=>
res
.
status
(
502
).
send
(
err
.
message
)
)
;
})
;
module
.
exports
=
router
module
.
exports
=
router
;
test/musicUrl.test.js
浏览文件 @
e8b18d03
const
assert
=
require
(
'
assert
'
)
const
crypto
=
require
(
'
crypto
'
)
const
{
createWebAPIRequest
}
=
require
(
'
../util/util
'
)
const
assert
=
require
(
"
assert
"
);
const
crypto
=
require
(
"
crypto
"
);
const
{
createWebAPIRequest
}
=
require
(
"
../util/util
"
);
describe
(
'
测试获取歌曲是否正常
'
,
()
=>
{
it
(
'
歌曲的 url 不应该为空
'
,
done
=>
{
const
id
=
347230
const
br
=
999000
describe
(
"
测试获取歌曲是否正常
"
,
()
=>
{
it
(
"
歌曲的 url 不应该为空
"
,
done
=>
{
const
id
=
462791935
;
const
br
=
999000
;
const
data
=
{
ids
:
[
id
],
br
:
br
,
csrf_token
:
''
}
const
cookie
=
''
csrf_token
:
""
}
;
const
cookie
=
""
;
createWebAPIRequest
(
'
music.163.com
'
,
'
/weapi/song/enhance/player/url
'
,
'
POST
'
,
"
music.163.com
"
,
"
/weapi/song/enhance/player/url
"
,
"
POST
"
,
data
,
cookie
,
music_req
=>
{
console
.
log
(
JSON
.
parse
(
music_req
).
data
[
0
].
url
)
assert
(
!!
JSON
.
parse
(
music_req
).
data
[
0
].
url
)
done
()
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
)
done
(
err
)
;
}
)
})
})
)
;
})
;
})
;
util/util.js
浏览文件 @
e8b18d03
const
Encrypt
=
require
(
'
./crypto.js
'
)
const
http
=
require
(
'
http
'
)
const
querystring
=
require
(
'
querystring
'
)
const
Encrypt
=
require
(
"
./crypto.js
"
);
const
request
=
require
(
"
request
"
);
const
querystring
=
require
(
"
querystring
"
);
function
randomUserAgent
()
{
const
userAgentList
=
[
'
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
'
,
'
Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
'
,
'
Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
'
,
'
Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36
'
,
'
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36
'
,
'
Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36
'
,
'
Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Mobile/14F89;GameHelper
'
,
'
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4
'
,
'
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1
'
,
'
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
'
,
'
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:46.0) Gecko/20100101 Firefox/46.0
'
,
'
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0
'
,
'
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
'
,
'
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
'
,
'
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
'
,
'
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)
'
,
'
Mozilla/5.0 (Windows NT 6.3; Win64, x64; Trident/7.0; rv:11.0) like Gecko
'
,
'
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586
'
,
'
Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1
'
]
const
num
=
Math
.
floor
(
Math
.
random
()
*
userAgentList
.
length
)
return
userAgentList
[
num
]
"
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
"
,
"
Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
"
,
"
Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
"
,
"
Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36
"
,
"
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36
"
,
"
Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36
"
,
"
Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Mobile/14F89;GameHelper
"
,
"
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4
"
,
"
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1
"
,
"
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
"
,
"
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:46.0) Gecko/20100101 Firefox/46.0
"
,
"
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0
"
,
"
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
"
,
"
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)
"
,
"
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
"
,
"
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)
"
,
"
Mozilla/5.0 (Windows NT 6.3; Win64, x64; Trident/7.0; rv:11.0) like Gecko
"
,
"
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586
"
,
"
Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1
"
]
;
const
num
=
Math
.
floor
(
Math
.
random
()
*
userAgentList
.
length
)
;
return
userAgentList
[
num
]
;
}
function
createWebAPIRequest
(
host
,
path
,
...
...
@@ -36,94 +37,62 @@ function createWebAPIRequest(
callback
,
errorcallback
)
{
let
music_req
=
''
const
cryptoreq
=
Encrypt
(
data
)
const
http_client
=
http
.
request
(
{
hostname
:
host
,
const
cryptoreq
=
Encrypt
(
data
);
const
options
=
{
url
:
`http://
${
host
}${
path
}
`
,
method
:
method
,
path
:
path
,
headers
:
{
Accept
:
'
*/*
'
,
'
Accept-Language
'
:
'
zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4
'
,
Connection
:
'
keep-alive
'
,
'
Content-Type
'
:
'
application/x-www-form-urlencoded
'
,
Referer
:
'
http://music.163.com
'
,
Host
:
'
music.163.com
'
,
Accept
:
"
*/*
"
,
"
Accept-Language
"
:
"
zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4
"
,
Connection
:
"
keep-alive
"
,
"
Content-Type
"
:
"
application/x-www-form-urlencoded
"
,
Referer
:
"
http://music.163.com
"
,
Host
:
"
music.163.com
"
,
Cookie
:
cookie
,
'
User-Agent
'
:
randomUserAgent
()
}
"
User-Agent
"
:
randomUserAgent
()
},
function
(
res
)
{
res
.
on
(
'
error
'
,
function
(
err
)
{
errorcallback
(
err
)
})
res
.
setEncoding
(
'
utf8
'
)
if
(
res
.
statusCode
!=
200
)
{
createWebAPIRequest
(
host
,
path
,
method
,
data
,
cookie
,
callback
)
return
}
else
{
res
.
on
(
'
data
'
,
function
(
chunk
)
{
music_req
+=
chunk
})
res
.
on
(
'
end
'
,
function
()
{
if
(
music_req
==
''
)
{
createWebAPIRequest
(
host
,
path
,
method
,
data
,
cookie
,
callback
)
return
}
if
(
res
.
headers
[
'
set-cookie
'
])
{
callback
(
music_req
,
res
.
headers
[
'
set-cookie
'
])
}
else
{
callback
(
music_req
)
}
})
}
}
)
http_client
.
write
(
querystring
.
stringify
({
body
:
querystring
.
stringify
({
params
:
cryptoreq
.
params
,
encSecKey
:
cryptoreq
.
encSecKey
})
)
http_client
.
end
()
};
request
(
options
,
function
(
error
,
res
,
body
)
{
if
(
error
)
{
errorcallback
(
error
);
}
else
{
callback
(
body
,
res
.
headers
[
"
set-cookie
"
]);
}
});
}
function
createRequest
(
path
,
method
,
data
,
callback
,
errorcallback
)
{
function
createRequest
(
path
,
method
,
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
ne_req
=
''
const
http_client
=
http
.
request
(
{
hostname
:
'
music.163.com
'
,
const
options
=
{
url
:
`http://music.163.com
${
path
}
`
,
method
:
method
,
path
:
path
,
headers
:
{
Referer
:
'
http://music.163.com
'
,
Cookie
:
'
appver=1.5.2
'
,
'
Content-Type
'
:
'
application/x-www-form-urlencoded
'
,
'
User-Agent
'
:
randomUserAgent
()
Referer
:
"
http://music.163.com
"
,
Cookie
:
"
appver=1.5.2
"
,
"
Content-Type
"
:
"
application/x-www-form-urlencoded
"
,
"
User-Agent
"
:
randomUserAgent
()
}
},
res
=>
{
res
.
setEncoding
(
'
utf8
'
)
res
.
on
(
'
error
'
,
err
=>
{
reject
(
err
)
})
res
.
on
(
'
data
'
,
chunk
=>
{
ne_req
+=
chunk
})
res
.
on
(
'
end
'
,
()
=>
{
resolve
(
ne_req
)
})
};
if
(
method
.
toLowerCase
()
===
"
post
"
)
{
options
.
body
=
data
;
}
)
if
(
method
==
'
POST
'
)
{
http_client
.
write
(
data
)
request
(
options
,
function
(
error
,
res
,
body
)
{
if
(
error
)
{
reject
(
error
);
}
else
{
resolve
(
body
);
}
http_client
.
end
()
})
});
})
;
}
module
.
exports
=
{
createWebAPIRequest
,
createRequest
}
}
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录