File size: 955 Bytes
151551b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()