Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
加一些防封措施
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawnnnnnn committed Mar 25, 2018
1 parent e3f4540 commit b815d86
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions API.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
最近b站在检测脚本挂机,请慎重考虑是否继续使用该软件,因使用脚本造成封号黑号的请自行承担后果。


3.25:

美化输出,设定延迟,加入查询功能,采用一定措施防止被封。

环境:
------
Expand Down
1 change: 1 addition & 0 deletions bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 9 additions & 4 deletions bilibiliCilent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from bilibili import bilibili
from API import API
import asyncio
import random
from struct import *
Expand Down Expand Up @@ -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)
Expand All @@ -86,7 +87,7 @@ async def ReceiveMessageLoop(self):
else:
continue

def parseDanMu(self, messages):
async def parseDanMu(self, messages):

try:
dic = json.loads(messages)
Expand All @@ -106,14 +107,16 @@ 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)
checklen = response.json()['data']
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:
Expand Down Expand Up @@ -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), "的小电视抽奖")
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit b815d86

Please sign in to comment.