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

Commit

Permalink
Merge pull request #201 from trazyn/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
trazyn authored Jul 6, 2018
2 parents e2ef49a + ed35759 commit 9d0a473
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build-main": "cross-env NODE_ENV=production node -r babel-register ./node_modules/webpack/bin/webpack --config ./config/webpack.config.electron.js --progress --profile --colors",
"build-renderer": "cross-env NODE_ENV=production node -r babel-register ./node_modules/webpack/bin/webpack --config ./config/webpack.config.production.js --progress --profile --colors",
"build": "rm -rf dist && npm run build-main && npm run build-renderer",
"api": "cross-env NODE_ENV=development AUTORUN=1 DEBUG_COLORS=true DEBUG=dev:*,-not_this node -r babel-register server/api.js",
"api": "cross-env NODE_ENV=development APIONLY=1 DEBUG_COLORS=true DEBUG=dev:*,-not_this node -r babel-register server/api.js",
"hot-server": "cross-env NODE_ENV=development DEBUG_COLORS=true DEBUG=dev:*,-not_this node -r babel-register server/dev.js",
"start-hot": "cross-env HOT=1 NODE_ENV=development DEBUG_COLORS=true DEBUG=dev:*,-not_this ./node_modules/.bin/electron -r babel-register -r babel-polyfill ./main",
"package-mac": "npm run build && rm -rf release && build --mac --projectDir ./dist",
Expand Down
2 changes: 1 addition & 1 deletion server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ app.use('/api/search', require('./router/search'));
app.use('/api/comments', require('./router/comments'));
app.use('/api/lyrics', cache('360 minutes'), require('./router/lyrics'));

if (process.env.AUTORUN) {
if (process.env.APIONLY) {
console.log(`API Server run with port: ${port}`);
app.listen(port);
}
Expand Down
9 changes: 5 additions & 4 deletions server/router/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import apicache from 'apicache'
import axios from 'axios';
import _debug from 'debug';
import chalk from 'chalk';
import search from '../search';
/* eslint-enable */

const debug = _debug('dev:api');
Expand Down Expand Up @@ -260,9 +259,11 @@ router.get('/song/:id/:name/:artists/:flac?', cache('3 minutes', onlyStatus200),
}
} catch (ex) {
try {
// Search from other source
debug(chalk.underline.black.bgYellow(`🔎 ${name} - ${artists}`));
song = await search(name, artists);
if (!process.env.APIONLY) {
// Search from other source
debug(chalk.underline.black.bgYellow(`🔎 ${name} - ${artists}`));
song = await require('../search').default(name, artists);
}
} catch (ex) {
debug(chalk.red.underline.bold(`💔 Not found: "${name} - ${artists}"`));
}
Expand Down
7 changes: 4 additions & 3 deletions server/search/Baidu.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ export default async(request, keyword, artists) => {
return Promise.reject();
}

song = {
src: response.data.songList[0].songLink,
};
song = response.data.songList[0];

song.src = song.songLink;
song.bitRate = song.rate * 1000;

if (!song.src) {
return Promise.reject();
Expand Down
5 changes: 2 additions & 3 deletions server/search/Kugou.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ export default async(request, keyword, artists) => {
let song = await getURL(e['320hash'] || e['hash']);

if (song) {
return {
src: song.url
};
song.src = song.url;
return song;
}
}
} catch (ex) {
Expand Down
77 changes: 77 additions & 0 deletions server/search/Kuwo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

import _debug from 'debug';
import chalk from 'chalk';

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

export default async(request, keyword, artists) => {
debug(chalk.black.bgGreen('💊 Loaded Kuwo music.'));

try {
// Apply cookie
await request({
uri: 'http://www.kuwo.cn/',
method: 'HEAD',
});

var response = await request({
uri: 'http://search.kuwo.cn/r.s',
qs: {
ft: 'music',
itemset: 'web_2013',
client: 'kt',
rformat: 'json',
encoding: 'utf8',
all: [keyword].concat(artists.split(',')).join('+'),
pn: 0,
rn: 20,
},
});
// eslint-disable-next-line
response = eval('(' + response + ')');
artists = artists.split(',');

var songs = response.abslist || [];
var payload = songs.find(
e => artists.findIndex(artist => e.ARTIST.indexOf(artist) !== -1) > -1
);

console.log(payload);

if (!payload) {
error(chalk.black.bgRed('🚧 Nothing.'));
return Promise.reject();
}

response = await request({
uri: 'http://antiserver.kuwo.cn/anti.s',
qs: {
type: 'convert_url',
format: 'aac|mp3|wma',
response: 'url',
rid: payload.MP3RID,
},
});

if (!response) {
error(chalk.black.bgRed('🚧 Nothing.'));
return Promise.reject();
}

var song = {
src: response,
isFlac: response.endsWith('.aac')
};

debug(chalk.black.bgGreen('🚚 Result >>>'));
debug(song);
debug(chalk.black.bgGreen('🚚 <<<'));
} catch (ex) {
// Anti-warnning
error('Failed to get song: %O', ex);
return Promise.reject();
}

return song;
};
4 changes: 1 addition & 3 deletions server/search/MiGu.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export default async(request, keyword, artists) => {
debug(e);
debug(chalk.black.bgGreen('🚚 <<<'));

return {
src: e.mp3
};
return Object.assign({}, e, { src: e.mp3 });
}
}
} catch (ex) {
Expand Down
2 changes: 2 additions & 0 deletions server/search/QQ.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ async function getSong(mid) {

if (file.size_320mp3) {
return {
bitRate: 320000,
src: getURL(`M800${mid}.mp3`, key, guid),
};
}

if (file.size_128mp3) {
return {
bitRate: 128000,
src: getURL(`M500${mid}.mp3`, key, guid),
};
}
Expand Down
6 changes: 3 additions & 3 deletions server/search/Xiami.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export default async(request, keyword, artists) => {
continue;
}

let song = {
src: e.listen_file,
};
let song = e;

song.src = e.listen_file;

if (!song.src) {
return Promise.reject();
Expand Down
9 changes: 8 additions & 1 deletion server/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import MiGu from './MiGu';
import Kugou from './Kugou';
import Baidu from './Baidu';
import Xiami from './Xiami';
import Kuwo from './Kuwo';

async function getPreferences() {
return new Promise(resolve => {
Expand All @@ -20,14 +21,16 @@ export default async(keyword, artists) => {
var rpOptions = {
timeout: 10000,
json: true,
jar: true,
};
var plugins = [];

if (!enginers) {
enginers = {
'QQ': true,
'MiGu': true,
'Xiami': true,
'Kuwo': true,
'Xiami': false,
'Kugou': false,
'Baidu': true,
};
Expand Down Expand Up @@ -62,6 +65,10 @@ export default async(keyword, artists) => {
plugins.push(Baidu);
}

if (enginers['Kuwo']) {
plugins.push(Kuwo);
}

var rp = require('request-promise-native').defaults(rpOptions);

return Promise.all(
Expand Down
9 changes: 5 additions & 4 deletions server/search/test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@

import search from './Baidu';
import search from './Kuwo';

async function test() {
var res = {};
var rp = require('request-promise-native').defaults({
proxy: 'http://127.0.0.1:1087',
strictSSL: false
strictSSL: true,
json: true,
});

try {
res = await search(rp, '尘埃', '王菲');
res = await search(rp, '演员', '薛之谦');
console.log(res);
console.log(res.purview_roles);
} catch (ex) {
console.error(ex);
}
Expand Down
8 changes: 8 additions & 0 deletions src/js/components/Preferences/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ class Options extends Component {
id="enginerOfKugou"
onChange={e => this.setEnginers({ 'Kugou': e.target.checked })} />
</label>
<label htmlFor="enginerOfKuwo">
<h4>酷我音乐</h4>

<Switch
defaultChecked={enginers['Kuwo']}
id="enginerOfKuwo"
onChange={e => this.setEnginers({ 'Kuwo': e.target.checked })} />
</label>
<label htmlFor="enginerOfBaidu">
<h4>百度音乐</h4>

Expand Down
1 change: 1 addition & 0 deletions src/js/stores/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Preferences {
'Xiami': false,
'Kugou': false,
'Baidu': true,
'kuwo': true,
};
@observable proxy = '';
Expand Down

0 comments on commit 9d0a473

Please sign in to comment.