This repository has been archived by the owner on Jun 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
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
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
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; | ||
}; |
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
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
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