Last active
December 23, 2015 08:09
-
-
Save nahakyuu/5b30bfaad5ecfc240c50 to your computer and use it in GitHub Desktop.
虾米下载链接提取
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (str ,num) { | |
var line = Math.floor(str.length / num); | |
var begin = 0; | |
var end = line; | |
var temp = []; | |
//切割str | |
for (var i = line * num - str.length; i; i++) { | |
temp.push(str.slice(begin, ++end)); | |
begin = end;end += line; | |
} | |
for (var i = str.length - num - line * num; i; i++) { | |
temp.push(str.slice(begin, end)); | |
begin = end;end += line; | |
} | |
//合并 | |
var result = ''; | |
for (var i = 0; i < line; i++) { | |
for( var j = 0; j < num; j++) { | |
result += temp[j][i]; | |
} | |
} | |
for (var i = 0; i < str.length - line * num; i++) { | |
result += temp[i][line]; | |
} | |
return decodeURIComponent(result).replace(/\^/g,'0'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var superagent = require('superagent'); | |
var decode = require('./decode') | |
var url = | |
'http://www.xiami.com/song/playlist/id/' + | |
process.argv[2] + | |
'/object_id/0/cat/json'; | |
superagent.get().end(function(err, res){ | |
if (err) | |
return console.error(err); | |
var result = JSON.parse(res.text); | |
var location = result.data.trackList[0].location; | |
console.log(decode(location.slice(1), Number(location[0]))); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "decode-xiami", | |
"main": "index.js", | |
"author": "nahakyuu <root@aroa.me>", | |
"dependencies": { | |
"superagent": "^1.3.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
蛮久之前写的了
下架的歌曲大概会导致意外错误吧