一些斗鱼TV Web API [Some DouyuTv API]
一些斗鱼tv web api [some douyutv api]
写在最前
去年ti5前开发了,网站需要用到各个直播平台api。不像国外网站twitch那样开放,都有现成的api可用,国内网站都很封闭,对开发者不太友好。本文所涉及api皆抓取自斗鱼ios手机客户端。
首先是不需要登录的api
获取当前全部直播
请求地址:http://capi.douyucdn.cn/api/v1/live?limit=20&offset=0
参数:
limit: 一次获取的个数
offset:起始位置,比如要获取前20个之后的 offset=20
, 下同
返回数据
{ "error": 0, "data": [ { "room_id": "16101", "room_src": "http://rpic.douyucdn.cn/z1602/22/16/16101_160222165702.jpg", "cate_id": "1", "room_name": "微笑: 过节就应该带妹!", "show_status": "1", "subject": "", "show_time": "1456126421", "owner_uid": "391270", "specific_catalog": "weixiao", "specific_status": "1", "vod_quality": "0", "nickname": "微笑", "online": 1075780, "url": "/weixiao", "game_url": "/directory/game/lol", "game_name": "英雄联盟", "child_id": "28", "fans": "936235" } ] }
获取父频道
请求地址:http://capi.douyucdn.cn/api/v1/getcolumnlist
部分返回数据:
{ "error": 0, "data": [ { "cate_id": "1", "cate_name": "游戏", "short_name": "game", "orderdisplay": "1", "is_relate": "1", "is_del": "0", "push_ios": "1", "push_show": "0" }, { "cate_id": "9", "cate_name": "手机游戏", "short_name": "sjyx", "orderdisplay": "2", "is_relate": "1", "is_del": "0", "push_ios": "1", "push_show": "0" } ] }
获取子频道
请求地址:http://capi.douyucdn.cn/api/v1/getcolumndetail?shortname=game
参数:
shortname: 父频道名字,来自上一个请求返回数据中的short_name
部分返回数据:
{ "error": 0, "data": [ { "tag_id": "134", "short_name": "wsm", "tag_name": "玩数码", "pic_name": "7c855c7fa9c8c03697ee61748999d112.jpg", "icon_name": "a3f49c62bd6156b358a275a07a5b95dd.jpg", "orderdisplay": "126", "rank_score": "0", "night_rank_score": "0", "nums": "0", "push_ios": "1", "push_home": "1", "is_game_cate": "0", "cate_id": "3", "is_del": "0", "is_relate": "1", "pic_url": "http://staticlive.douyutv.com/upload/game_cate/7c855c7fa9c8c03697ee61748999d112.jpg", "url": "/directory/game/wsm", "icon_url": "http://staticlive.douyutv.com/upload/game_cate/a3f49c62bd6156b358a275a07a5b95dd.jpg", "count": 15, "count_ios": 8 }, { "tag_id": "136", "short_name": "car", "tag_name": "玩汽车", "pic_name": "6b83cf650fb4ba62881c9c528ab602d5.jpg", "icon_name": "ade2b45ee56831c3b100a436b8c2f624.jpg", "orderdisplay": "127", "rank_score": "0", "night_rank_score": "0", "nums": "0", "push_ios": "1", "push_home": "1", "is_game_cate": "0", "cate_id": "3", "is_del": "0", "is_relate": "1", "pic_url": "http://staticlive.douyutv.com/upload/game_cate/6b83cf650fb4ba62881c9c528ab602d5.jpg", "url": "/directory/game/car", "icon_url": "http://staticlive.douyutv.com/upload/game_cate/ade2b45ee56831c3b100a436b8c2f624.jpg", "count": 4, "count_ios": 2 } ] }
获取父频道所有直播列表
请求地址:http://capi.douyucdn.cn/api/v1/getcolumnroom/<cate_id>?limit=20&offset=0
参数:
cate_id: 父频道id
limit
offset
返回数据:
{ "error": 0, "data": [ { "room_id": "536341", "room_src": "http://rpic.douyucdn.cn/z1602/22/17/536341_160222172043.jpg", "cate_id": "134", "room_name": "22日晚5点30分mwc现场探馆看产品", "show_status": "1", "subject": "", "show_time": "1456132678", "owner_uid": "38598100", "specific_catalog": "", "specific_status": "0", "vod_quality": "0", "nickname": "zol中关村在线", "online": 1969, "child_id": "0" }, { "room_id": "279558", "room_src": "http://rpic.douyucdn.cn/z1602/22/17/279558_160222171918.jpg", "cate_id": "136", "room_name": "[24h斗鱼第一专业车评]陈震yyp选车", "show_status": "1", "subject": "", "show_time": "1455963983", "owner_uid": "18462494", "specific_catalog": "", "specific_status": "0", "vod_quality": "0", "nickname": "金叔2015", "online": 12304, "child_id": "0" } ] }
获取子频道直播列表
请求地址:http://capi.douyucdn.cn/api/v1/live/<tag_id>?&limit=1&offset=0
参数:
tag_id: 子频道id
limit
offset
返回数据:
{ "error": 0, "data": [ { "room_id": "536341", "room_src": "http://rpic.douyucdn.cn/z1602/22/17/536341_160222172043.jpg", "cate_id": "134", "room_name": "22日晚5点30分mwc现场探馆看产品", "show_status": "1", "subject": "", "show_time": "1456132678", "owner_uid": "38598100", "specific_catalog": "", "specific_status": "0", "vod_quality": "0", "nickname": "zol中关村在线", "online": 5700, "url": "/536341", "game_url": "/directory/game/wsm", "game_name": "玩数码", "child_id": "0", "fans": "4084" } ] }
获取房间信息
请求地址:http://capi.douyucdn.cn/api/v1/room/<room_id>?aid=android&client_sys=android&time=<time>&auth=c0a6170a754ca187e8a52a3343ecf273
参数:
room_id: 房间id
time: unix_time/1000
auth: md5("room/"+room_id+"?aid=android&client_sys=android&time="+1231) 注意:time要和上面一致,android也不能改成ios
插曲[不重要可以跳过不看]:为了查找auth的算法,我先是反编译了斗鱼的apk,结果他们把算法藏在了jni里,随后尝试反汇编找出来的share object,无果。然后在斗鱼网页里的javascript里各种找,也没有,不过发现网页里也有一条类似的api,是从swf里发出的。之后去逐个反编译斗鱼网页里的swf,发现核心的core.swf是被加密了的,好在webroom.swf里找到了解密逻辑。解密后找到一个算sign/auth的function,然而没看懂,是一种变形的c。。最后的最后我在github上搜了一下之前解密用的key,发现之前果然有大神找到了auth算法,附链接。拿到算法,玩了一圈发现必须是这个格式才行,把android换成ios就会验证失败。
返回数据:
{ "error": 0, "data": { "room_id": "58428", "room_src": "http://rpic.douyucdn.cn/z1602/23/23/58428_160223234559.jpg", "cate_id": "3", "room_name": "yyf直播间 电子竞技只有锤!", "vod_quality": "0", "show_status": "2", "show_time": "1456221459", "owner_uid": "236231", "specific_catalog": "", "specific_status": "1", "online": 0, // 这个是在线人数,虽然比较虚 "nickname": "yyfyyf", "url": "/58428", "game_url": "/directory/game/dota2", "game_name": "dota2", "game_icon_url": "http://staticlive.douyutv.com/upload/game_cate/bfe845a28fef8106cf645ed3b83aa375.jpg", "rtmp_url": "", //如果再直播会有,我抓这个时候鱼鱼枫已经被怼的下播了 "rtmp_live": "", "rtmp_cdn": "", "rtmp_multi_bitrate": [], "hls_url": "", "servers": [ //这个就比较重要了,这个是弹幕验证服务器列表!弹幕相关的socket加密解密源代码我也找到了。如有需求请留言,我看情况发出来。 { "ip": "119.90.49.93", "port": "8063" }, ....略 ], "use_p2p": "0", "room_dm_delay": 30, "black": [], "show_details": "yyf贴吧: http://tieba.baidu.com/f?kw=yyf&fr=ala0&tpl=5\n新浪微博: http://www.weibo.com/u/2176141495/home?wvr=5", "owner_avatar": "http://uc.douyutv.com/avatar.php?uid=236231&size=big", "cdns": [], "owner_weight": "304.67t", //主播体重 "fans": "492867", //这个应该是关注数。 "gift": [ //一些礼物信息 { "id": "59", "name": "火箭", "pc": "50000", "type": "2", "gx": 5000, "desc": "赠送网站广播并派送出神秘宝箱", "intro": "我们的征途是星辰大海", "ef": 1, "pimg": "http://staticlive.douyutv.com/upload/dygift/447b61f6c0d6890d4490a90d0bdbf8bc.png", "mimg": "http://staticlive.douyutv.com/upload/dygift/ab957377200959761121a3791a54b9b7.png", "cimg": "http://staticlive.douyutv.com/upload/dygift/7dce6b2170eebecf85596b47370217ce.gif", "himg": "http://staticlive.douyutv.com/upload/dygift/7f0643700d331aca31a6f6ea255e323e.gif", "stay_time": 200000, "drgb": "", "urgb": "#732909", "grgb": "#732909", "brgb": "#5861b5", "pdbimg": "http://staticlive.douyutv.com/upload/dygift/005786105dd86e3964732e7fc2fc2085.png", "pdhimg": "http://staticlive.douyutv.com/upload/dygift/6ffb9bc8d35d315943ae117dc788824e.gif", "small_effect_icon": "http://staticlive.douyutv.com/upload/dygift/75e55aae938fc703d977e8c966fef91d.png", "big_effect_icon": "http://staticlive.douyutv.com/upload/dygift/40f964e70faa46923dcc4c4931bbac8f.gif", "pad_big_effect_icon": "http://staticlive.douyutv.com/upload/dygift/ccffe8c6453074a68be1730802203241.gif" }, ...略 ] } }
搜索直播间
请求地址:http://capi.douyucdn.cn/api/v1/searchnew/<search_string>/1?limit=1&offset=0
参数:
search_string: 要搜索的内容,房间id或者房间名
limit:
offset:
返回数据:
{ "error": 0, "data": { "count": 299, "room": [ { "room_id": "73327", "room_src": "http://rpic.douyucdn.cn/z1602/24/02/73327_160224021924.jpg", "cate_id": "134", "room_name": "返回windows写个博客", "show_status": "1", "subject": "", "show_time": "1456244441", "owner_uid": "2154075", "specific_catalog": "dotaonly", "specific_status": "1", "vod_quality": "0", "nickname": "shanex", "online": 5, "child_id": "0", "url": "/dotaonly", "game_url": "/directory/game/wsm", "game_name": "玩数码", "fans": "2490" } ] } }
以上就是我觉着有用的不用登陆可获取api,下面是需要登陆的
需登陆可用的api
获取登陆token
请求地址:http://capi.douyucdn.cn/api/v1/login?username=<user_name>&password=<password_md5>
参数:
user_name: 用户名
password_md5: 密码的md5
返回数据:
{ "error": 0, "data": { "uid": "2154075", "username": "auto_bekeughsjv", "nickname": "shanex", "email": "245****@qq.com", //不知道斗鱼为何要遮蔽邮箱以及下面的电话 "qq": "", "mobile_phone": "150****3913", "phone_status": "1", "email_status": "1", "lastlogin": "1455383420", "avatar": { //头像 "small": "http://uc.douyutv.com/avatar.php?uid=2154075&size=small", "middle": "http://uc.douyutv.com/avatar.php?uid=2154075&size=middle", "big": "http://uc.douyutv.com/avatar.php?uid=2154075&size=big" }, "has_room": "1", //是否是直播 "groupid": "1", "is_own_room": "1", "gold1": "4772", //鱼丸数 "score": "117020", //经验值 "level": { "current": { "lv": 12, "pic": "user12.gif", "mpic": "gold05.png", "name": "黄金5", "pic_url": "http://staticlive.douyutv.com/common/douyu/images/classimg/user12.gif?v=v26185", "score": 100000 }, "next": { "lv": 13, "pic": "user13.gif", "mpic": "gold04.png", "name": "黄金4", "pic_url": "http://staticlive.douyutv.com/common/douyu/images/classimg/user13.gif?v=v26185", "score": 150000 } }, "follow": "35", "ios_gold_switch": 1, "gold": "372.4", //鱼翅 "token": "a**********a", //token! "token_exp": 1457111772 //过期时间,十天 } }
获取个人信息
请求地址:http://capi.douyucdn.cn/api/v1/my_info?token=<token>
参数:
token: 登陆token
返回数据:
和上面的一毛一样。
获取关注列表
请求地址:http://capi.douyucdn.cn/api/v1/remind_list?token=<token>&limit=1&offset=1
参数:
token:
limit:
offset:
请求地址2:http://capi.douyucdn.cn/api/v1/followroom?token=<token>&live=1
参数:
token:
live: 1是正在直播的,0是没开直播的
返回数据:
{ "error": 0, "data": [ { "id": "163643", "room_id": "163643", "room_src": "http://rpic.douyucdn.cn/z1602/24/00/163643_160224001525.jpg", "cate_id": "26", "nickname": "蓝天上的流云", "show_status": "2", "owner_uid": "4773042", "name": "【流云红警】一个人默默地直播,5555~", "game_tag_id": "26", "game_tag_name": "怀旧游戏", "owner": "蓝天上的流云", "owner_avatar_small": "http://uc.douyutv.com/avatar.php?uid=4773042&size=small", "owner_avatar_middle": "http://uc.douyutv.com/avatar.php?uid=4773042&size=middle", "owner_avatar_big": "http://uc.douyutv.com/avatar.php?uid=4773042&size=big", "remind_status": "0", "live_status": "2", "online": 0, "show_time": "1456238974", "fans": "47425" } ] }
取消关注
【post】请求地址:http://capi.douyucdn.cn/api/v1/follow/del
参数:
ids: 要取消关注的列表, e.g.:123,321,132
返回数据:
{ "error": 0, "data": [20360, 184219] }
获取观看历史
请求地址:http://capi.douyucdn.cn/api/v1/history?token=<token>
参数:
token:
返回数据:
{ "error": 0, "data": [ { "room_id": "73327", "room_src": "http://rpic.douyucdn.cn/z1602/24/01/73327_160224015628.jpg", "cate_id": "134", "room_name": "返回windows写个博客", "show_status": "1", "subject": "", "show_time": "1456244441", "owner_uid": "2154075", "specific_catalog": "dotaonly", "specific_status": "1", "vod_quality": "0", "nickname": "shanex", "online": 4, "child_id": "0", "url": "/dotaonly", "game_url": "/directory/game/wsm", "game_name": "玩数码", "rid": "73327", "oid": "2154075", "n": "返回windows写个博客", "lt": "1456246497", "uc": "5", "ls": "1", "on": "shanex", "fans": "2489" } ] }
写在最后
我写这个时候在直播,有个人跑我直播间说我抓这个毫无意义,那我就呵呵了。还有就是不得不感慨一下斗鱼程序猿写代码能力之弱,我翻代码时候甚至看到过这样的代码(time/1000/60)*60
前端js也是很乱。
额,如果有什么问题或者不明,欢迎留言,转载请注明。
我的直播间: 不定时会直播码code
上一篇: PHP数组无限分级数据的层级化处理代码
下一篇: 有趣搞笑的建筑图片