ソースを参照

2024-06-04
西瓜上线

罗俊辉 1 年間 前
コミット
5c91779cb4

+ 11 - 11
applications/schedule/search_schedule.py

@@ -176,17 +176,17 @@ class SearchMethod(object):
                     info="通过baidu搜索失败---{}".format(text),
                     trace_id=trace_id,
                 )
-                return None
-                # xigua_result = xigua_search(keyword=text, sensitive_words=cls.s_words)
-                # if xigua_result:
-                #     return {"platform": "xg_search", "result": xigua_result[0]}
-                # else:
-                #     logging(
-                #         code="7001",
-                #         info="通过西瓜搜索失败---{}, 启用兜底方式".format(text),
-                #         trace_id=trace_id,
-                #     )
-                #     return None
+                # return None
+                xigua_result = xigua_search_v2(keyword=text, sensitive_words=cls.s_words)
+                if xigua_result:
+                    return {"platform": "xg_search", "result": xigua_result[0]}
+                else:
+                    logging(
+                        code="7001",
+                        info="通过西瓜搜索失败---{}, 启用兜底方式".format(text),
+                        trace_id=trace_id,
+                    )
+                    return None
 
 
 async def video_sender(video_obj, user, trace_id, platform):

+ 1 - 1
applications/search/__init__.py

@@ -3,4 +3,4 @@
 """
 from .hksp_search import hksp_search
 from .weixin_search import wx_search
-from .xigua_search import xigua_search
+from .xigua_search import xigua_search_v2

+ 23 - 2
applications/search/xigua_search.py

@@ -240,5 +240,26 @@ def xigua_search_v2(keyword, sensitive_words):
         'user-agent': FakeUserAgent().chrome
     }
     response = requests.request("GET", url, headers=headers, params=params)
-
-    print(json.dumps(response.json()['data']['data'], ensure_ascii=False, indent=4))
+    try:
+        recall_list = response.json()['data']['data']
+        if recall_list:
+            for obj in recall_list:
+                if obj['type'] == "video":
+                    title = obj['data']['title']
+                    url = obj['data']['group_id']
+                    duration = obj['data']['video_time']
+                    watch_count = obj['data']['video_watch_count']
+                    if sensitive_flag(sensitive_words, title) and duration <= 300:
+                        try:
+                            res = XiGuaFunctions().get_video_info(url)
+                            if res:
+                                return [res]
+                            else:
+                                continue
+                        except Exception as e:
+                            print(e)
+            return []
+        else:
+            return []
+    except Exception as e:
+        return []