Sfoglia il codice sorgente

fix: douyin works sync play/like count

1. Update Douyin works API URL to remove 'scene=star_atlas' and 'aid=1128' parameters to ensure all works (not just Star Atlas ones) are fetched with correct statistics.
2. Add error handling for fetch request in Douyin works API call.
3. This ensures play_count and like_count are correctly synchronized and saved to the database.
Ethanfly 23 ore fa
parent
commit
2d89114bd9
1 ha cambiato i file con 16 aggiunte e 6 eliminazioni
  1. 16 6
      server/python/platforms/douyin.py

+ 16 - 6
server/python/platforms/douyin.py

@@ -479,18 +479,26 @@ class DouyinPublisher(BasePublisher):
             
             # 调用作品列表 API
             cursor = page * page_size
-            api_url = f"https://creator.douyin.com/janus/douyin/creator/pc/work_list?status=0&scene=star_atlas&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&aid=1128"
+            # 移除 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"
             
             response = await self.page.evaluate(f'''
                 async () => {{
-                    const resp = await fetch("{api_url}", {{
-                        credentials: 'include',
-                        headers: {{ 'Accept': 'application/json' }}
-                    }});
-                    return await resp.json();
+                    try {{
+                        const resp = await fetch("{api_url}", {{
+                            credentials: 'include',
+                            headers: {{ 'Accept': 'application/json' }}
+                        }});
+                        return await resp.json();
+                    }} catch (e) {{
+                        return {{ error: e.toString() }};
+                    }}
                 }}
             ''')
             
+            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', [])
@@ -502,6 +510,8 @@ class DouyinPublisher(BasePublisher):
                     continue
                 
                 statistics = aweme.get('statistics', {})
+                # 打印调试信息,确认字段存在
+                # print(f"[{self.platform_name}] 作品 {aweme_id} 统计: {statistics}", flush=True)
                 
                 # 获取封面
                 cover_url = ''