From 833e17e3151589673df60c81f80b3b51cf94aedb Mon Sep 17 00:00:00 2001 From: Dawnspace <1050596704@qq.com> Date: Mon, 14 May 2018 23:17:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=91=A9=E5=A4=A9=E5=A4=A7=E6=A5=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OnlineHeart.py | 2 +- README.md | 1 - bilibili.py | 34 +++++++++++++--------------------- bilibiliCilent.py | 22 +++++++++------------- conf/bilibili.conf | 12 ++++++------ 5 files changed, 29 insertions(+), 42 deletions(-) diff --git a/OnlineHeart.py b/OnlineHeart.py index 34c033b..fcdadf8 100644 --- a/OnlineHeart.py +++ b/OnlineHeart.py @@ -26,7 +26,7 @@ async def heart_gift(self): # 因为休眠时间差不多,所以放到这里,此为实验性功能 async def draw_lottery(self): black_list = ["测试","test"] - for i in range(68,90): + for i in range(72,90): response = await bilibili().get_lotterylist(i) json_response = await response.json() if json_response['code'] == 0: diff --git a/README.md b/README.md index 40fb03b..9b4ca99 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,6 @@ python3.6 - 使用方法: ------ diff --git a/bilibili.py b/bilibili.py index 9e873e0..3a931fb 100644 --- a/bilibili.py +++ b/bilibili.py @@ -239,16 +239,16 @@ async def get_gift_of_events_app(self, text1, text2, raffleid): response1 = await self.bili_section_get(true_url, params=params, headers=headers) return response1 - async def get_gift_of_TV(self, real_roomid, raffleid): - temp_params = 'access_key=' + self.dic_bilibili['access_key'] + '&actionKey=' + self.dic_bilibili[ - 'actionKey'] + '&appkey=' + self.dic_bilibili['appkey'] + '&build=' + self.dic_bilibili[ - 'build'] + '&device=' + self.dic_bilibili['device'] + '&id=' + str( - raffleid) + '&mobi_app=' + self.dic_bilibili['mobi_app'] + '&platform=' + self.dic_bilibili[ - 'platform'] + '&roomid=' + str( - real_roomid) + '&ts=' + CurrentTime() - sign = self.calc_sign(temp_params) - true_url = 'https://api.live.bilibili.com/AppSmallTV/join?' + temp_params + '&sign=' + sign - response2 = await self.bili_section_get(true_url, headers=self.dic_bilibili['appheaders']) + async def get_gift_of_TV(self,type,real_roomid, raffleid): + url = "https://api.live.bilibili.com/gift/v3/smalltv/join" + data = { + "roomid": real_roomid, + "raffleId": raffleid, + "type": type, + "csrf_token": self.dic_bilibili['csrf'], + "visit_id": "8u0aig7b8100" + } + response2 = await self.bili_section_post(url,data=data,headers=self.dic_bilibili['pcheaders']) return response2 async def get_gift_of_captain(self, roomid, id): @@ -270,18 +270,11 @@ async def get_giftlist_of_events(self, text1): return response async def get_giftlist_of_TV(self, real_roomid): - temp_params = 'access_key=' + self.dic_bilibili['access_key'] + '&actionKey=' + self.dic_bilibili[ - 'actionKey'] + '&appkey=' + self.dic_bilibili['appkey'] + '&build=' + self.dic_bilibili[ - 'build'] + '&device=' + self.dic_bilibili['device'] + \ - '&mobi_app=' + self.dic_bilibili['mobi_app'] + '&platform=' + self.dic_bilibili[ - 'platform'] + '&roomid=' + str( - real_roomid) + '&ts=' + CurrentTime() - sign = self.calc_sign(temp_params) - check_url = 'https://api.live.bilibili.com/AppSmallTV/index?' + temp_params + '&sign=' + sign + url = "https://api.live.bilibili.com/gift/v3/smalltv/check?roomid="+str(real_roomid) headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36", } - response = await self.bili_section_get(check_url, headers=headers) + response = await self.bili_section_get(url, headers=headers) return response async def get_giftlist_of_captain(self, roomid): @@ -324,8 +317,7 @@ async def get_activity_result(self, activity_roomid, activity_raffleid): return response async def get_TV_result(self, TV_roomid, TV_raffleid): - url = "https://api.live.bilibili.com/gift/v2/smalltv/notice?roomid=" + str(TV_roomid) + "&raffleId=" + str( - TV_raffleid) + url = "https://api.live.bilibili.com/gift/v3/smalltv/notice?raffleId="+str(TV_raffleid) headers = { 'Accept': 'application/json, text/plain, */*', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36', diff --git a/bilibiliCilent.py b/bilibiliCilent.py index 68a23c0..0ae960b 100644 --- a/bilibiliCilent.py +++ b/bilibiliCilent.py @@ -11,15 +11,14 @@ import requests import sys -async def handle_1_TV_raffle(num, real_roomid, raffleid): - #print('参与') +async def handle_1_TV_raffle(type,num, real_roomid, raffleid): + await asyncio.sleep(random.uniform(0.5, min(10, num * 1))) - response2 = await bilibili().get_gift_of_TV(real_roomid, raffleid) + response2 = await bilibili().get_gift_of_TV(type,real_roomid, raffleid) Printer().printlist_append(['join_lottery', '小电视', 'user', "参与了房间{:^9}的小电视抽奖".format(real_roomid)], True) json_response2 = await response2.json() Printer().printlist_append( ['join_lottery', '小电视', 'user', "小电视道具抽奖状态: ", json_response2['msg']],True) - # -400不存在 if json_response2['code'] == 0: Statistics().append_to_TVlist(raffleid, real_roomid) else: @@ -55,23 +54,21 @@ async def handle_1_room_TV(real_roomid): if True in result: Printer().printlist_append(['join_lottery', '钓鱼提醒', 'user', "WARNING:检测到房间{:^9}的钓鱼操作".format(real_roomid)], True) else: - # print(True) await bilibili().post_watching_history(real_roomid) response = await bilibili().get_giftlist_of_TV(real_roomid) json_response = await response.json() - checklen = json_response['data']['unjoin'] + checklen = json_response['data']['list'] num = len(checklen) list_available_raffleid = [] for j in range(0, num): - # await asyncio.sleep(random.uniform(0.5, 1)) - resttime = json_response['data']['unjoin'][j]['dtime'] - raffleid = json_response['data']['unjoin'][j]['id'] + raffleid = json_response['data']['list'][j]['raffleId'] + type = json_response['data']['list'][j]['type'] if Statistics().check_TVlist(raffleid): - list_available_raffleid.append(raffleid) + list_available_raffleid.append([type,raffleid]) tasklist = [] num_available = len(list_available_raffleid) - for raffleid in list_available_raffleid: - task = asyncio.ensure_future(handle_1_TV_raffle(num_available, real_roomid, raffleid)) + for k in list_available_raffleid: + task = asyncio.ensure_future(handle_1_TV_raffle(k[0],num_available, real_roomid, k[1])) tasklist.append(task) if tasklist: await asyncio.wait(tasklist, return_when=asyncio.ALL_COMPLETED) @@ -91,7 +88,6 @@ async def handle_1_room_activity(text1, text2): list_available_raffleid = [] for j in range(0, num): # await asyncio.sleep(random.uniform(0.5, 1)) - resttime = checklen[j]['time'] raffleid = checklen[j]['raffleId'] if Statistics().check_activitylist(raffleid): list_available_raffleid.append(raffleid) diff --git a/conf/bilibili.conf b/conf/bilibili.conf index 9ebd2b6..7d0395d 100644 --- a/conf/bilibili.conf +++ b/conf/bilibili.conf @@ -37,14 +37,14 @@ Host = api.live.bilibili.com cookie = [account] -username = -password = +username = +password = [saved-session] -access_key = -cookie = -csrf = -uid = +access_key = +cookie = +csrf = +uid = [types] int = _ChatPort _protocolversion roomid