diff --git a/README.MD b/README.MD index 78d436b32fa49938fff41f73520215db0b7ededc..55b00d45ebf89c1d7223d590d50994dfede3caa0 100644 --- a/README.MD +++ b/README.MD @@ -59,6 +59,11 @@ api.getArtistAlbums(id:Number,[callback:function,limit:Number default:3, offset: api.getAlbums(id:Number,[callback:function]) ``` +## getPlaylists + +``` javascript +api.Playlists(id:Number,[callback:function]) +``` ## License [The MIT License (MIT)](LICENSE) diff --git a/build/app.js b/build/app.js index 607e512f94f56d8556f600d8613c600808e1318a..cd4f66ad3a49141d85f050462bc23c27e87c4e7f 100644 --- a/build/app.js +++ b/build/app.js @@ -15,12 +15,15 @@ var _getArtistAlbums = require('./component/getArtistAlbums'); var _getAlbums = require('./component/getAlbums'); +var _getPlaylists = require('./component/getPlaylists'); + var api = { search: _search.search, song: _song.song, lrc: _lrc.lrc, getArtistAlbums: _getArtistAlbums.getArtistAlbums, - getAlbums: _getAlbums.getAlbums + getAlbums: _getAlbums.getAlbums, + getPlaylists: _getPlaylists.getPlaylists }; -exports.api = api; \ No newline at end of file +exports.api = api; diff --git a/build/component/getPlaylists b/build/component/getPlaylists new file mode 100644 index 0000000000000000000000000000000000000000..3be62f2e528dc8709d4cbdbfbc2c53197c371a19 --- /dev/null +++ b/build/component/getPlaylists @@ -0,0 +1,32 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.getAlbums = undefined; + +var _request = require('request'); + +var _request2 = _interopRequireDefault(_request); + +var _config = require('../config'); + +var _util = require('../util'); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var getPlaylists = function getPlaylists(id, callback) { + var option = (0, _util.deepCopy)(_config.globalOption); + var url = _config.origin + '/api/playlist/detail?id=' + id; + var method = 'get'; + Object.assign(option, { url: url, method: method }); + (0, _request2.default)(option, function (err, res, body) { + if (!err && res.statusCode == 200) { + var info = JSON.parse(body); + callback && callback(JSON.stringify(info, '', 2)); + } else { + console.error(err); + } + }); +}; +exports.getPlaylists = getPlaylists; diff --git a/src/app.js b/src/app.js index 791dcbd3363cd7d46bdabb6e3e43930976c893c9..e2c7f9a9cb7611ecb084c34bf241ec7e185d95d2 100644 --- a/src/app.js +++ b/src/app.js @@ -3,13 +3,15 @@ import { song } from './component/song' import { lrc } from './component/lrc' import { getArtistAlbums } from './component/getArtistAlbums' import { getAlbums } from './component/getAlbums' +import { getPlaylists } from './component/getPlaylists' let api = { search: search, song: song, lrc: lrc, getArtistAlbums: getArtistAlbums, - getAlbums: getAlbums + getAlbums: getAlbums, + getPlaylists: getPlaylists } export {api} diff --git a/src/component/getPlaylists.js b/src/component/getPlaylists.js new file mode 100644 index 0000000000000000000000000000000000000000..7c35a3697ac4e2751ae485a04922d267aad19139 --- /dev/null +++ b/src/component/getPlaylists.js @@ -0,0 +1,19 @@ +import request from 'request' +import { origin, globalOption } from '../config' +import { deepCopy } from '../util' + +const getPlaylists = (id, callback) => { + const option = deepCopy(globalOption) + const url = `${origin}/api/playlist/detail?id=${id}` + const method = 'get' + Object.assign(option, {url, method}) + request(option, (err, res, body) => { + if(!err && res.statusCode == 200) { + let info = JSON.parse(body) + callback && callback(JSON.stringify(info, '', 2)) + } else { + console.error(err); + } + }) +} +export { Playlists } diff --git a/test/test.js b/test/test.js index 36ac96c2ade513abeee9329880e34da6c8e24d34..42722a923a203eb1fff8d348c0332decf8b6190c 100644 --- a/test/test.js +++ b/test/test.js @@ -26,3 +26,8 @@ api.getAlbums('32311', data => { console.log("####################Albums####################") console.log(data) }) + +api.getPlaylists('311785002', data => { + console.log("####################Playlists####################") +console.log(data) +})