video_parsers / modules /bvid2acid.py
admin
sync ms
0d6128e
raw
history blame
1.08 kB
import requests
import gradio as gr
from utils import LANG, HEADER
ZH2EN = {
"状态栏": "Status",
"将 Bvid 转为 aid 或 cid": "Bvid to aid / cid",
}
def _L(zh_txt: str):
if LANG:
return ZH2EN[zh_txt]
else:
return zh_txt
def infer(bvid: str):
status = "Success"
aid = cid = None
try:
response = requests.get(
"https://api.bilibili.com/x/web-interface/view",
params={"bvid": bvid},
headers=HEADER,
)
data = response.json()["data"]
aid = data["aid"]
cid = data["cid"]
except Exception as e:
status = f"{e}"
return status, aid, cid
def bv2acid():
return gr.Interface(
fn=infer,
inputs=gr.Textbox(label="bvid"),
outputs=[
gr.Textbox(label=_L("状态栏"), show_copy_button=True),
gr.Textbox(label="aid", show_copy_button=True),
gr.Textbox(label="cid", show_copy_button=True),
],
title=_L("将 Bvid 转为 aid 或 cid"),
flagging_mode="never",
)