Kaynağa Gözat

增加抖音来源

xueyiming 6 gün önce
ebeveyn
işleme
e577c76da6
2 değiştirilmiş dosya ile 34 ekleme ve 1 silme
  1. 6 0
      app/core/config.py
  2. 28 1
      app/hot_content/client.py

+ 6 - 0
app/core/config.py

@@ -113,6 +113,12 @@ class Settings:
                 "hot_rank_path": "/crawler/kuai_shou/hot_rank",
                 "hot_rank_payload": {},
             },
+            {
+                "source": "抖音",
+                "hot_rank_base_url": "http://8.217.190.241:8888",
+                "hot_rank_path": "/crawler/dou_yin/hot_rank",
+                "hot_rank_payload": {"tab_name": "热点榜"},
+            },
         ]
     )
 

+ 28 - 1
app/hot_content/client.py

@@ -71,9 +71,36 @@ class JsonApiClient:
         return context
 
 
+def _extract_douyin_word_list_items(inner: dict[str, Any]) -> list[dict[str, Any]]:
+    word_list = inner.get("word_list")
+    if not isinstance(word_list, list):
+        return []
+
+    result: list[dict[str, Any]] = []
+    for item in word_list:
+        if not isinstance(item, dict):
+            continue
+        word = str(item.get("word") or "").strip()
+        if not word:
+            continue
+        normalized = dict(item)
+        normalized["title"] = word
+        position = item.get("position")
+        if position is not None:
+            normalized["rank"] = position
+        result.append(normalized)
+    return result
+
+
 def extract_rank_items(resp: dict[str, Any], source: str) -> list[dict[str, Any]]:
     data = resp.get("data") or {}
-    rows = data.get("data") if isinstance(data, dict) else data
+    inner = data.get("data") if isinstance(data, dict) else None
+    if isinstance(inner, dict):
+        douyin_items = _extract_douyin_word_list_items(inner)
+        if douyin_items:
+            return douyin_items
+
+    rows = inner if isinstance(inner, list) else data
     if not isinstance(rows, list):
         return []