openapi 源码 + token 模板 + nginx 统一入口配置
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import asyncio
|
||||
import sys
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from bilibili_api.login_v2 import QrCodeLogin, QrCodeLoginEvents, QrCodeLoginChannel
|
||||
|
||||
QR_PATH = Path("/home/bilibili/qrcode.png")
|
||||
COOKIE_FILE = Path("/home/bilibili/cookies.txt")
|
||||
CF_QR_PATH = "root@rrrosmontis.icu:/mnt/E/temp/bilibili_qrcode.png"
|
||||
|
||||
async def main():
|
||||
# try TV channel which may have longer expiration
|
||||
login = QrCodeLogin(platform=QrCodeLoginChannel.TV)
|
||||
await login.generate_qrcode()
|
||||
pic = login.get_qrcode_picture()
|
||||
QR_PATH.write_bytes(pic.content)
|
||||
print(f"QR regenerated: {QR_PATH}")
|
||||
|
||||
# sync to cf immediately
|
||||
try:
|
||||
subprocess.run([
|
||||
"sshpass", "-p", "ftA406u@all#2309",
|
||||
"scp", "-P", "10526", str(QR_PATH), CF_QR_PATH
|
||||
], check=True, timeout=10)
|
||||
print("QR synced to cf")
|
||||
except Exception as e:
|
||||
print(f"Sync failed: {e}")
|
||||
|
||||
print("Scan now! Polling every 3s for 3 minutes...")
|
||||
for i in range(60):
|
||||
await asyncio.sleep(3)
|
||||
state = await login.check_state()
|
||||
print(f"[{i*3}s] {state}")
|
||||
if state == QrCodeLoginEvents.DONE:
|
||||
cred = login.get_credential()
|
||||
lines = []
|
||||
if cred.sessdata: lines.append(f"SESSDATA={cred.sessdata}")
|
||||
if cred.bili_jct: lines.append(f"bili_jct={cred.bili_jct}")
|
||||
if cred.buvid3: lines.append(f"buvid3={cred.buvid3}")
|
||||
if cred.dedeuserid: lines.append(f"dedeuserid={cred.dedeuserid}")
|
||||
if cred.ac_time_value: lines.append(f"ac_time_value={cred.ac_time_value}")
|
||||
COOKIE_FILE.write_text("\n".join(lines) + "\n")
|
||||
print("LOGIN SUCCESS")
|
||||
print(f"ac_time_value: {bool(cred.ac_time_value)}")
|
||||
return
|
||||
elif state == QrCodeLoginEvents.TIMEOUT:
|
||||
print("QR TIMEOUT")
|
||||
sys.exit(1)
|
||||
print("POLLING TIMEOUT")
|
||||
sys.exit(1)
|
||||
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user