Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
add baidu music library
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Oct 16, 2017
1 parent 795cf69 commit 8dbae56
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iease-music",
"version": "1.0.0",
"version": "1.0.1",
"description": "这应该是最好的网易云音乐播放器了,没有之一,如果有请打醒 🤘",
"main": "main.js",
"scripts": {
Expand Down
43 changes: 43 additions & 0 deletions server/search/Baidu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

import axios from 'axios';
import _debug from 'debug';

const debug = _debug('dev:plugin:Baidu');
const error = _debug('dev:plugin:Baidu:error');

export default async(keyword, artists) => {
debug(`Search '${keyword} - ${artists}' use Baidu library.`);

var response = await axios.get('http://sug.music.baidu.com/info/suggestion', {
params: {
word: keyword,
version: 2,
from: 0,
}
});
var songs = response.data.data.song;
var song = songs.find(e => artists.indexOf(e.artistname) > -1);

if (!song) {
return false;
}
response = await axios.get('http://music.baidu.com/data/music/fmlink', {
params: {
songIds: song.songid,
type: 'mp3',
rate: '320',
},
});

try {
song = {
src: response.data.data.songList[0].songLink,
};
} catch (ex) {
// Anti-warnning
error('Failed to get song URL: %O', ex);
song = false;
}

return song;
};
2 changes: 1 addition & 1 deletion server/search/Kugou.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function getURL(hash) {
}

export default async(keyword, artists) => {
debug(`Search '${keyword} - ${artists}' use Kugou plugin.`);
debug(`Search '${keyword} - ${artists}' use Kugou library.`);

var response = await axios.get(`http://mobilecdn.kugou.com/api/v3/search/song?format=json&keyword=${encodeURIComponent(keyword)}&page=1&pagesize=1&showtype=1`);
var data = response.data;
Expand Down
2 changes: 1 addition & 1 deletion server/search/QQ.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function getURL(data) {
}

export default async(keyword, artists) => {
debug(`Search '${keyword} - ${artists}' use QQ plugin.`);
debug(`Search '${keyword} - ${artists}' use QQ library.`);

try {
await updateVkey();
Expand Down
3 changes: 2 additions & 1 deletion server/search/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

import QQ from './QQ';
import Kugou from './Kugou';
import Baidu from './Baidu';
import _debug from 'debug';

const debug = _debug('plugin:');

export default (keyword, artists) => {
var plugins = [QQ, Kugou];
var plugins = [Baidu, QQ, Kugou];

debug('Plugin has loaded, search: \'%s\', \'%s\'', keyword, artists);

Expand Down

0 comments on commit 8dbae56

Please sign in to comment.