Spaces:
Running
Running
admin
commited on
Commit
·
3b23771
1
Parent(s):
08d3634
sync ms
Browse files- app.py +2 -5
- modules/bili.py +47 -2
- modules/bvid2acid.py +0 -45
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from modules.tiktok import tiktok_parser
|
3 |
-
from modules.bili import
|
4 |
-
from modules.bvid2acid import bv2acid
|
5 |
from utils import EN_US
|
6 |
|
7 |
ZH2EN = {
|
@@ -22,8 +21,6 @@ if __name__ == "__main__":
|
|
22 |
tiktok_parser()
|
23 |
|
24 |
with gr.Tab(_L("B站")):
|
25 |
-
|
26 |
-
bv2acid()
|
27 |
-
bili_parser()
|
28 |
|
29 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from modules.tiktok import tiktok_parser
|
3 |
+
from modules.bili import bili
|
|
|
4 |
from utils import EN_US
|
5 |
|
6 |
ZH2EN = {
|
|
|
21 |
tiktok_parser()
|
22 |
|
23 |
with gr.Tab(_L("B站")):
|
24 |
+
bili()
|
|
|
|
|
25 |
|
26 |
demo.launch()
|
modules/bili.py
CHANGED
@@ -23,10 +23,11 @@ ZH2EN = {
|
|
23 |
"视频时长(s)": "Video duration(s)",
|
24 |
"UP主头像": "Uploader avatar",
|
25 |
"UP主昵称": "Uploader nickname",
|
26 |
-
"B站视频解析": "BiliBili video parser",
|
27 |
"通道": "Channel",
|
28 |
"接口1": "Interface 1",
|
29 |
"接口2": "Interface 2",
|
|
|
|
|
30 |
}
|
31 |
|
32 |
|
@@ -200,7 +201,6 @@ def bili_parser():
|
|
200 |
gr.Image(label=_L("UP主头像"), show_share_button=False),
|
201 |
gr.Textbox(label=_L("UP主昵称"), show_copy_button=True),
|
202 |
],
|
203 |
-
title=_L("B站视频解析"),
|
204 |
flagging_mode="never",
|
205 |
examples=[
|
206 |
[_L("接口1"), "BV1Dt4y1o7bU", 1],
|
@@ -214,3 +214,48 @@ def bili_parser():
|
|
214 |
],
|
215 |
cache_examples=False,
|
216 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
"视频时长(s)": "Video duration(s)",
|
24 |
"UP主头像": "Uploader avatar",
|
25 |
"UP主昵称": "Uploader nickname",
|
|
|
26 |
"通道": "Channel",
|
27 |
"接口1": "Interface 1",
|
28 |
"接口2": "Interface 2",
|
29 |
+
"B站视频解析": "BiliBili video parser",
|
30 |
+
"将 Bvid 转为 aid 或 cid": "Bvid to aid / cid",
|
31 |
}
|
32 |
|
33 |
|
|
|
201 |
gr.Image(label=_L("UP主头像"), show_share_button=False),
|
202 |
gr.Textbox(label=_L("UP主昵称"), show_copy_button=True),
|
203 |
],
|
|
|
204 |
flagging_mode="never",
|
205 |
examples=[
|
206 |
[_L("接口1"), "BV1Dt4y1o7bU", 1],
|
|
|
214 |
],
|
215 |
cache_examples=False,
|
216 |
)
|
217 |
+
|
218 |
+
|
219 |
+
# bv2acid
|
220 |
+
def bvid_to_aid_or_cid(bvid: str):
|
221 |
+
status = "Success"
|
222 |
+
aid = cid = None
|
223 |
+
try:
|
224 |
+
response = requests.get(
|
225 |
+
"https://api.bilibili.com/x/web-interface/view",
|
226 |
+
params={"bvid": bvid},
|
227 |
+
headers=HEADER,
|
228 |
+
)
|
229 |
+
data = response.json()["data"]
|
230 |
+
aid = data["aid"]
|
231 |
+
cid = data["cid"]
|
232 |
+
|
233 |
+
except Exception as e:
|
234 |
+
status = f"{e}"
|
235 |
+
|
236 |
+
return status, aid, cid
|
237 |
+
|
238 |
+
|
239 |
+
def bv2acid():
|
240 |
+
return gr.Interface(
|
241 |
+
fn=bvid_to_aid_or_cid,
|
242 |
+
inputs=gr.Textbox(label="bvid"),
|
243 |
+
outputs=[
|
244 |
+
gr.Textbox(label=_L("状态栏"), show_copy_button=True),
|
245 |
+
gr.Textbox(label="aid", show_copy_button=True),
|
246 |
+
gr.Textbox(label="cid", show_copy_button=True),
|
247 |
+
],
|
248 |
+
flagging_mode="never",
|
249 |
+
examples=["BV1Dt4y1o7bU", "BV1G8iRYBE4f"],
|
250 |
+
)
|
251 |
+
|
252 |
+
|
253 |
+
# bili ui
|
254 |
+
def bili():
|
255 |
+
with gr.Blocks() as demo:
|
256 |
+
with gr.Tab(_L("B站视频解析")):
|
257 |
+
bili_parser()
|
258 |
+
with gr.Tab(_L("将 Bvid 转为 aid 或 cid")):
|
259 |
+
bv2acid()
|
260 |
+
|
261 |
+
return demo
|
modules/bvid2acid.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
import gradio as gr
|
3 |
-
from utils import EN_US, HEADER
|
4 |
-
|
5 |
-
ZH2EN = {
|
6 |
-
"状态栏": "Status",
|
7 |
-
"将 Bvid 转为 aid 或 cid": "Bvid to aid / cid",
|
8 |
-
}
|
9 |
-
|
10 |
-
|
11 |
-
def _L(zh_txt: str):
|
12 |
-
return ZH2EN[zh_txt] if EN_US else zh_txt
|
13 |
-
|
14 |
-
|
15 |
-
def infer(bvid: str):
|
16 |
-
status = "Success"
|
17 |
-
aid = cid = None
|
18 |
-
try:
|
19 |
-
response = requests.get(
|
20 |
-
"https://api.bilibili.com/x/web-interface/view",
|
21 |
-
params={"bvid": bvid},
|
22 |
-
headers=HEADER,
|
23 |
-
)
|
24 |
-
data = response.json()["data"]
|
25 |
-
aid = data["aid"]
|
26 |
-
cid = data["cid"]
|
27 |
-
|
28 |
-
except Exception as e:
|
29 |
-
status = f"{e}"
|
30 |
-
|
31 |
-
return status, aid, cid
|
32 |
-
|
33 |
-
|
34 |
-
def bv2acid():
|
35 |
-
return gr.Interface(
|
36 |
-
fn=infer,
|
37 |
-
inputs=gr.Textbox(label="bvid"),
|
38 |
-
outputs=[
|
39 |
-
gr.Textbox(label=_L("状态栏"), show_copy_button=True),
|
40 |
-
gr.Textbox(label="aid", show_copy_button=True),
|
41 |
-
gr.Textbox(label="cid", show_copy_button=True),
|
42 |
-
],
|
43 |
-
title=_L("将 Bvid 转为 aid 或 cid"),
|
44 |
-
flagging_mode="never",
|
45 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|