Navigation Menu

Skip to content
chengxianghe edited this page Mar 17, 2017 · 18 revisions
  • 豆瓣并没有开放 douban.fm 的API

  • 以下的分析只是通过抓包,并结合网上前人的研究,猜测参数的作用

登录接口

使用 douban.fm 并不需要使用豆瓣的 OAuth 认证,只需要简单地把用户名密码 POST 过去,并保存 Token 和 Expire 即可。

  • URL: https://www.douban.com/service/auth2/token

  • Method: POST

  • Arguments:

    • apikey: 02646d3fb69a52ff072d47bf23cef8fd

    • client_id: 02646d3fb69a52ff072d47bf23cef8fd

    • client_secret: cde5d61429abcd7c

    • udid: b88146214e19b8a8244c9bc0e2789da68955234d

    • douban_udid: b635779c65b816b13b330b68921c0f8edc049590

    • device_id: b88146214e19b8a8244c9bc0e2789da68955234d

    • grant_type: password

    • redirect_uri: http://www.douban.com/mobile/fm

    • username: 用户帐号

    • password: 明文密码

  • Header: Content-Type: application/x-www-form-urlencoded

  • Response ( application/json )

登录成功

{
    "access_token": "21a0867e86f16fb464e1937b94d44f1w",
    "douban_user_id": 145636941,
    "douban_user_name": "xxxx",
    "expires_in": 7775999,
    "refresh_token": "77bc1538a652d3b867343fa9f2f87b18"
}

在获得access_tokenexpire后,保存起来,expire 应该是默认的90天的过期时间, 在使用获取歌曲列表、红心等API时,需要在相应的请求header里面添加Authorization字段,对应的值是Bearer + access_token, 注意Bearer后面是有空格的,例如 Bearer 21a0867e86f16fb464e1937b94d44f1w

获取频道列表

这个接口获取的频道列表是对应客户端上的第一个Tab。 测试

  • URL: https://api.douban.com/v2/fm/app_channels

  • Method: GET

  • Arguments:

    • alt: json

    • app_name: radio_iphone

    • apikey: 02646d3fb69a52ff072d47bf23cef8fd

    • client: s:mobile|y:iOS 10.2|f:115|d:b88146214e19b8a8244c9bc0e2789da68955234d|e:iPhone7,1|m:appstore

    • client_id: 02646d3fb69a52ff072d47bf23cef8fd

    • icon_cate: xlarge

    • udid: b88146214e19b8a8244c9bc0e2789da68955234d

    • douban_udid: b635779c65b816b13b330b68921c0f8edc049590

    • version: 115

  • Response ( application/json ):

{
    "groups": [
        {
            "chls": [
                {
                    "style": {
                        "display_text": "",
                        "bg_color": "0x499884",
                        "layout_type": 1,
                        "bg_image": ""
                    },
                    "intro": "我的个性化音乐频道",
                    "name": "我的私人",
                    "song_num": 0,
                    "collected": "disabled",
                    "cover": "https://img3.doubanio.com/f/fm/11bed977076d721fb66ef6c2f2cfb66ae79ed07a/pics/fm/default_personal_channel_cover.png",
                    "id": 0
                }, {
                    "style": {
                        "bg_color": "0xe06b59",
                        "layout_type": 2,
                        "bg_image": ""
                    },
                    "intro": "豆瓣好评音乐精选",
                    "name": "豆瓣精选",
                    "collected": "disabled",
                    "cover": "https://img3.doubanio.com/f/fm/c1f6362114965225752341e9291a4b2f39f78cfb/pics/fm/channel_selected_cover.png",
                    "id": -10
                }
            ],
            "group_id": 0,
            "group_name": ""
        },
...
 ]
}

基本上是几个大分组,比如单曲, 风格流派, 语言年代...

歌曲列表

歌曲列表参数比较多, 登录与否主要看header的Authorization字段,在我测试的时候发现和userid基本没有关系... 测试

  • URL: https://api.douban.com/v2/fm/playlist

  • Method: GET

  • Header:

    //未登录的不填

    • Authorization: Bearer 21a0867e86f16fb464e1937b94d44f1w
  • Arguments:

    • channel: 填写对应的channel id

    • from: mainsite

    • pt: 0.0

    • kbps: 128

    • formats: aac

    • alt: json

    • app_name: radio_iphone

    • apikey: 02646d3fb69a52ff072d47bf23cef8fd

    • client: s:mobile|y:iOS 10.2|f:115|d:b88146214e19b8a8244c9bc0e2789da68955234d|e:iPhone7,1|m:appstore

    • client_id: 02646d3fb69a52ff072d47bf23cef8fd

    • icon_cate: xlarge

    • udid: b88146214e19b8a8244c9bc0e2789da68955234d

    • douban_udid: b635779c65b816b13b330b68921c0f8edc049590

    • version: 115

  • Response ( application/json ):

{
    "warning": "user_is_ananymous",
    "r": 0,
    "version_max": 116,
    "is_show_quick_start": 0,
    "song": [
        {
            "albumtitle": "The Princess Diaries 2: Royal Engagement",
            "url": "http://mr3.doubanio.com/764cb746b8dfa264b39aa5513c8bc4fb/0/fm/song/p1439388_128k.mp4",
            "file_ext": "mp4",
            "album": "/subject/1765409/",
            "ssid": "98c4",
            "title": "Because You Live",
            "sid": "1439388",
            "sha256": "fd651e012a7c45bc5c9e582d06c88d44fdb845d6d2ae9b2515343e3eafb0e4a7",
            "status": 0,
            "picture": "http://img3.doubanio.com/lpic/s2837777.jpg",
            "update_time": 1470126128,
            "alert_msg": "",
            "public_time": "2004",
            "singers": [
                {
                    "style": [],
                    "name": "Jesse McCartney",
                    "region": [
                        "美国"
                    ],
                    "name_usual": "Jesse McCartney",
                    "genre": [
                        "Pop"
                    ],
                    "avatar": "http://img7.doubanio.com/img/fmadmin/large/32852.jpg",
                    "related_site_id": 0,
                    "is_site_artist": false,
                    "id": "2558"
                },
                {
                    "style": [],
                    "name": "Various Artists",
                    "region": [
                        "欧美"
                    ],
                    "name_usual": "Various Artists",
                    "genre": [
                        "Pop",
                        "Rock",
                        "Electronic"
                    ],
                    "avatar": "http://img7.doubanio.com/img/fmadmin/large/2118995.jpg",
                    "related_site_id": 0,
                    "is_site_artist": false,
                    "id": "0"
                }
            ],
            "like": 0,
            "artist": "Various Artists / Jesse McCartney",
            "is_royal": false,
            "subtype": "",
            "length": 199,
            "release": {
                "link": "https://douban.fm/album/1765409gb789",
                "id": "1765409",
                "ssid": "b789"
            },
            "aid": "1765409",
            "kbps": "128"
        },
...
  ]
}

列出来的返回字段可能不全,建议点击测试直接看结果。

歌曲操作上报

歌曲操作的上报最为复杂,其参数也比较多

  • URL: https://api.douban.com/v2/fm/playlist

  • Method: GET

  • Header:

    //未登录的不填

    • Authorization: Bearer 21a0867e86f16fb464e1937b94d44f1w
  • Arguments:

参数名 是否必选 参数类型 备注
app_name 必选 string radio_android 固定
version 必选 int 100 固定
user_id 非必选 string user_id 若已登录,则填入
expire 非必选 int expire 若已登录,则填入
token 非必选 string token 若已登录,则填入
sid 非必选 int song id 在需要针对单曲操作时需要
h 非必选 string 最近播放列表 单次报告曲目播放状态,其格式是 |sid:报告类型|sid:报告类型
channel 非必选 int 频道id 获取频道时取得的channel_id
type 必选 string 报告类型 需要调用的接口类型,也是使用下表的报告类型

其中报告类型是以下的一种类型,都是一个字母。

类型 需要参数 含义 报告长度
b sid bye,不再播放,并放回一个新的歌曲列表 长报告
e sid end,当前歌曲播放完毕,但是歌曲队列中还有歌曲 短报告
n new,没有歌曲播放,歌曲队列也没有任何歌曲,需要返回新播放列表 长报告
p playing,歌曲正在播放,队列中还有歌曲,需要返回新的播放列表 长报告
s sid skip,歌曲正在播放,队列中还有歌曲,适用于用户点击下一首 短报告
r sid rate,歌曲正在播放,标记喜欢当前歌曲 短报告
u sid unrate,歌曲正在播放,标记取消喜欢当前歌曲 短报告
  • Response ( application/json ):

所有的这些都会返回一个json字符串,其中都会包括歌曲列表(上面得到的歌曲URL,只会在一定时间内有效,过期之后就不能再访问了,因此猜测每次访问都返回一些歌曲就是想更新一下后面的曲库,因为当前这首不能播了,很可能后面的也不能播)。

r若为1即出错,err里面会写上出错原因,而r0即调用成功。

其中的歌曲列表格式是

{
    "r": 0,
    "version_max": 100,
    "song": [
        {
            "album": "/subject/5952615/",
            "picture": "http://img3.douban.com/mpic/s4616653.jpg",
            "ssid": "e1b2",
            "artist": "Bruno Mars / B.o.B",
            "url": "http://mr3.douban.com/201308250247/4a3de2e8016b5d659821ec76e6a2f35d/view/song/small/p1562725.mp3",
            "company": "EMI",
            "title": "Nothin' On You",
            "rating_avg": 4.04017,
            "length": 267,
            "subtype": "",
            "public_time": "2011",
            "sid": "1562725",
            "aid": "5952615",
            "sha256": "2422b6fa22611a7858060fd9c238e679626b3173bb0d161258b4175d69f17473",
            "kbps": "64",
            "albumtitle": "2011 Grammy Nominees",
            "like": 1
        },
        ...
    ]
}

参数都可以直接从名字看出其意义

  • album 专辑跳转地址
  • picture 专辑图片地址
  • ssid 未知
  • artist 艺术家
  • url 歌曲的URL
  • company 唱片公司
  • title 歌曲名
  • rating_avg 平均分数
  • length 长度
  • subtype 子类型(有些广告的字类型会是T)
  • public_time 出版年份
  • sid 歌曲id
  • aid 专辑id
  • kbps 码率
  • albumtitle 专辑名
  • like 是否已喜欢,0为false,1为true

歌词

  • URL: https://api.douban.com/v2/fm/lyric

  • Method: GET

  • Arguments:

参数名 是否必选 参数类型 备注
sid int 歌曲的sid
ssid string 歌曲的ssid
  • Response (application/json):
{
    "lyric": "歌词正文",
    "name": "歌名",
    "sid": "sid"
}

Note

  • 2017年3月,接口升级为v2。
  • 2016年11月,歌词接口改为了GET,测试了POST已经不可用。
  • 2015年11月,豆瓣关闭了其桌面音乐播放器服务,导致接口不能使用。但将 radio_desktop_win 改为 radio_android 即可使用(#41)。
Clone this wiki locally