import requests import gradio as gr def bv2acid(bvid: str): try: response = requests.get( "https://api.bilibili.com/x/web-interface/view", params={"bvid": bvid}, headers={ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0" }, ) data = response.json()["data"] return data["aid"], data["cid"] except Exception as e: return "Failed to parse aid / cid", f"{e}" if __name__ == "__main__": gr.Interface( fn=bv2acid, inputs=gr.Textbox(label="bvid", show_copy_button=True), outputs=[ gr.Textbox(label="aid", show_copy_button=True), gr.Textbox(label="cid", show_copy_button=True), ], title="Bvid to aid / cid", flagging_mode="never", ).launch()