Skip to content

Instantly share code, notes, and snippets.

@prinsss
Last active July 25, 2016 06:58
Show Gist options
  • Select an option

  • Save prinsss/2bb8c1514589140f461630f21380867d to your computer and use it in GitHub Desktop.

Select an option

Save prinsss/2bb8c1514589140f461630f21380867d to your computer and use it in GitHub Desktop.
Generate playlist config for APlayer from netease music automatically
/*
* @Author: printempw
* @Date: 2016-07-25 13:03:12
* @Last Modified by: printempw
* @Last Modified time: 2016-07-25 14:51:29
*/
var superagent = require('superagent');
// fill your ids here
var songs = [
'40729832',
'629877',
'629880',
'29787857',
'399411850',
'4949085',
'32098023',
'29816800',
'34367795',
'27961148',
'29829320'
];
var configs = new Array();
function getSongJson(id, callback) {
console.log('Getting details of song id.'+id)
var url = "http://music.163.com/api/song/detail/?id="+id+"&ids=%5B"+id+"%5D";
superagent.get(url)
.set('Cookie', 'appver=1.5.0.75771;')
.set('Referer','http://music.163.com/')
.end(function(err, res) {
callback(JSON.parse(res.text));
});
}
for (index in songs) {
getSongJson(songs[index], function(json) {
var artists = [];
// parse artists
for (artist in json['songs'][0]['artists']) {
artists.push(json['songs'][0]['artists'][artist]['name']);
}
var config = new Object();
config.title = json['songs'][0]['name'];
config.author = artists.join(', ');
if (json['songs'][0]['mp3Url']) {
config.url = json['songs'][0]['mp3Url'].replace('http://m', 'http://p');
} else {
console.log('Warning: Could not found song id.'+json['songs'][0]['id']+'\'s src');
}
config.pic = json['songs'][0]['album']['picUrl'];
configs.push(config);
if (configs.length >= songs.length) {
console.log('Parse netease music to APlayer config:\n')
// pretty print
console.log(JSON.stringify(configs, null, ' '));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment