Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
myhirra committed Jul 10, 2016
0 parents commit a4c9517
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
53 changes: 53 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var request = require("request");
var argv = require('minimist')(process.argv.slice(2));

var qqUrl = `http://i.y.qq.com/s.plcloud/fcgi-bin/smartbox_new.fcg?key=${encodeURI(argv.keywords)}`;
var baiduUrl = `http://sug.music.baidu.com/info/suggestion?word=${encodeURI(argv.keywords)}`;
var xiamiUrl = `http://www.xiami.com/ajax/search-index?key=${encodeURI(argv.keywords)}`;

request.get(qqUrl, function(error, response, body){
var result = JSON.parse(body.toString());
if(result.data && result.data.song && result.data.song.count){
var qqLink = `http://y.qq.com/#type=song&mid=${result.data.song.itemlist[0].mid}`;
console.log('qq',qqLink);
}else{
request.get(baiduUrl, function(error, response, body){
var result = JSON.parse(body.toString());
if(result.data && result.data.song[0]){
var baiduLink = '';
var encrypted_songid = result.data.song[0].encrypted_songid;
var songid = result.data.song[0].songid;
if(encrypted_songid){
baiduLink = `http://music.baidu.com/song/s/${encrypted_songid}`
}else{
baiduLink = `http://y.baidu.com/song/${songid}`;
}
console.log('baidu',baiduLink);
}else{
request.get(xiamiUrl,function(error, response, body){
// xiami response is `html`
var result = body.toString();

var jsdom = require("jsdom").jsdom;
var doc = jsdom(result);
var window = doc.defaultView;
var resultNodes = doc.getElementsByClassName('song_result');

if(resultNodes.length){
var xiamiLink = resultNodes[0].getAttribute('href');
console.log('xiami',xiamiLink);
}else{
var neteaseApi=require('NeteaseCloudMusicApi').api
neteaseApi.search(argv.keywords,function(data){
var songs = JSON.parse(data).result.songs;
if(songs.length){
var neteaseLink = `http://music.163.com/#/song?id=${songs[0].id}`;
console.log('netease',neteaseLink);
}
});
}
});
}
});
}
});
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "music",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"song"
],
"author": "hirra",
"license": "ISC",
"dependencies":{
"request":"*",
"minimist":"*",
"jsdom":"*",
"NeteaseCloudMusicApi":"*"
}
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 简介
由于现在歌曲版权问题,导致有些歌只能在某些特定的平台才能找到。因此这个工具可以方便大家快速找到音乐链接。

0 comments on commit a4c9517

Please sign in to comment.