Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #719

Merged
merged 26 commits into from
Mar 18, 2024
Merged

Dev #719

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f7de473
feat: active buvid3
Nemo2011 Feb 8, 2024
2ac5d65
docs: upd README.md
Nemo2011 Feb 10, 2024
1c47a2f
chore(deps): update tqdm requirement from ~=4.66.1 to ~=4.66.2
dependabot[bot] Feb 12, 2024
116db78
Merge pull request #679 from Nemo2011/dependabot/pip/dev/tqdm-approx-…
z0z0r4 Feb 12, 2024
be6a4a4
fix: [新功能] check_qrcode_events接口失效 #684
Nemo2011 Feb 16, 2024
55a8b22
chore: Merge branch 'dev' of https://github.com/Nemo2011/bilibili-api…
Nemo2011 Feb 16, 2024
1f0236e
fix: Only show the name under license field (since classifier include…
TimG233 Feb 22, 2024
89d089b
fix: update active_buvid3
Nemo2011 Feb 24, 2024
8294f14
feat: 自定义 Credential Cookies
z0z0r4 Feb 24, 2024
f3ed84e
Merge pull request #693 from z0z0r4/dev
z0z0r4 Feb 24, 2024
9176a11
Merge pull request #689 from TimG233/pyproject_fix
z0z0r4 Feb 24, 2024
fd283ec
fix: wtf the has_more
z0z0r4 Feb 24, 2024
af5cd56
Merge pull request #694 from z0z0r4/dev
z0z0r4 Feb 24, 2024
eef3d1f
fix: active buvid3
Nemo2011 Feb 25, 2024
53d0ff6
修复 login.login_with_key 返回的值没有 data 字段引起的 bug
liaokongVFX Mar 5, 2024
70d492d
Merge pull request #700 from liaokongVFX/fix-bug
z0z0r4 Mar 7, 2024
0272d9c
fix: video_uploader.py
z0z0r4 Mar 11, 2024
1260fa8
Fix typo in video_uploader.py
valkjsaaa Mar 11, 2024
9ab1df3
Pass source in meta to dict for upload
valkjsaaa Mar 11, 2024
8d02207
Avoid shadowing lan parameter in subtitle posting
valkjsaaa Mar 11, 2024
41a6ae4
Merge pull request #710 from valkjsaaa/patch-3
z0z0r4 Mar 11, 2024
71acda9
Merge pull request #706 from valkjsaaa/patch-1
z0z0r4 Mar 11, 2024
6b01816
Update video_uploader.py
z0z0r4 Mar 11, 2024
cba07a9
Merge pull request #709 from valkjsaaa/patch-2
z0z0r4 Mar 11, 2024
166927b
Fix video upload and update
valkjsaaa Mar 12, 2024
5e84161
Merge pull request #712 from valkjsaaa/patch-4
z0z0r4 Mar 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bilibili_api/data/api/credential.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
"refresh_token": "在刷新前 localStorage 中的ac_time_value获取,并非刷新后返回的值"
},
"comment": "确认刷新"
},
"active": {
"url": "https://api.bilibili.com/x/internal/gaia-gateway/ExClimbWuzhi",
"method": "POST",
"verify": false,
"json_body": true,
"data": "see https://github.com/SocialSisterYi/bilibili-API-collect/issues/933",
"comment": "激活 buvid3"
}
}
}
17 changes: 17 additions & 0 deletions bilibili_api/exceptions/ExClimbWuzhiException.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
bilibili_api.exceptions.ExClimbWuzhiException

ExClimbWuzhi 失败异常
"""

from .ApiException import ApiException


class ExClimbWuzhiException(ApiException):
"""
ExClimbWuzhi 失败异常
"""

def __init__(self, code: int, msg: str):
super().__init__()
self.msg = f"ExClimbWuzhi 失败,信息: {code} - {msg}"
1 change: 1 addition & 0 deletions bilibili_api/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
from .DynamicExceedImagesException import *
from .CredentialNoAcTimeValueException import *
from .StatementException import *
from .ExClimbWuzhiException import *
2 changes: 1 addition & 1 deletion bilibili_api/login_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def check_qrcode_events(login_key: str) -> Tuple[QrCodeLoginEvents, Union[str, C
elif events["code"] == 86038:
return QrCodeLoginEvents.TIMEOUT, events["message"]
elif events["code"] == 0:
url: str = events["data"]["url"]
url: str = events["url"]
cookies_list = url.split("?")[1].split("&")
sessdata = ""
bili_jct = ""
Expand Down
1 change: 0 additions & 1 deletion bilibili_api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@ async def get_dynamics_new(self, offset: int = "") -> dict:
Returns:
dict: 调用接口返回的内容。
"""
self.credential.raise_for_no_sessdata()
api = API["info"]["dynamic_new"]
params = {
"host_mid": self.__uid,
Expand Down
12 changes: 12 additions & 0 deletions bilibili_api/utils/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(
buvid3: Union[str, None] = None,
dedeuserid: Union[str, None] = None,
ac_time_value: Union[str, None] = None,
**kwargs
) -> None:
"""
各字段获取方式查看:https://nemo2011.github.io/bilibili-api/#/get-credential.md
Expand All @@ -43,6 +44,9 @@ def __init__(
dedeuserid (str | None, optional): 浏览器 Cookies 中的 DedeUserID 字段值. Defaults to None.

ac_time_value (str | None, optional): 浏览器 Cookies 中的 ac_time_value 字段值. Defaults to None.


其他 Cookie 参数可以直接填入,优先级低于上述参数。
"""
self.sessdata = (
None
Expand All @@ -56,6 +60,9 @@ def __init__(
self.dedeuserid = dedeuserid
self.ac_time_value = ac_time_value

for key, value in kwargs.items():
setattr(self, key, value)

def get_cookies(self) -> dict:
"""
获取请求 Cookies 字典
Expand All @@ -71,6 +78,11 @@ def get_cookies(self) -> dict:
}
if self.dedeuserid:
cookies.update({"DedeUserID": self.dedeuserid})

# 填入所有其他参数
for key, value in self.__dict__.items():
if key not in cookies and value is not None:
cookies[key] = value
return cookies

def has_dedeuserid(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions bilibili_api/utils/credential_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ async def refresh_cookies(credential: Credential) -> Credential:
bili_jct=resp.cookies["bili_jct"],
dedeuserid=resp.cookies["DedeUserID"],
ac_time_value=resp.json()["data"]["refresh_token"],
**credential.__dict__.items(),
)
await confirm_refresh(credential, new_credential)
return new_credential
Expand Down
293 changes: 293 additions & 0 deletions bilibili_api/utils/exclimbwuzhi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
import time
import random
import struct
import io
import json


MOD = 1 << 64


def get_time_milli() -> int:
return int(time.time() * 1000)


def rotate_left(x: int, k: int) -> int:
bin_str = bin(x)[2:].rjust(64, "0")
return int(bin_str[k:] + bin_str[:k], base=2)


def gen_uuid_infoc() -> str:
t = get_time_milli() % 100000
mp = list("123456789ABCDEF") + ["10"]
pck = [8, 4, 4, 4, 12]
gen_part = lambda x: "".join([random.choice(mp) for _ in range(x)])
return "-".join([gen_part(l) for l in pck]) + str(t).ljust(5, "0") + "infoc"


def gen_b_lsid() -> str:
ret = ""
for _ in range(8):
ret += hex(random.randint(0, 15))[2:].upper()
ret = f"{ret}_{hex(get_time_milli())[2:].upper()}"
return ret


def gen_buvid_fp(key: str, seed: int):
source = io.BytesIO(bytes(key, "ascii"))
m = murmur3_x64_128(source, seed)
return "{}{}".format(hex(m & (MOD - 1))[2:], hex(m >> 64)[2:])


def murmur3_x64_128(source: io.BufferedIOBase, seed: int) -> str:
C1 = 0x87C3_7B91_1142_53D5
C2 = 0x4CF5_AD43_2745_937F
C3 = 0x52DC_E729
C4 = 0x3849_5AB5
R1, R2, R3, M = 27, 31, 33, 5
h1, h2 = seed, seed
processed = 0
while 1:
read = source.read(16)
processed += len(read)
if len(read) == 16:
k1 = struct.unpack("<q", read[:8])[0]
k2 = struct.unpack("<q", read[8:])[0]
h1 ^= rotate_left(k1 * C1 % MOD, R2) * C2 % MOD
h1 = ((rotate_left(h1, R1) + h2) * M + C3) % MOD
h2 ^= rotate_left(k2 * C2 % MOD, R3) * C1 % MOD
h2 = ((rotate_left(h2, R2) + h1) * M + C4) % MOD
elif len(read) == 0:
h1 ^= processed
h2 ^= processed
h1 = (h1 + h2) % MOD
h2 = (h2 + h1) % MOD
h1 = fmix64(h1)
h2 = fmix64(h2)
h1 = (h1 + h2) % MOD
h2 = (h2 + h1) % MOD
return (h2 << 64) | h1
else:
k1 = 0
k2 = 0
if len(read) >= 15:
k2 ^= int(read[14]) << 48
if len(read) >= 14:
k2 ^= int(read[13]) << 40
if len(read) >= 13:
k2 ^= int(read[12]) << 32
if len(read) >= 12:
k2 ^= int(read[11]) << 24
if len(read) >= 11:
k2 ^= int(read[10]) << 16
if len(read) >= 10:
k2 ^= int(read[9]) << 8
if len(read) >= 9:
k2 ^= int(read[8])
k2 = rotate_left(k2 * C2 % MOD, R3) * C1 % MOD
h2 ^= k2
if len(read) >= 8:
k1 ^= int(read[7]) << 56
if len(read) >= 7:
k1 ^= int(read[6]) << 48
if len(read) >= 6:
k1 ^= int(read[5]) << 40
if len(read) >= 5:
k1 ^= int(read[4]) << 32
if len(read) >= 4:
k1 ^= int(read[3]) << 24
if len(read) >= 3:
k1 ^= int(read[2]) << 16
if len(read) >= 2:
k1 ^= int(read[1]) << 8
if len(read) >= 1:
k1 ^= int(read[0])
k1 = rotate_left(k1 * C1 % MOD, R2) * C2 % MOD
h1 ^= k1


def fmix64(k: int) -> int:
C1 = 0xFF51_AFD7_ED55_8CCD
C2 = 0xC4CE_B9FE_1A85_EC53
R = 33
tmp = k
tmp ^= tmp >> R
tmp = tmp * C1 % MOD
tmp ^= tmp >> R
tmp = tmp * C2 % MOD
tmp ^= tmp >> R
return tmp


def get_payload(uuid: str) -> str:
content = {
"3064": 1,
"5062": get_time_milli(),
"03bf": "https%3A%2F%2Fwww.bilibili.com%2F",
"39c8": "333.788.fp.risk",
"34f1": "",
"d402": "",
"654a": "",
"6e7c": "839x959",
"3c43": {
"2673": 0,
"5766": 24,
"6527": 0,
"7003": 1,
"807e": 1,
"b8ce": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3 Safari/605.1.15",
"641c": 0,
"07a4": "en-US",
"1c57": "not available",
"0bd0": 8,
"748e": [900, 1440],
"d61f": [875, 1440],
"fc9d": -480,
"6aa9": "Asia/Shanghai",
"75b8": 1,
"3b21": 1,
"8a1c": 0,
"d52f": "not available",
"adca": "MacIntel",
"80c9": [
[
"PDF Viewer",
"Portable Document Format",
[["application/pdf", "pdf"], ["text/pdf", "pdf"]],
],
[
"Chrome PDF Viewer",
"Portable Document Format",
[["application/pdf", "pdf"], ["text/pdf", "pdf"]],
],
[
"Chromium PDF Viewer",
"Portable Document Format",
[["application/pdf", "pdf"], ["text/pdf", "pdf"]],
],
[
"Microsoft Edge PDF Viewer",
"Portable Document Format",
[["application/pdf", "pdf"], ["text/pdf", "pdf"]],
],
[
"WebKit built-in PDF",
"Portable Document Format",
[["application/pdf", "pdf"], ["text/pdf", "pdf"]],
],
],
"13ab": "0dAAAAAASUVORK5CYII=",
"bfe9": "QgAAEIQAACEIAABCCQN4FXANGq7S8KTZayAAAAAElFTkSuQmCC",
"a3c1": [
"extensions:ANGLE_instanced_arrays;EXT_blend_minmax;EXT_color_buffer_half_float;EXT_float_blend;EXT_frag_depth;EXT_shader_texture_lod;EXT_texture_compression_bptc;EXT_texture_compression_rgtc;EXT_texture_filter_anisotropic;EXT_sRGB;KHR_parallel_shader_compile;OES_element_index_uint;OES_fbo_render_mipmap;OES_standard_derivatives;OES_texture_float;OES_texture_float_linear;OES_texture_half_float;OES_texture_half_float_linear;OES_vertex_array_object;WEBGL_color_buffer_float;WEBGL_compressed_texture_astc;WEBGL_compressed_texture_etc;WEBGL_compressed_texture_etc1;WEBGL_compressed_texture_pvrtc;WEBKIT_WEBGL_compressed_texture_pvrtc;WEBGL_compressed_texture_s3tc;WEBGL_compressed_texture_s3tc_srgb;WEBGL_debug_renderer_info;WEBGL_debug_shaders;WEBGL_depth_texture;WEBGL_draw_buffers;WEBGL_lose_context;WEBGL_multi_draw",
"webgl aliased line width range:[1, 1]",
"webgl aliased point size range:[1, 511]",
"webgl alpha bits:8",
"webgl antialiasing:yes",
"webgl blue bits:8",
"webgl depth bits:24",
"webgl green bits:8",
"webgl max anisotropy:16",
"webgl max combined texture image units:32",
"webgl max cube map texture size:16384",
"webgl max fragment uniform vectors:1024",
"webgl max render buffer size:16384",
"webgl max texture image units:16",
"webgl max texture size:16384",
"webgl max varying vectors:30",
"webgl max vertex attribs:16",
"webgl max vertex texture image units:16",
"webgl max vertex uniform vectors:1024",
"webgl max viewport dims:[16384, 16384]",
"webgl red bits:8",
"webgl renderer:WebKit WebGL",
"webgl shading language version:WebGL GLSL ES 1.0 (1.0)",
"webgl stencil bits:0",
"webgl vendor:WebKit",
"webgl version:WebGL 1.0",
"webgl unmasked vendor:Apple Inc.",
"webgl unmasked renderer:Apple GPU",
"webgl vertex shader high float precision:23",
"webgl vertex shader high float precision rangeMin:127",
"webgl vertex shader high float precision rangeMax:127",
"webgl vertex shader medium float precision:23",
"webgl vertex shader medium float precision rangeMin:127",
"webgl vertex shader medium float precision rangeMax:127",
"webgl vertex shader low float precision:23",
"webgl vertex shader low float precision rangeMin:127",
"webgl vertex shader low float precision rangeMax:127",
"webgl fragment shader high float precision:23",
"webgl fragment shader high float precision rangeMin:127",
"webgl fragment shader high float precision rangeMax:127",
"webgl fragment shader medium float precision:23",
"webgl fragment shader medium float precision rangeMin:127",
"webgl fragment shader medium float precision rangeMax:127",
"webgl fragment shader low float precision:23",
"webgl fragment shader low float precision rangeMin:127",
"webgl fragment shader low float precision rangeMax:127",
"webgl vertex shader high int precision:0",
"webgl vertex shader high int precision rangeMin:31",
"webgl vertex shader high int precision rangeMax:30",
"webgl vertex shader medium int precision:0",
"webgl vertex shader medium int precision rangeMin:31",
"webgl vertex shader medium int precision rangeMax:30",
"webgl vertex shader low int precision:0",
"webgl vertex shader low int precision rangeMin:31",
"webgl vertex shader low int precision rangeMax:30",
"webgl fragment shader high int precision:0",
"webgl fragment shader high int precision rangeMin:31",
"webgl fragment shader high int precision rangeMax:30",
"webgl fragment shader medium int precision:0",
"webgl fragment shader medium int precision rangeMin:31",
"webgl fragment shader medium int precision rangeMax:30",
"webgl fragment shader low int precision:0",
"webgl fragment shader low int precision rangeMin:31",
"webgl fragment shader low int precision rangeMax:30",
],
"6bc5": "Apple Inc.~Apple GPU",
"ed31": 0,
"72bd": 0,
"097b": 0,
"52cd": [0, 0, 0],
"a658": [
"Andale Mono",
"Arial",
"Arial Black",
"Arial Hebrew",
"Arial Narrow",
"Arial Rounded MT Bold",
"Arial Unicode MS",
"Comic Sans MS",
"Courier",
"Courier New",
"Geneva",
"Georgia",
"Helvetica",
"Helvetica Neue",
"Impact",
"LUCIDA GRANDE",
"Microsoft Sans Serif",
"Monaco",
"Palatino",
"Tahoma",
"Times",
"Times New Roman",
"Trebuchet MS",
"Verdana",
"Wingdings",
"Wingdings 2",
"Wingdings 3",
],
"d02f": "124.04345259929687",
},
"54ef": '{"in_new_ab":true,"ab_version":{"remove_back_version":"REMOVE","login_dialog_version":"V_PLAYER_PLAY_TOAST","open_recommend_blank":"SELF","storage_back_btn":"HIDE","call_pc_app":"FORBID","clean_version_old":"GO_NEW","optimize_fmp_version":"LOADED_METADATA","for_ai_home_version":"V_OTHER","bmg_fallback_version":"DEFAULT","ai_summary_version":"SHOW","weixin_popup_block":"ENABLE","rcmd_tab_version":"DISABLE","in_new_ab":true},"ab_split_num":{"remove_back_version":11,"login_dialog_version":43,"open_recommend_blank":90,"storage_back_btn":87,"call_pc_app":47,"clean_version_old":46,"optimize_fmp_version":28,"for_ai_home_version":38,"bmg_fallback_version":86,"ai_summary_version":466,"weixin_popup_block":45,"rcmd_tab_version":90,"in_new_ab":0},"pageVersion":"new_video","videoGoOldVersion":-1}',
"8b94": "https%3A%2F%2Fwww.bilibili.com%2F",
"df35": uuid,
"07a4": "en-US",
"5f45": None,
"db46": 0,
}
return json.dumps(
{"payload": json.dumps(content, separators=(",", ":"))},
separators=(",", ":"),
)
Loading
Loading