Commit b9d4640

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-01-24 02:56:10
fix(douyin): handle no comments video
1 parent 0c18719
Changed files (1)
src
preview
src/preview/douyin.py
@@ -135,8 +135,8 @@ async def get_comments(aweme_id: str = "", platform: str = "douyin", douyin_comm
         api_url = api_urls.get(f"{platform}_free")
         headers = {"accept": "application/json"}
         try:
-            resp = await hx_req(api_url, headers=headers, check_has_kv=["data.comments"], check_kv={"code": 200})
-            data = resp.json()["data"]["comments"]
+            resp = await hx_req(api_url, headers=headers, check_has_kv=["data"], check_kv={"code": 200})
+            data = resp.json()["data"].get("comments", [])
             succ = True
         except Exception:
             logger.warning(f"{platform} comments API [free] failed: {resp}")
@@ -144,8 +144,8 @@ async def get_comments(aweme_id: str = "", platform: str = "douyin", douyin_comm
         api_url = api_urls.get(f"{platform}_tikhub")
         headers = {"authorization": f"Bearer {TOKEN.TIKHUB}", "accept": "application/json"}
         try:
-            resp = await hx_req(api_url, headers=headers, check_has_kv=["data.comments"], check_kv={"code": 200})
-            data = resp.json()["data"]["comments"]
+            resp = await hx_req(api_url, headers=headers, check_has_kv=["data"], check_kv={"code": 200})
+            data = resp.json()["data"].get("comments", [])
         except Exception:
             logger.warning(f"{platform} comments API [tikhub] failed: {resp}")
             return []