|
|
@@ -676,15 +676,25 @@ class DouyinPublisher(BasePublisher):
|
|
|
)
|
|
|
|
|
|
async def get_works(self, cookies: str, page: int = 0, page_size: int = 20) -> WorksResult:
|
|
|
- """获取抖音作品列表"""
|
|
|
+ """获取抖音作品列表
|
|
|
+
|
|
|
+ Args:
|
|
|
+ cookies: Cookie 字符串或 JSON
|
|
|
+ page: 分页参数,首次请求传 0,后续传上一次返回的 next_page(即 API 的 max_cursor)
|
|
|
+ page_size: 每页数量
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ WorksResult: 包含 works, total, has_more, next_page(用于下一页请求)
|
|
|
+ """
|
|
|
print(f"\n{'='*60}")
|
|
|
print(f"[{self.platform_name}] 获取作品列表")
|
|
|
- print(f"[{self.platform_name}] page={page}, page_size={page_size}")
|
|
|
+ print(f"[{self.platform_name}] cursor={page}, page_size={page_size}")
|
|
|
print(f"{'='*60}")
|
|
|
|
|
|
works: List[WorkItem] = []
|
|
|
total = 0
|
|
|
has_more = False
|
|
|
+ next_cursor = 0
|
|
|
|
|
|
try:
|
|
|
await self.init_browser()
|
|
|
@@ -703,10 +713,9 @@ class DouyinPublisher(BasePublisher):
|
|
|
if "login" in current_url or "passport" in current_url:
|
|
|
raise Exception("Cookie 已过期,请重新登录")
|
|
|
|
|
|
- # 调用作品列表 API
|
|
|
- cursor = page * page_size
|
|
|
- # 移除 scene=star_atlas 和 aid=1128,使用更通用的参数
|
|
|
- api_url = f"https://creator.douyin.com/janus/douyin/creator/pc/work_list?status=0&device_platform=android&count={page_size}&max_cursor={cursor}&cookie_enabled=true&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_online=true&timezone_name=Asia%2FShanghai"
|
|
|
+ # 调用作品列表 API:page 作为 max_cursor(首次 0,后续为上一页返回的 max_cursor)
|
|
|
+ max_cursor = page
|
|
|
+ api_url = f"https://creator.douyin.com/janus/douyin/creator/pc/work_list?status=0&device_platform=android&count={page_size}&max_cursor={max_cursor}&cookie_enabled=true&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_online=true&timezone_name=Asia%2FShanghai"
|
|
|
|
|
|
response = await self.page.evaluate(f'''
|
|
|
async () => {{
|
|
|
@@ -725,10 +734,19 @@ class DouyinPublisher(BasePublisher):
|
|
|
if response.get('error'):
|
|
|
print(f"[{self.platform_name}] API 请求失败: {response.get('error')}", flush=True)
|
|
|
|
|
|
- print(f"[{self.platform_name}] API 响应: has_more={response.get('has_more')}, aweme_list={len(response.get('aweme_list', []))}")
|
|
|
-
|
|
|
- aweme_list = response.get('aweme_list', [])
|
|
|
+ aweme_list = response.get('aweme_list', []) or []
|
|
|
has_more = response.get('has_more', False)
|
|
|
+ next_cursor = response.get('max_cursor', 0)
|
|
|
+
|
|
|
+ # 从第一个作品的 author.aweme_count 获取总作品数
|
|
|
+ if aweme_list and len(aweme_list) > 0:
|
|
|
+ first_aweme = aweme_list[0]
|
|
|
+ author_aweme_count = first_aweme.get('author', {}).get('aweme_count', 0)
|
|
|
+ if author_aweme_count > 0:
|
|
|
+ total = author_aweme_count
|
|
|
+ print(f"[{self.platform_name}] 从 author.aweme_count 获取总作品数: {total}")
|
|
|
+
|
|
|
+ print(f"[{self.platform_name}] API 响应: has_more={has_more}, aweme_list={len(aweme_list)}, next_cursor={next_cursor}")
|
|
|
|
|
|
for aweme in aweme_list:
|
|
|
aweme_id = str(aweme.get('aweme_id', ''))
|
|
|
@@ -769,8 +787,9 @@ class DouyinPublisher(BasePublisher):
|
|
|
share_count=int(statistics.get('share_count', 0)),
|
|
|
))
|
|
|
|
|
|
- total = len(works)
|
|
|
- print(f"[{self.platform_name}] 获取到 {total} 个作品")
|
|
|
+ if total == 0:
|
|
|
+ total = len(works)
|
|
|
+ print(f"[{self.platform_name}] 本页获取到 {len(works)} 个作品")
|
|
|
|
|
|
except Exception as e:
|
|
|
import traceback
|
|
|
@@ -786,7 +805,8 @@ class DouyinPublisher(BasePublisher):
|
|
|
platform=self.platform_name,
|
|
|
works=works,
|
|
|
total=total,
|
|
|
- has_more=has_more
|
|
|
+ has_more=has_more,
|
|
|
+ next_page=next_cursor
|
|
|
)
|
|
|
|
|
|
async def get_comments(self, cookies: str, work_id: str, cursor: str = "") -> CommentsResult:
|