Skip to content

Commit

Permalink
更新登录组件
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsury committed Jul 4, 2020
1 parent d6bccc3 commit 2278006
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if: 'tag IS blank'
env:
global:
- TRAVIS_TAG=v2.2
- TRAVIS_TAG=v2.3
jobs:
include:
-
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2019 Hsury
Copyright (c) 2018-2020 Hsury

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h1 align="center">- Bilibili Toolkit -</h1>

<p align="center">
<img src="https://img.shields.io/badge/version-2020.7.2-green.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/badge/version-2020.7.4-green.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/badge/license-SATA-blue.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/travis/com/Hsury/Bilibili-Toolkit?style=for-the-badge">
</p>
Expand All @@ -20,7 +20,7 @@

|组件 |版本 |描述 |
|--------------------|---------------|------------------------------|
|login |2019/12/22 |登录 |
|login |2020/7/4 |登录 |
|get_user_info |2019/9/15 |获取用户信息 |
|set_privacy |2018/7/24 |修改隐私设置 |
|silver_to_coin |2018/8/8 |银瓜子兑换硬币 |
Expand Down
14 changes: 9 additions & 5 deletions bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
__author__ = "Hsury"
__email__ = "i@hsury.com"
__license__ = "SATA"
__version__ = "2020.7.2"
__version__ = "2020.7.4"

class Bilibili:
app_key = "1d8b6e7d45233436"
app_key = "bca7e84c2d947ac6"
patterns = {
'video': {
'id': 1,
Expand All @@ -65,7 +65,7 @@ class Bilibili:

def __init__(self, https=True, queue=None):
self._session = requests.Session()
self._session.headers.update({'User-Agent': "Mozilla/5.0 BiliDroid/5.51.1 (bbcallen@gmail.com)"})
self._session.headers.update({'User-Agent': "Mozilla/5.0 BiliDroid/6.4.0 (bbcallen@gmail.com) os/android model/M1903F11I mobi_app/android build/6040500 channel/bili innerVer/6040500 osVer/9.0.0 network/2"})
self.__queue = queue
self.get_cookies = lambda: self._session.cookies.get_dict(domain=".bilibili.com")
self.get_csrf = lambda: self.get_cookies().get("bili_jct", "")
Expand Down Expand Up @@ -123,7 +123,7 @@ def __push_to_queue(self, manufacturer, data):

@staticmethod
def calc_sign(param):
salt = "560c52ccd288fed045859ed18bffd973"
salt = "60698ba2f68e01ce44738920a0ffe768"
sign_hash = hashlib.md5()
sign_hash.update(f"{param}{salt}".encode())
return sign_hash.hexdigest()
Expand Down Expand Up @@ -235,7 +235,11 @@ def get_key():
time.sleep(10)
break
elif response['code'] == -449:
time.sleep(1)
self._log("服务繁忙, 尝试使用V3接口登录")
url = f"{self.protocol}://passport.bilibili.com/api/v3/oauth2/login"
param = f"access_key=&actionKey=appkey&appkey={Bilibili.app_key}&build=6040500&captcha=&challenge=&channel=bili&cookies=&device=phone&mobi_app=android&password={parse.quote_plus(base64.b64encode(rsa.encrypt(f'{key_hash}{self.password}'.encode(), pub_key)))}&permission=ALL&platform=android&seccode=&subid=1&ts={int(time.time())}&username={parse.quote_plus(self.username)}&validate="
payload = f"{param}&sign={self.calc_sign(param)}"
headers = {'Content-type': "application/x-www-form-urlencoded"}
response = self._requests("post", url, data=payload, headers=headers)
elif response['code'] == 0 and response['data']['status'] == 0:
for cookie in response['data']['cookie_info']['cookies']:
Expand Down

0 comments on commit 2278006

Please sign in to comment.