|
| 1 | +# Import API SDK Client class |
| 2 | +from tikhub.http_client.api_client import APIClient |
| 3 | + |
| 4 | + |
| 5 | +class BilibiliWeb: |
| 6 | + |
| 7 | + # Initialize |
| 8 | + def __init__(self, client: APIClient): |
| 9 | + self.client = client |
| 10 | + |
| 11 | + # Fetch single video data | 获取单个视频详情信息 |
| 12 | + async def fetch_one_video(self, bv_id: str): |
| 13 | + endpoint = "/api/v1/bilibili/web/fetch_one_video" |
| 14 | + data = await self.client.fetch_get_json(f"{endpoint}?bv_id={bv_id}") |
| 15 | + return data |
| 16 | + |
| 17 | + # Fetch video playurl | 获取视频流地址 |
| 18 | + async def fetch_video_playurl(self, bv_id: str, cid: str): |
| 19 | + endpoint = "/api/v1/bilibili/web/fetch_video_playurl" |
| 20 | + data = await self.client.fetch_get_json(f"{endpoint}?bv_id={bv_id}&cid={cid}") |
| 21 | + return data |
| 22 | + |
| 23 | + # Fetch user post videos | 获取用户发布视频作品数据 |
| 24 | + async def fetch_user_post_videos(self, uid: str, pn: int = 1): |
| 25 | + endpoint = "/api/v1/bilibili/web/fetch_user_post_videos" |
| 26 | + data = await self.client.fetch_get_json(f"{endpoint}?uid={uid}&pn={pn}") |
| 27 | + return data |
| 28 | + |
| 29 | + # Fetch collection folders | 获取用户所有收藏夹信息 |
| 30 | + async def fetch_collect_folders(self, uid: str): |
| 31 | + endpoint = "/api/v1/bilibili/web/fetch_collect_folders" |
| 32 | + data = await self.client.fetch_get_json(f"{endpoint}?uid={uid}") |
| 33 | + return data |
| 34 | + |
| 35 | + # Fetch videos from collection folder | 获取指定收藏夹内视频数据 |
| 36 | + async def fetch_user_collection_videos(self, folder_id: str, pn: int = 1): |
| 37 | + endpoint = "/api/v1/bilibili/web/fetch_user_collection_videos" |
| 38 | + data = await self.client.fetch_get_json(f"{endpoint}?folder_id={folder_id}&pn={pn}") |
| 39 | + return data |
| 40 | + |
| 41 | + # Fetch user profile | 获取指定用户的信息 |
| 42 | + async def fetch_user_profile(self, uid: str): |
| 43 | + endpoint = "/api/v1/bilibili/web/fetch_user_profile" |
| 44 | + data = await self.client.fetch_get_json(f"{endpoint}?uid={uid}") |
| 45 | + return data |
| 46 | + |
| 47 | + # Fetch comprehensive popular videos | 获取综合热门视频信息 |
| 48 | + async def fetch_com_popular(self, pn: int = 1): |
| 49 | + endpoint = "/api/v1/bilibili/web/fetch_com_popular" |
| 50 | + data = await self.client.fetch_get_json(f"{endpoint}?pn={pn}") |
| 51 | + return data |
| 52 | + |
| 53 | + # Fetch video comments | 获取指定视频的评论 |
| 54 | + async def fetch_video_comments(self, bv_id: str, pn: int = 1): |
| 55 | + endpoint = "/api/v1/bilibili/web/fetch_video_comments" |
| 56 | + data = await self.client.fetch_get_json(f"{endpoint}?bv_id={bv_id}&pn={pn}") |
| 57 | + return data |
| 58 | + |
| 59 | + # Fetch comment reply | 获取视频下指定评论的回复 |
| 60 | + async def fetch_comment_reply(self, bv_id: str, rpid: str, pn: int = 1): |
| 61 | + endpoint = "/api/v1/bilibili/web/fetch_comment_reply" |
| 62 | + data = await self.client.fetch_get_json(f"{endpoint}?bv_id={bv_id}&pn={pn}&rpid={rpid}") |
| 63 | + return data |
| 64 | + |
| 65 | + # Fetch user dynamics | 获取指定用户动态 |
| 66 | + async def fetch_user_dynamic(self, uid: str, offset: str = ""): |
| 67 | + endpoint = "/api/v1/bilibili/web/fetch_user_dynamic" |
| 68 | + data = await self.client.fetch_get_json(f"{endpoint}?uid={uid}&offset={offset}") |
| 69 | + return data |
| 70 | + |
| 71 | + # Fetch video danmaku | 获取视频实时弹幕 |
| 72 | + async def fetch_video_danmaku(self, cid: str): |
| 73 | + endpoint = "/api/v1/bilibili/web/fetch_video_danmaku" |
| 74 | + data = await self.client.fetch_get_json(f"{endpoint}?cid={cid}") |
| 75 | + return data |
| 76 | + |
| 77 | + # Fetch live room details | 获取指定直播间信息 |
| 78 | + async def fetch_live_room_detail(self, room_id: str): |
| 79 | + endpoint = "/api/v1/bilibili/web/fetch_live_room_detail" |
| 80 | + data = await self.client.fetch_get_json(f"{endpoint}?room_id={room_id}") |
| 81 | + return data |
| 82 | + |
| 83 | + # Fetch live room videos | 获取指定直播间视频流 |
| 84 | + async def fetch_live_videos(self, room_id: str): |
| 85 | + endpoint = "/api/v1/bilibili/web/fetch_live_videos" |
| 86 | + data = await self.client.fetch_get_json(f"{endpoint}?room_id={room_id}") |
| 87 | + return data |
| 88 | + |
| 89 | + # Fetch live streamers in area | 获取指定分区正在直播的主播 |
| 90 | + async def fetch_live_streamers(self, area_id: str, pn: int = 1): |
| 91 | + endpoint = "/api/v1/bilibili/web/fetch_live_streamers" |
| 92 | + data = await self.client.fetch_get_json(f"{endpoint}?area_id={area_id}&pn={pn}") |
| 93 | + return data |
| 94 | + |
| 95 | + # Fetch all live areas | 获取所有直播分区列表 |
| 96 | + async def fetch_all_live_areas(self): |
| 97 | + endpoint = "/api/v1/bilibili/web/fetch_all_live_areas" |
| 98 | + data = await self.client.fetch_get_json(endpoint) |
| 99 | + return data |
| 100 | + |
| 101 | + # Convert bv_id to aid | 通过bv号获得视频aid号 |
| 102 | + async def bv_to_aid(self, bv_id: str): |
| 103 | + endpoint = "/api/v1/bilibili/web/bv_to_aid" |
| 104 | + data = await self.client.fetch_get_json(f"{endpoint}?bv_id={bv_id}") |
| 105 | + return data |
| 106 | + |
| 107 | + # Fetch video parts by bv_id | 通过bv号获得视频分p信息 |
| 108 | + async def fetch_video_parts(self, bv_id: str): |
| 109 | + endpoint = "/api/v1/bilibili/web/fetch_video_parts" |
| 110 | + data = await self.client.fetch_get_json(f"{endpoint}?bv_id={bv_id}") |
| 111 | + return data |
0 commit comments