Skip to content

Instantly share code, notes, and snippets.

@abc1763613206
Last active August 31, 2024 01:43
Show Gist options
  • Save abc1763613206/b8afbb88849835f064f74e652fdb16c5 to your computer and use it in GitHub Desktop.
Save abc1763613206/b8afbb88849835f064f74e652fdb16c5 to your computer and use it in GitHub Desktop.
BVID Validate
import requests
import json
import random
Back_URL = 'https://api.bilibili.com/x/web-interface/archive/stat?aid='
headers = {
'Cookie': "Replace Me With REAL COOKIE" ,
'Pragma': 'no-cache',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
}
table='fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'
tr={}
for i in range(58):
tr[table[i]]=i
s=[11,10,3,8,4,6]
xor=177451812
add=8728348608
def dec(x):
r=0
for i in range(6):
r+=tr[x[s[i]]]*58**i
return (r-add)^xor
def enc(x):
x=(x^xor)+add
r=list('BV1 4 1 7 ')
for i in range(6):
r[s[i]]=table[x//58**i%58]
return ''.join(r)
def checkv(x,y):
if str(enc(int(x))) == str(y):
return "Vaild √"
else:
return "Not Vaild ×"
for i in range(0,50000):
n = random.randint(100,9999999)
resp = requests.get(Back_URL+str(n),headers=headers)
#print(resp.text)
res = json.loads(resp.text)
if int(res["code"]==0):
print("{} {} {}".format(res["data"]["aid"],res["data"]["bvid"],str(checkv(res["data"]["aid"],res["data"]["bvid"]))))
@Revincx
Copy link

Revincx commented Mar 24, 2020

围观,竟然没有评论~
溜了溜了

@elegantYU
Copy link

溜了溜了

@QiuYuMiao
Copy link

溜了溜了

@e101406
Copy link

e101406 commented Mar 24, 2020

溜了溜了

@hnyqwqgh
Copy link

溜了溜了

@hui-shao
Copy link

留个爪印

@CberYellowstone
Copy link

留个爪印

怎么感觉你有些眼熟???

@hui-shao
Copy link

留个爪印

怎么感觉你有些眼熟???

aha 被发现了

@Xzonn
Copy link

Xzonn commented Mar 24, 2020

valid是不是打错成vaild了……

@FBshtml
Copy link

FBshtml commented Mar 25, 2020

没人?

@qinlili23333
Copy link

围观

@Canscx
Copy link

Canscx commented Mar 26, 2020

举个爪

@littleblacklb
Copy link

溜了溜了~

@SunHIAhia
Copy link

溜了溜了

@sparrowhe
Copy link

溜了溜了

@iLoveElysia
Copy link

吃瓜

@zwzheng45
Copy link

溜了溜了

@dxl1236
Copy link

dxl1236 commented Apr 6, 2020

溜了溜了

@Joe2030
Copy link

Joe2030 commented Apr 8, 2020

溜了溜了

@heklmbbsna
Copy link

tql

@Misaka17032
Copy link

留名

@lieternity
Copy link

溜了溜了

@zl7261
Copy link

zl7261 commented Aug 21, 2021

复制了下代码到js里面.
才知道python的运算符优先级 ** 比 //高

Math.floor(x / Math.pow(58, i)) % 58

@Chr0mium24
Copy link

溜了溜了

@Nathaniel-Wu
Copy link

Nathaniel-Wu commented Feb 23, 2024

这个转换方法似乎对一些比较新的视频失效了,可能是中间哪里位数不够。
比如av1650838668实际对应BV1Sj421D7q6,但是enc(1650838668)结果是'BV1sc4C1N7Ya'dec('BV1Sj421D7q6')结果是-496644980.

编辑:
找到另一个repo里的算法是可用的:Prcuvu/bilibili-aid-bvid-converter。不过他因为写的是Win32程序,读起来略繁琐。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment