Spaces:
Running
Running
File size: 1,055 Bytes
0d6128e bf7d327 0d6128e bf7d327 0d6128e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import requests
import gradio as gr
from utils import EN_US, HEADER
ZH2EN = {
"状态栏": "Status",
"将 Bvid 转为 aid 或 cid": "Bvid to aid / cid",
}
def _L(zh_txt: str):
return ZH2EN[zh_txt] if EN_US else 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",
)
|