|
| 1 | +# 导入API SDK Client类 |
| 2 | + |
| 3 | +from tikhub.http_client.api_client import APIClient |
| 4 | + |
| 5 | +# 标记已废弃的方法 |
| 6 | +from tikhub.http_client.deprecated import deprecated |
| 7 | + |
| 8 | + |
| 9 | +class XiguaAppV2: |
| 10 | + |
| 11 | + # 初始化 | Initialize |
| 12 | + def __init__(self, client: APIClient): |
| 13 | + self.client = client |
| 14 | + |
| 15 | + # 获取单个作品数据 | Get single video data |
| 16 | + async def fetch_one_video(self, item_id: str): |
| 17 | + endpoint = f"/api/v1/xigua/app/v2/fetch_one_video" |
| 18 | + data = await self.client.fetch_get_json(f"{endpoint}?item_id={item_id}") |
| 19 | + return data |
| 20 | + |
| 21 | + # 视频评论列表 | Video comment list |
| 22 | + async def fetch_video_comment_list(self, item_id: str, offset: int = 0, count: int = 20): |
| 23 | + endpoint = f"/api/v1/xigua/app/v2/fetch_video_comment_list" |
| 24 | + data = await self.client.fetch_get_json(f"{endpoint}?item_id={item_id}&offset={offset}&count={count}") |
| 25 | + return data |
| 26 | + |
| 27 | + # 搜索视频 | Search video |
| 28 | + async def search_video(self, keyword: str, offset: int = 0, order_type: str = None, min_duration: int = None, max_duration: int = None): |
| 29 | + endpoint = f"/api/v1/xigua/app/v2/search_video" |
| 30 | + data = await self.client.fetch_get_json(f"{endpoint}?keyword={keyword}&offset={offset}&order_type={order_type}&min_duration={min_duration}&max_duration={max_duration}") |
| 31 | + return data |
| 32 | + |
| 33 | + # 个人信息 | Personal information |
| 34 | + async def fetch_user_info(self, user_id: str): |
| 35 | + endpoint = f"/api/v1/xigua/app/v2/fetch_user_info" |
| 36 | + data = await self.client.fetch_get_json(f"{endpoint}?user_id={user_id}") |
| 37 | + return data |
| 38 | + |
| 39 | + # 获取个人作品列表 | Get user post list |
| 40 | + async def fetch_user_post_list(self, user_id: str, max_behot_time: str = None): |
| 41 | + endpoint = f"/api/v1/xigua/app/v2/fetch_user_post_list" |
| 42 | + data = await self.client.fetch_get_json(f"{endpoint}?user_id={user_id}&max_behot_time={max_behot_time}") |
| 43 | + return data |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + import asyncio |
| 48 | + |
| 49 | + |
| 50 | + async def main(): |
| 51 | + client = APIClient(base_url="http://127.0.0.1:8000", client_headers={ |
| 52 | + "Authorization": "Bearer l7sVQFh64V8ltC8fzEaNtWE60zVSopDLlpVX62fArT1FznsPds9+2RGoXw=="}) |
| 53 | + |
| 54 | + xigua_app_v2 = XiguaAppV2(client) |
| 55 | + |
| 56 | + asyncio.run(main()) |
0 commit comments