返回提交历史
Modified
docs/misc/bvid_desc.md
+13
-13
XFEstudio/bilibili-API-collect
docs/misc/bvid_desc.md: 删除多余的行尾空格
a53d158
代码差异
1 个文件
+13
-13
@@ -26,9 +26,9 @@
26
26
27
27
## 算法概述
28
28
29
~~算法以及程序主要参考[知乎@mcfx的回答](https://www.zhihu.com/question/381784377/answer/1099438784)~~
30
~~实际上该算法并不完整,新的算法参考自[【揭秘】av号转bv号的过程](https://www.bilibili.com/video/BV1N741127Tj)~~
31
实际上上面的算法依然不完整,新的算法参考自 [SocialSisterYi#740](https://github.com/SocialSisterYi/bilibili-API-collect/issues/740)~~来自 B 站某个 JS 文件?~~
29
~~算法以及程序主要参考[知乎@mcfx的回答](https://www.zhihu.com/question/381784377/answer/1099438784)~~
30
~~实际上该算法并不完整,新的算法参考自[【揭秘】av号转bv号的过程](https://www.bilibili.com/video/BV1N741127Tj)~~
31
实际上上面的算法依然不完整,新的算法参考自 [SocialSisterYi#740](https://github.com/SocialSisterYi/bilibili-API-collect/issues/740)~~来自 B 站某个 JS 文件?~~
32
32
33
33
### av->bv算法
34
34
@@ -69,7 +69,7 @@
69
69
70
70
<CodeGroup>
71
71
<CodeGroupItem title="JavaScript">
72
72
73
73
```javascript
74
74
const XOR_CODE = 23442827791579n;
75
75
const MASK_CODE = 2251799813685247n;
@@ -174,7 +174,7 @@ def av2bv(aid: int) -> str:
174
174
175
175
def bv2av(bvid: str) -> int:
176
176
assert bvid[:3] == PREFIX
177
177
178
178
bvid = list(bvid[3:])
179
179
tmp = 0
180
180
for i in range(CODE_LEN):
@@ -207,16 +207,16 @@ func av2bv(avid: UInt64) -> String {
207
207
var bytes: [UInt8] = [66, 86, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48]
208
208
var bvIdx = BV_LEN - 1
209
209
var tmp = (MAX_AID | avid) ^ XOR_CODE
210
210
211
211
while tmp != 0 {
212
212
bytes[bvIdx] = data[Int(tmp % BASE)]
213
213
tmp /= BASE
214
214
bvIdx -= 1
215
215
}
216
216
217
217
bytes.swapAt(3, 9)
218
218
bytes.swapAt(4, 7)
219
219
220
220
return String(decoding: bytes, as: UTF8.self)
221
221
}
222
222
@@ -228,20 +228,20 @@ func bv2av(bvid: String) -> UInt64 {
228
228
fixedBvid = "BV" + bvid
229
229
}
230
230
var bvidArray = Array(fixedBvid.utf8)
231
231
232
232
bvidArray.swapAt(3, 9)
233
233
bvidArray.swapAt(4, 7)
234
234
235
235
let trimmedBvid = String(decoding: bvidArray[3...], as: UTF8.self)
236
236
237
237
var tmp: UInt64 = 0
238
238
239
239
for char in trimmedBvid {
240
240
if let idx = data.firstIndex(of: char.utf8.first!) {
241
241
tmp = tmp * BASE + UInt64(idx)
242
242
}
243
243
}
244
244
245
245
return (tmp & MASK_CODE) ^ XOR_CODE
246
246
}
247
247