一些鬥魚TV Web API [Some DouyuTv API] 寫在最前 去年TI5前開發了dotaonly.com,網站需要用到各個直播平臺API。不像國外網站Twitch那樣開放,都有現成的API可用,國內網站都很封閉,對開發者不太友好。本文所涉及API皆抓取自鬥魚IOS手機客戶端。 首先是 ...
一些鬥魚TV Web API [Some DouyuTv API]
寫在最前
去年TI5前開發了dotaonly.com,網站需要用到各個直播平臺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"
}
]
}
12345678910111213141516171819202122232425
獲取父頻道
請求地址: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"
}
]
}
12345678910111213141516171819202122232425
獲取子頻道
請求地址: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
}
]
}
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
獲取父頻道所有直播列表
請求地址: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"
}
]
}
12345678910111213141516171819202122232425262728293031323334353637
獲取子頻道直播列表
請求地址: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"
}
]
}
12345678910111213141516171819202122232425
獲取房間信息
請求地址: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"
},
...略
]
}
}
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
搜索直播間
請求地址: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"
}
]
}
}
12345678910111213141516171819202122232425262728
以上就是我覺著有用的不用登陸可獲取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 //過期時間,十天
}
}
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
獲取個人信息
請求地址:http://capi.douyucdn.cn/api/v1/my_info?token=<token>
參數:
token: 登陸token
返回數據:
和上面的一毛一樣。
1
獲取關註列表
請求地址: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"
}
]
}
1234567891011121314151617181920212223242526
取消關註
【POST】請求地址:http://capi.douyucdn.cn/api/v1/follow/del
參數:
ids: 要取消關註的列表, e.g.:123,321,132
返回數據:
{
"error": 0,
"data": [20360, 184219]
}
1234
獲取觀看歷史
請求地址: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"
}
]
}
1234567891011121314151617181920212223242526272829303132
寫在最後
我寫這個時候在直播,有個人跑我直播間說我抓這個毫無意義,那我就呵呵了。還有就是不得不感慨一下鬥魚程式猿寫代碼能力之弱,我翻代碼時候甚至看到過這樣的代碼(time/1000/60)*60
前端js也是很亂。
額,如果有什麼問題或者不明,歡迎留言,轉載請註明。
我的直播間: 鬥魚 不定時會直播碼code