92 lines
2.7 KiB
JavaScript
92 lines
2.7 KiB
JavaScript
/**
|
||
*
|
||
* @authors Your Name (you@example.org)
|
||
* @date 2017-08-03 10:29:18
|
||
* @version $Id$
|
||
*/
|
||
|
||
const request = require('request');
|
||
|
||
function randomString(len) {
|
||
len = len || 32;
|
||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||
var maxPos = chars.length;
|
||
var pwd = '';
|
||
for (i = 0; i < len; i++) {
|
||
pwd += chars.charAt(Math.floor(Math.random() * maxPos));
|
||
}
|
||
return pwd;
|
||
}
|
||
|
||
module.exports = {
|
||
|
||
getSearchSongList:function(param,req,callback){
|
||
//let proxy_url = 'http://songsearch.kugou.com/song_search_v2?keyword='+param+'&page=1&pagesize=30&userid=-1&clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1&privilege_filter=0&_='+Date.now();
|
||
let proxy_url = 'http://songsearch.kugou.com/song_search_v2?' + param + '&_='+Date.now();
|
||
let options = {
|
||
headers: {"Connection": "close"},
|
||
url: proxy_url,
|
||
method: req.method,
|
||
json: true,
|
||
body: req.body
|
||
};
|
||
|
||
console.log(req.method);
|
||
|
||
request(options, function(error, response, data){
|
||
if (!error && response.statusCode == 200) {
|
||
//console.log('------接口代理数据------',response,data);
|
||
|
||
if(callback) callback(data);
|
||
//res.json(data)
|
||
}
|
||
});
|
||
},
|
||
|
||
getNewSongList:function(param,req,callback){
|
||
let proxy_url = 'http://m.kugou.com/?' + param;
|
||
let options = {
|
||
headers: {"Connection": "close"},
|
||
url: proxy_url,
|
||
method: req.method,
|
||
json: true,
|
||
body: req.body
|
||
};
|
||
|
||
console.log(req.method);
|
||
|
||
request(options, function(error, response, data){
|
||
if (!error && response.statusCode == 200) {
|
||
//console.log('------接口代理数据------',response,data);
|
||
|
||
if(callback) callback(data);
|
||
//res.json(data)
|
||
}
|
||
});
|
||
},
|
||
|
||
getSongMsg:function(hash,req,callback){
|
||
let proxy_url = 'http://www.kugou.com/yy/index.php?r=play/getdata&hash='+hash;
|
||
|
||
let options = {
|
||
url: proxy_url,
|
||
headers: {
|
||
"Connection": "close",
|
||
"Cookie":"kg_mid="+randomString()
|
||
},
|
||
method: req.method.toUpperCase(),
|
||
json: true,
|
||
body: req.body
|
||
};
|
||
|
||
request(options, function(error, response, data){
|
||
if (!error && response.statusCode == 200) {
|
||
//console.log('------接口数据------',data);
|
||
|
||
if(callback) callback(data);
|
||
//res.json(data)
|
||
}
|
||
});
|
||
}
|
||
|
||
} |