Spaces:
Running
Running
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", | |
) | |