kakamond commited on
Commit
151551b
·
verified ·
1 Parent(s): b67fe7a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+
4
+
5
+ def bv2acid(bvid: str):
6
+ try:
7
+ response = requests.get(
8
+ "https://api.bilibili.com/x/web-interface/view",
9
+ params={"bvid": bvid},
10
+ headers={
11
+ "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"
12
+ },
13
+ )
14
+ data = response.json()["data"]
15
+ return data["aid"], data["cid"]
16
+
17
+ except Exception as e:
18
+ return "Failed to parse aid / cid", f"{e}"
19
+
20
+
21
+ if __name__ == "__main__":
22
+ gr.Interface(
23
+ fn=bv2acid,
24
+ inputs=gr.Textbox(label="bvid", show_copy_button=True),
25
+ outputs=[
26
+ gr.Textbox(label="aid", show_copy_button=True),
27
+ gr.Textbox(label="cid", show_copy_button=True),
28
+ ],
29
+ title="Bvid to aid / cid",
30
+ flagging_mode="never",
31
+ ).launch()