From b815d86b72db729173d36d80d3b8efe17844d35e Mon Sep 17 00:00:00 2001 From: Dawnspace <1050596704@qq.com> Date: Sun, 25 Mar 2018 21:20:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=B8=80=E4=BA=9B=E9=98=B2=E5=B0=81?= =?UTF-8?q?=E6=8E=AA=E6=96=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API.py | 4 ++-- README.md | 3 +++ bilibili.py | 1 + bilibiliCilent.py | 13 +++++++++---- login.py | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/API.py b/API.py index 0430e0e..da62df7 100644 --- a/API.py +++ b/API.py @@ -19,8 +19,8 @@ def post_watching_history(csrf_token, room_id): "csrf_token": csrf_token } url = "https://api.live.bilibili.com/room/v1/Room/room_entry_action" - requests.post(url, data=data, headers=bilibili.pcheaders) - # print(response.json()) + response = requests.post(url, data=data, headers=bilibili.pcheaders) + #print(response.json()) return 0 def get_bag_list(): diff --git a/README.md b/README.md index a095652..a3e3ffc 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,9 @@ 最近b站在检测脚本挂机,请慎重考虑是否继续使用该软件,因使用脚本造成封号黑号的请自行承担后果。 +3.25: + + 美化输出,设定延迟,加入查询功能,采用一定措施防止被封。 环境: ------ diff --git a/bilibili.py b/bilibili.py index ef0b69b..08e7e87 100644 --- a/bilibili.py +++ b/bilibili.py @@ -8,6 +8,7 @@ class bilibili(): app_secret = '560c52ccd288fed045859ed18bffd973' access_key = "" cookie = "" + csrf = "" pcheaders = { 'Accept': 'application/json, text/plain, */*', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36', diff --git a/bilibiliCilent.py b/bilibiliCilent.py index 7389d54..aa9b4ca 100644 --- a/bilibiliCilent.py +++ b/bilibiliCilent.py @@ -1,4 +1,5 @@ from bilibili import bilibili +from API import API import asyncio import random from struct import * @@ -75,7 +76,7 @@ async def ReceiveMessageLoop(self): messages = tmp.decode('utf-8') except: continue - self.parseDanMu(messages) + await self.parseDanMu(messages) continue elif num == 5 or num == 6 or num == 7: tmp = await self._reader.read(num2) @@ -86,7 +87,7 @@ async def ReceiveMessageLoop(self): else: continue - def parseDanMu(self, messages): + async def parseDanMu(self, messages): try: dic = json.loads(messages) @@ -106,6 +107,8 @@ def parseDanMu(self, messages): } text1 = dic['real_roomid'] text2 = dic['url'] + await asyncio.sleep(random.uniform(3, 5)) + API.post_watching_history(bilibili.csrf,text1) url = 'http://api.live.bilibili.com/activity/v1/Raffle/check?roomid=' + str(text1) print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "检测到房间", str(text1).center(9), "的活动抽奖") response = requests.get(url, headers=headers) @@ -113,7 +116,7 @@ def parseDanMu(self, messages): num = len(checklen) while num != 0: for j in range(0,num): - time.sleep(0.5) + await asyncio.sleep(random.uniform(0.5, 1)) resttime = response.json()['data'][j]['time'] raffleid = response.json()['data'][j]['raffleId'] if raffleid not in bilibili.activity_raffleid_list: @@ -165,6 +168,8 @@ def parseDanMu(self, messages): params = temp_params + self.app_secret hash = hashlib.md5() hash.update(params.encode('utf-8')) + await asyncio.sleep(random.uniform(3, 5)) + API.post_watching_history(bilibili.csrf,real_roomid) check_url = 'https://api.live.bilibili.com/AppSmallTV/index?' + temp_params + '&sign=' + str( hash.hexdigest()) print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "监测到房间", str(real_roomid).center(9), "的小电视抽奖") @@ -181,7 +186,7 @@ def parseDanMu(self, messages): num = len(checklen) while num != 0: for j in range(0,num): - time.sleep(0.5) + await asyncio.sleep(random.uniform(0.5, 1)) resttime = response.json()['data']['unjoin'][j]['dtime'] raffleid = response.json()['data']['unjoin'][j]['id'] if raffleid not in bilibili.TV_raffleid_list: diff --git a/login.py b/login.py index 6abf968..3945b54 100644 --- a/login.py +++ b/login.py @@ -45,7 +45,7 @@ def success(self): cookie_format = "" for i in range(0, len(cookie)): cookie_format = cookie_format + cookie[i]['name'] + "=" + cookie[i]['value'] + ";" - + bilibili.csrf = cookie[0]['value'] bilibili.access_key = access_key bilibili.cookie = cookie_format bilibili.pcheaders = {