Skip to content

Commit ca05f11

Browse files
authored
Merge pull request #481 from Koyomi781/update
[update] 调整代码结构,增加一些接口
2 parents 1587b7d + a693308 commit ca05f11

File tree

8 files changed

+457
-235
lines changed

8 files changed

+457
-235
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ TikHub的部分源代码会开源在Github上,并且会赞助一些开源项
223223
- [x] 获取列表unique_id
224224
- 哔哩哔哩网页版API
225225
- [x] 获取单个视频详情信息
226+
- [x] 获取视频流地址
226227
- [x] 获取用户发布视频作品数据
227228
- [x] 获取用户所有收藏夹信息
228229
- [x] 获取指定收藏夹内视频数据
@@ -231,8 +232,12 @@ TikHub的部分源代码会开源在Github上,并且会赞助一些开源项
231232
- [x] 获取指定视频的评论
232233
- [x] 获取视频下指定评论的回复
233234
- [x] 获取指定用户动态
235+
- [x] 获取视频实时弹幕
234236
- [x] 获取指定直播间信息
237+
- [x] 获取直播间视频流
238+
- [x] 获取指定分区正在直播的主播
235239
- [x] 获取所有直播分区列表
240+
- [x] 通过bv号获得视频分p信息
236241
---
237242

238243
## 📦调用解析库(已废弃需要更新):

app/api/endpoints/bilibili_web.py

Lines changed: 236 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,48 @@ async def fetch_one_video(request: Request,
4646
raise HTTPException(status_code=status_code, detail=detail.dict())
4747

4848

49+
# 获取视频流地址
50+
@router.get("/fetch_video_playurl", response_model=ResponseModel, summary="获取视频流地址/Get video playurl")
51+
async def fetch_one_video(request: Request,
52+
bv_id: str = Query(example="BV1y7411Q7Eq", description="作品id/Video id"),
53+
cid:str = Query(example="171776208", description="作品cid/Video cid")):
54+
"""
55+
# [中文]
56+
### 用途:
57+
- 获取视频流地址
58+
### 参数:
59+
- bv_id: 作品id
60+
- cid: 作品cid
61+
### 返回:
62+
- 视频流地址
63+
64+
# [English]
65+
### Purpose:
66+
- Get video playurl
67+
### Parameters:
68+
- bv_id: Video id
69+
- cid: Video cid
70+
### Return:
71+
- Video playurl
72+
73+
# [示例/Example]
74+
bv_id = "BV1y7411Q7Eq"
75+
cid = "171776208"
76+
"""
77+
try:
78+
data = await BilibiliWebCrawler.fetch_video_playurl(bv_id, cid)
79+
return ResponseModel(code=200,
80+
router=request.url.path,
81+
data=data)
82+
except Exception as e:
83+
status_code = 400
84+
detail = ErrorResponseModel(code=status_code,
85+
router=request.url.path,
86+
params=dict(request.query_params),
87+
)
88+
raise HTTPException(status_code=status_code, detail=detail.dict())
89+
90+
4991
# 获取用户发布视频作品数据
5092
@router.get("/fetch_user_post_videos", response_model=ResponseModel,
5193
summary="获取用户主页作品数据/Get user homepage video data")
@@ -385,6 +427,44 @@ async def fetch_collect_folders(request: Request,
385427
raise HTTPException(status_code=status_code, detail=detail.dict())
386428

387429

430+
# 获取视频实时弹幕
431+
@router.get("/fetch_video_danmaku", response_model=ResponseModel, summary="获取视频实时弹幕/Get Video Danmaku")
432+
async def fetch_one_video(request: Request,
433+
cid: str = Query(example="1639235405", description="作品cid/Video cid")):
434+
"""
435+
# [中文]
436+
### 用途:
437+
- 获取视频实时弹幕
438+
### 参数:
439+
- cid: 作品cid
440+
### 返回:
441+
- 视频实时弹幕
442+
443+
# [English]
444+
### Purpose:
445+
- Get Video Danmaku
446+
### Parameters:
447+
- cid: Video cid
448+
### Return:
449+
- Video Danmaku
450+
451+
# [示例/Example]
452+
cid = "1639235405"
453+
"""
454+
try:
455+
data = await BilibiliWebCrawler.fetch_video_danmaku(cid)
456+
return ResponseModel(code=200,
457+
router=request.url.path,
458+
data=data)
459+
except Exception as e:
460+
status_code = 400
461+
detail = ErrorResponseModel(code=status_code,
462+
router=request.url.path,
463+
params=dict(request.query_params),
464+
)
465+
raise HTTPException(status_code=status_code, detail=detail.dict())
466+
467+
388468
# 获取指定直播间信息
389469
@router.get("/fetch_live_room_detail", response_model=ResponseModel,
390470
summary="获取指定直播间信息/Get information of specified live room")
@@ -424,43 +504,86 @@ async def fetch_collect_folders(request: Request,
424504
raise HTTPException(status_code=status_code, detail=detail.dict())
425505

426506

427-
# # 获取指定直播间视频流
428-
# @router.get("/fetch_live_videos", response_model=ResponseModel,
429-
# summary="获取直播间视频流/Get live video data of specified room")
430-
# async def fetch_collect_folders(request: Request,
431-
# room_id: str = Query(example="22816111", description="直播间ID/Live room ID")):
432-
# """
433-
# # [中文]
434-
# ### 用途:
435-
# - 获取指定直播间视频流
436-
# ### 参数:
437-
# - room_id: 直播间ID
438-
# ### 返回:
439-
# - 指定直播间视频流
440-
#
441-
# # [English]
442-
# ### Purpose:
443-
# - Get live video data of specified room
444-
# ### Parameters:
445-
# - room_id: Live room ID
446-
# ### Return:
447-
# - live video data of specified room
448-
#
449-
# # [示例/Example]
450-
# room_id = "22816111"
451-
# """
452-
# try:
453-
# data = await BilibiliWebCrawler.fetch_live_videos(room_id)
454-
# return ResponseModel(code=200,
455-
# router=request.url.path,
456-
# data=data)
457-
# except Exception as e:
458-
# status_code = 400
459-
# detail = ErrorResponseModel(code=status_code,
460-
# router=request.url.path,
461-
# params=dict(request.query_params),
462-
# )
463-
# raise HTTPException(status_code=status_code, detail=detail.dict())
507+
# 获取指定直播间视频流
508+
@router.get("/fetch_live_videos", response_model=ResponseModel,
509+
summary="获取直播间视频流/Get live video data of specified room")
510+
async def fetch_collect_folders(request: Request,
511+
room_id: str = Query(example="1815229528", description="直播间ID/Live room ID")):
512+
"""
513+
# [中文]
514+
### 用途:
515+
- 获取指定直播间视频流
516+
### 参数:
517+
- room_id: 直播间ID
518+
### 返回:
519+
- 指定直播间视频流
520+
521+
# [English]
522+
### Purpose:
523+
- Get live video data of specified room
524+
### Parameters:
525+
- room_id: Live room ID
526+
### Return:
527+
- live video data of specified room
528+
529+
# [示例/Example]
530+
room_id = "1815229528"
531+
"""
532+
try:
533+
data = await BilibiliWebCrawler.fetch_live_videos(room_id)
534+
return ResponseModel(code=200,
535+
router=request.url.path,
536+
data=data)
537+
except Exception as e:
538+
status_code = 400
539+
detail = ErrorResponseModel(code=status_code,
540+
router=request.url.path,
541+
params=dict(request.query_params),
542+
)
543+
raise HTTPException(status_code=status_code, detail=detail.dict())
544+
545+
546+
# 获取指定分区正在直播的主播
547+
@router.get("/fetch_live_streamers", response_model=ResponseModel,
548+
summary="获取指定分区正在直播的主播/Get live streamers of specified live area")
549+
async def fetch_collect_folders(request: Request,
550+
area_id: str = Query(example="9", description="直播分区id/Live area ID"),
551+
pn: int = Query(default=1, description="页码/Page number")):
552+
"""
553+
# [中文]
554+
### 用途:
555+
- 获取指定分区正在直播的主播
556+
### 参数:
557+
- area_id: 直播分区id
558+
- pn: 页码
559+
### 返回:
560+
- 指定分区正在直播的主播
561+
562+
# [English]
563+
### Purpose:
564+
- Get live streamers of specified live area
565+
### Parameters:
566+
- area_id: Live area ID
567+
- pn: Page number
568+
### Return:
569+
- live streamers of specified live area
570+
571+
# [示例/Example]
572+
area_id = "9"
573+
pn = 1
574+
"""
575+
try:
576+
data = await BilibiliWebCrawler.fetch_live_streamers(area_id, pn)
577+
return ResponseModel(code=200,
578+
router=request.url.path,
579+
data=data)
580+
except Exception as e:
581+
status_code = 400
582+
detail = ErrorResponseModel(code=status_code,
583+
router=request.url.path,
584+
params=dict(request.query_params),
585+
)
586+
raise HTTPException(status_code=status_code, detail=detail.dict())
464587

465588

466589
# 获取所有直播分区列表
@@ -496,3 +619,79 @@ async def fetch_collect_folders(request: Request,):
496619
params=dict(request.query_params),
497620
)
498621
raise HTTPException(status_code=status_code, detail=detail.dict())
622+
623+
624+
# 通过bv号获得视频aid号
625+
@router.get("/bv_to_aid", response_model=ResponseModel, summary="通过bv号获得视频aid号/Generate aid by bvid")
626+
async def fetch_one_video(request: Request,
627+
bv_id: str = Query(example="BV1M1421t7hT", description="作品id/Video id")):
628+
"""
629+
# [中文]
630+
### 用途:
631+
- 通过bv号获得视频aid号
632+
### 参数:
633+
- bv_id: 作品id
634+
### 返回:
635+
- 视频aid号
636+
637+
# [English]
638+
### Purpose:
639+
- Generate aid by bvid
640+
### Parameters:
641+
- bv_id: Video id
642+
### Return:
643+
- Video aid
644+
645+
# [示例/Example]
646+
bv_id = "BV1M1421t7hT"
647+
"""
648+
try:
649+
data = await BilibiliWebCrawler.bv_to_aid(bv_id)
650+
return ResponseModel(code=200,
651+
router=request.url.path,
652+
data=data)
653+
except Exception as e:
654+
status_code = 400
655+
detail = ErrorResponseModel(code=status_code,
656+
router=request.url.path,
657+
params=dict(request.query_params),
658+
)
659+
raise HTTPException(status_code=status_code, detail=detail.dict())
660+
661+
662+
# 通过bv号获得视频分p信息
663+
@router.get("/fetch_video_parts", response_model=ResponseModel, summary="通过bv号获得视频分p信息/Get Video Parts By bvid")
664+
async def fetch_one_video(request: Request,
665+
bv_id: str = Query(example="BV1vf421i7hV", description="作品id/Video id")):
666+
"""
667+
# [中文]
668+
### 用途:
669+
- 通过bv号获得视频分p信息
670+
### 参数:
671+
- bv_id: 作品id
672+
### 返回:
673+
- 视频分p信息
674+
675+
# [English]
676+
### Purpose:
677+
- Get Video Parts By bvid
678+
### Parameters:
679+
- bv_id: Video id
680+
### Return:
681+
- Video Parts
682+
683+
# [示例/Example]
684+
bv_id = "BV1vf421i7hV"
685+
"""
686+
try:
687+
data = await BilibiliWebCrawler.fetch_video_parts(bv_id)
688+
return ResponseModel(code=200,
689+
router=request.url.path,
690+
data=data)
691+
except Exception as e:
692+
status_code = 400
693+
detail = ErrorResponseModel(code=status_code,
694+
router=request.url.path,
695+
params=dict(request.query_params),
696+
)
697+
raise HTTPException(status_code=status_code, detail=detail.dict())

crawlers/bilibili/web/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ TokenManager:
55
'origin': https://www.bilibili.com
66
'referer': https://space.bilibili.com/
77
'origin_2': https://space.bilibili.com
8-
'cookie': buvid3=D6E58E7B-E3A9-7CD3-7BE5-B5F255788A3020034infoc; b_nut=1723702120; _uuid=6E10D69A10-A711-9DA8-6833-1010262296C24B21337infoc; buvid_fp=6cf2ea8e143bbc49f3b7c0dcb2465fc2; buvid4=748EC8F0-82E2-1672-A286-8445DDB2A80C06110-023112304-; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjM5NjEzMjIsImlhdCI6MTcyMzcwMjA2MiwicGx0IjotMX0.IWOEMLCDKqWAX24rePU-1Qgm9Isf5CU8Tz0O-j6GHfo; bili_ticket_expires=1723961262; CURRENT_FNVAL=4048; rpdid=|(JluY|JJ|RR0J'u~kJ~|kkuY; b_lsid=E10B83DC4_191552166D6; header_theme_version=CLOSE; enable_web_push=DISABLE; home_feed_column=5; browser_resolution=1488-714; sid=873ujj7i
8+
'cookie': buvid4=748EC8F0-82E2-1672-A286-8445DDB2A80C06110-023112304-; buvid3=73EF1E2E-B7A9-78DD-F2AE-9AB2B476E27638524infoc; b_nut=1727075638; _uuid=77AA4910F-5C8F-9647-7DA3-F583C8108BD7942063infoc; buvid_fp=75b22e5d0c3dbc642b1c80956c62c7da; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjczNDI1NTYsImlhdCI6MTcyNzA4MzI5NiwicGx0IjotMX0.G3pvk6OC4FDWBL7GNgKkkVtUMl29UtNdgok_cANoKsw; bili_ticket_expires=1727342496; header_theme_version=CLOSE; enable_web_push=DISABLE; home_feed_column=5; browser_resolution=1488-712; b_lsid=5B4EDF8A_1921EAA1BDA
99
'user-agent': Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36
1010

1111
proxies:

crawlers/bilibili/web/endpoints.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ class BilibiliAPIEndpoints:
1111
# 作品信息 (Post Detail)
1212
POST_DETAIL = f"{BILIAPI_DOMAIN}/x/web-interface/view"
1313

14-
# 用户播放列表 (用于爬取用户所有视频数据)
15-
USER_POST = f"{BILIAPI_DOMAIN}/x/v2/medialist/resource/list"
14+
# 作品视频流
15+
VIDEO_PLAYURL = f"{BILIAPI_DOMAIN}/x/player/wbi/playurl"
16+
17+
# 用户发布视频作品数据
18+
USER_POST = f"{BILIAPI_DOMAIN}/x/space/wbi/arc/search"
1619

1720
# 收藏夹列表
1821
COLLECT_FOLDERS = f"{BILIAPI_DOMAIN}/x/v3/fav/folder/created/list-all"
@@ -35,9 +38,15 @@ class BilibiliAPIEndpoints:
3538
# 视频评论
3639
VIDEO_COMMENTS = f"{BILIAPI_DOMAIN}/x/v2/reply"
3740

41+
# 用户动态
42+
USER_DYNAMIC = f"{BILIAPI_DOMAIN}/x/polymer/web-dynamic/v1/feed/space"
43+
3844
# 评论的回复
3945
COMMENT_REPLY = f"{BILIAPI_DOMAIN}/x/v2/reply/reply"
4046

47+
# 视频分p信息
48+
VIDEO_PARTS = f"{BILIAPI_DOMAIN}/x/player/pagelist"
49+
4150
# 直播间信息
4251
LIVEROOM_DETAIL = f"{LIVE_DOMAIN}/room/v1/Room/get_info"
4352

@@ -47,4 +56,7 @@ class BilibiliAPIEndpoints:
4756
# 直播间视频流
4857
LIVE_VIDEOS = f"{LIVE_DOMAIN}/room/v1/Room/playUrl"
4958

59+
# 正在直播的主播
60+
LIVE_STREAMER = f"{LIVE_DOMAIN}/xlive/web-interface/v1/second/getList"
61+
5062

0 commit comments

Comments
 (0)