Skip to content

Commit

Permalink
new: 11.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo2011 committed Jul 20, 2022
1 parent 91f8b2d commit 875ae38
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOGS/v11.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v11.5.1 2022/7/20

## Python

- 修复密码登录小 bug
- Episode 类重构了 get_download_url(#23), get_danmaku_view, get_danmakus, get_danmaku_xml, get_history_danmaku_index。

# v11.5.0 2022/7/19

## Python
Expand Down
23 changes: 16 additions & 7 deletions bilibili_api/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import json
import re
from typing import Union
import uuid
import hashlib
Expand Down Expand Up @@ -186,7 +187,7 @@ def login_with_password(username: str, password: str):
password(str): 密码
Returns:
Credential: 凭据类
Union[Credential, Check]: 如果需要验证,会返回 [`Check`](#check) 类,否则返回 `Credential` 类
"""
api_token = API["password"]["get_token"]
sess = get_session()
Expand All @@ -195,9 +196,11 @@ def login_with_password(username: str, password: str):
key = token_data["data"]["key"]
final_password = encrypt(hash_, key, password)
login_api = API["password"]["login"]
appkey = "bca7e84c2d947ac6"
appsec = "60698ba2f68e01ce44738920a0ffe768"
datas = {
"actionKey": "appkey",
"appkey": "ae57252b0c09105d",
"appkey": appkey,
"build": 6270200,
"captcha": "",
"challenge": "",
Expand All @@ -214,7 +217,7 @@ def login_with_password(username: str, password: str):
"validate": ""
}
form_urlencoded = to_form_urlencoded(datas)
md5_string = form_urlencoded + "c75875c596a69eb55bd119e74b07cfe3"
md5_string = form_urlencoded + appsec
hasher = hashlib.md5(md5_string.encode(encoding='utf-8'))
datas['sign'] = hasher.hexdigest()
login_data = json.loads(
Expand All @@ -224,14 +227,19 @@ def login_with_password(username: str, password: str):
login_api["url"],
data=datas,
headers={
"content-type": "application/x-www-form-urlencoded",
"user-agent": "Mozilla/5.0",
"referer": "https://passport.bilibili.com/login",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0",
"Referer": "https://passport.bilibili.com/login",
},
cookies={
"buvid3": str(uuid.uuid1())
}
)
).text
)
if login_data["code"] == 0:
if login_data['data']['status'] == 2:
return Check(login_data['data']['url'], username)
sessdata = login_data['data']['cookie_info']['cookies'][0]['value']
bili_jct = login_data['data']['cookie_info']['cookies'][1]['value']
dede = login_data['data']['cookie_info']['cookies'][2]['value']
Expand Down Expand Up @@ -484,9 +492,10 @@ class Check:
验证类,如果密码登录需要验证会返回此类
"""

def __init__(self, check_url):
def __init__(self, check_url, username):
self.check_url = check_url
self.now_time = time.perf_counter()
self.phonenumber = None

def set_phone(self, phonenumber):
"""
Expand Down
15 changes: 12 additions & 3 deletions docs/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,17 @@ if mode == 1:
password = input("请输入密码:")
print("正在登录。")
c = login_with_password(username, password)
credential = c
print("登陆成功!")
if isinstance(c, Check):
# 还需验证
phone = input("需要验证。请输入手机号:")
c.set_phone(PhoneNumber(phone, country="+86")) # 默认设置地区为中国大陆
c.send_code()
print("已发送验证码。")
code = input("请输入验证码:")
credential = c.login(code)
print("登录成功!")
else:
credential = c
elif mode == 2:
# 验证码登录
phone = input("请输入手机号:")
Expand All @@ -78,7 +87,7 @@ elif mode == 2:
code = input("请输入验证码:")
c = login_with_sms(PhoneNumber(phone, country="+86"), code)
credential = c
print("登录成功")
print("登录成功")
else:
print("请输入 1/2 !")
exit()
Expand Down
42 changes: 41 additions & 1 deletion docs/modules/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $ sudo apt-get install python3-tk

密码登录。

**Returns:** Credential: 凭据类
**Returns:** Union[Credential, Check]: 如果需要验证,会返回 [`Check`](#check) 类,否则返回 `Credential`

## def send_sms()

Expand All @@ -121,3 +121,43 @@ $ sudo apt-get install python3-tk
验证码登录

**Returns:** Credential 凭据类

---

## <span id="check"> class Check </span>

### Functions

#### def \_\_init\_\_()

| name | type | description |
| - | - | - |
| check_url | string | 验证网址 |

#### def set_phone()

设置手机号

| name | type | description |
| - | - | - |
| phonenumber | PhoneNumber | 手机号类 |

**Returns:** None

#### def send_code()

发送验证码

**Returns:** None

#### def login()

| name | type | description |
| - | - | - |
| code | string | 验证码 |

登录

**Returns:** Credential 凭据类

---
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='bilibili-api-python',
version='11.5.0',
version='11.5.1',
license='GPLv3+',
author='MoyuScript, Nemo2011',
description='原 bilibili-api。哔哩哔哩的各种 API 调用便捷整合(视频、动态、直播等),另外附加一些常用的功能。',
Expand Down

0 comments on commit 875ae38

Please sign in to comment.