Skip to content

Commit

Permalink
docs aid_bvid_transformer.py
Browse files Browse the repository at this point in the history
为什么注释被吞了...
  • Loading branch information
z0z0r4 authored Feb 1, 2024
1 parent 4160cdc commit 9b7a8de
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bilibili_api/utils/aid_bvid_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
PREFIX = "BV1"

def bvid2aid(bvid: str) -> int:
"""
BV 号转 AV 号。
Args:
bvid (str): BV 号。
Returns:
int: AV 号。
"""
bvid = list(bvid)
bvid[3], bvid[9] = bvid[9], bvid[3]
bvid[4], bvid[7] = bvid[7], bvid[4]
Expand All @@ -28,6 +35,13 @@ def bvid2aid(bvid: str) -> int:
return (tmp & MASK_CODE) ^ XOR_CODE

def aid2bvid(aid: int) -> str:
"""
AV 号转 BV 号。
Args:
aid (int): AV 号。
Returns:
str: BV 号。
"""
bytes = [b'B', b'V', b'1', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0']
bv_idx = BV_LEN - 1
tmp = (MAX_AID | aid) ^ XOR_CODE
Expand Down

0 comments on commit 9b7a8de

Please sign in to comment.