Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from xwartz/dev
Browse files Browse the repository at this point in the history
接口更新
  • Loading branch information
xwartz authored Jul 14, 2016
2 parents b6b77cd + a005ec2 commit 071f4e3
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 157 deletions.
14 changes: 9 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = {
"extends": "standard",
"plugins": [
"standard"
]
};
"extends": "standard",
"plugins": [
"standard"
],
"env": {
"mocha": true,
"node": true
}
}
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
sudo: false
language: node_js
node_js:
- "5"
- "node"

cache:
Expand All @@ -14,7 +13,6 @@ install:
script:
- npm run lint
- npm run build
- npm run test
- npm run cover
- npm run codecov

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# doubanfm-sdk [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)[![Build Status](https://travis-ci.org/xwartz/doubanfm-sdk.svg?branch=master)](https://travis-ci.org/xwartz/doubanfm-sdk)[![codecov](https://codecov.io/gh/xwartz/doubanfm-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/xwartz/doubanfm-sdk)
# doubanfm-sdk [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/xwartz/doubanfm-sdk.svg?branch=master)](https://travis-ci.org/xwartz/doubanfm-sdk) [![codecov](https://codecov.io/gh/xwartz/doubanfm-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/xwartz/doubanfm-sdk)

豆瓣 FM SDK

inspired by https://github.com/sapjax/dbfm-app-sdk

## 接口

`captcha_id`: 获取验证码id
`captchaId`: 获取验证码id

`login`: 登录

`logout`: 登出

`channels`: 获取频道

`hot_channels`: 获取热门频道
`hotChannels`: 获取热门频道

`star`: 加心

`unstar`: 取消红心

`never_play_again`: 不再播放
`neverPlayAgain`: 不再播放

`user_info`: 获取用户信息
`userInfo`: 获取用户信息

`lyric`: 获取歌词

Expand Down
30 changes: 4 additions & 26 deletions dist/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,23 @@ var HOST_URL = exports.HOST_URL = 'https://douban.fm/';

var Apis = {
// 验证码id
captcha_id: 'j/new_captcha',
// 验证码图片
captcha_pic: 'misc/captcha',
captchaId: 'j/new_captcha',
// 登录
login: 'j/login',
// 频道
channels: 'j/v2/rec_channels',
// 热门兆赫
hot_channels: 'j/explore/hot_channels',
// 上升最快兆赫
up_trending_channels: 'j/explore/up_trending_channels',
// 根据流派获取频道
genre_channels: 'j/explore/genre',
// 查询频道详细信息
channel_detail: 'j/explore/channel_detail',
hotChannels: 'j/explore/hot_channels',
// 搜索频道
search: 'j/explore/search',
// 收藏频道
fav_channel: 'j/explore/fav_channel',
// 取消收藏频道
unfav_channel: 'j/explore/unfav_channel',
// 我收藏的频道
fav_channels: 'j/fav_channels',
// 是否已收藏频道
is_fav_channel: 'j/explore/is_fav_channel',
favChannels: 'j/explore/fav_channel',
// 根据频道获取歌曲信息
songs: 'j/mine/playlist',
// 红心歌曲
redheart: '/j/v2/redheart/songs',
// 下一首
skip: 'j/mine/playlist',
// 加红心
star: 'j/mine/playlist',
// 取消红心
unstar: 'j/mine/playlist',
// 不再播放
never_play_again: 'j/mine/playlist',
// 用户信息
user_info: 'j/v2/user_info',
userInfo: 'j/v2/user_info',
// 歌词
lyric: 'j/v2/lyric'
};
Expand Down
46 changes: 13 additions & 33 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ var SDK = function SDK() {};
var fn = SDK.prototype;

// 获取验证码id
fn.captcha_id = function (opt, cb) {
fn.captchaId = function (opt, cb) {
cb = cb || noop;
req({
url: _apis2.default['captcha_id'],
url: _apis2.default['captchaId'],
r: random()
}, function (err, res, body) {
if (err) return cb(err);
Expand All @@ -68,27 +68,6 @@ fn.captcha_id = function (opt, cb) {
});
};

// 获取验证码图片 Content-Type:image/jpeg
fn.captcha_pic = function (opt, cb) {
cb = cb || noop;
req({
url: _apis2.default['captcha_pic'],
r: random(),
qs: {
size: 'm',
id: opt.id
}
}, function (err, res, body) {
if (err) return cb(err);
var data = {
id: opt.id,
url: _apis2.default['captcha_pic'] + '?size=m&id=' + opt.id,
body: body
};
cb(null, data);
});
};

// 登录
fn.login = function (opt, cb) {
cb = cb || noop;
Expand Down Expand Up @@ -149,10 +128,10 @@ fn.channels = function (opt, cb) {
};

// 获取热门频道
fn.hot_channels = function (opt, cb) {
fn.hotChannels = function (opt, cb) {
cb = cb || noop;
req({
url: _apis2.default['hot_channels'],
url: _apis2.default['hotChannels'],
qs: {
start: opt.start || 1,
limit: opt.limit || 6
Expand All @@ -174,7 +153,8 @@ fn.hot_channels = function (opt, cb) {
// 根据频道获取歌曲
fn.songs = function (opt, cb) {
var dqs = {
from: 'mainsite',
client: 's:mainsite|y:3.0',
app_name: 'radio_website',
version: 100,
channel: 0,
kbps: 128,
Expand Down Expand Up @@ -218,28 +198,28 @@ fn.unstar = function (opt, cb) {
};

// 不再播放
fn.never_play_again = function (opt, cb) {
fn.neverPlayAgain = function (opt, cb) {
opt.type = 'b';
fn.songs(opt, cb);
};

// 获取私人频道歌曲
fn.personal_channel = function (opt, cb) {
fn.personalChannel = function (opt, cb) {
opt.channel_id = PERSONAL_CHANNEL_ID;
fn.songs(opt, cb);
};

// 获取红心频道歌曲
fn.personal_like_channel = function (opt, cb) {
fn.personalLikeChannel = function (opt, cb) {
opt.channel_id = PERSONAL_LIKE_CHANNEL_ID;
fn.songs(opt, cb);
};

// 我收藏的频道
fn.fav_channels = function (opt, cb) {
fn.favChannels = function (opt, cb) {
cb = cb || noop;
req({
url: _apis2.default['fav_channels'],
url: _apis2.default['favChannels'],
r: random()
}, function (err, res, body) {
if (err) return cb(err);
Expand All @@ -251,10 +231,10 @@ fn.fav_channels = function (opt, cb) {
};

// 获取用户信息
fn.user_info = function (opt, cb) {
fn.userInfo = function (opt, cb) {
cb = cb || noop;
req({
url: _apis2.default['user_info'],
url: _apis2.default['userInfo'],
method: 'GET',
form: true
}, function (err, res, body) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "doubanfm-sdk",
"version": "1.1.1",
"version": "2.0.0",
"description": "douban fm web sdk",
"main": "dist/index.js",
"scripts": {
"lint": "eslint src *.js",
"build": "babel src -d dist",
"test": "mocha --compilers js:babel-register --recursive -t 8000 test/*.js",
"cover": "node_modules/.bin/babel-node node_modules/.bin/istanbul cover _mocha --report lcovonly -- -R spec -t 8000",
"test": "mocha --compilers js:babel-register --recursive -t 10000 test/*.js",
"cover": "node_modules/.bin/babel-node node_modules/.bin/istanbul cover _mocha --report lcovonly -- -R spec -t 10000",
"codecov": "codecov -t f0a0b002-8fa2-494c-a84b-fecfd62c5ca6"
},
"repository": {
Expand Down
30 changes: 4 additions & 26 deletions src/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,23 @@ export const HOST_URL = 'https://douban.fm/'

let Apis = {
// 验证码id
captcha_id: 'j/new_captcha',
// 验证码图片
captcha_pic: 'misc/captcha',
captchaId: 'j/new_captcha',
// 登录
login: 'j/login',
// 频道
channels: 'j/v2/rec_channels',
// 热门兆赫
hot_channels: 'j/explore/hot_channels',
// 上升最快兆赫
up_trending_channels: 'j/explore/up_trending_channels',
// 根据流派获取频道
genre_channels: 'j/explore/genre',
// 查询频道详细信息
channel_detail: 'j/explore/channel_detail',
hotChannels: 'j/explore/hot_channels',
// 搜索频道
search: 'j/explore/search',
// 收藏频道
fav_channel: 'j/explore/fav_channel',
// 取消收藏频道
unfav_channel: 'j/explore/unfav_channel',
// 我收藏的频道
fav_channels: 'j/fav_channels',
// 是否已收藏频道
is_fav_channel: 'j/explore/is_fav_channel',
favChannels: 'j/explore/fav_channel',
// 根据频道获取歌曲信息
songs: 'j/mine/playlist',
// 红心歌曲
redheart: '/j/v2/redheart/songs',
// 下一首
skip: 'j/mine/playlist',
// 加红心
star: 'j/mine/playlist',
// 取消红心
unstar: 'j/mine/playlist',
// 不再播放
never_play_again: 'j/mine/playlist',
// 用户信息
user_info: 'j/v2/user_info',
userInfo: 'j/v2/user_info',
// 歌词
lyric: 'j/v2/lyric'
}
Expand Down
Loading

0 comments on commit 071f4e3

Please sign in to comment.