zhangyong 7 月之前
父节点
当前提交
bd16c65667
共有 5 个文件被更改,包括 29 次插入19 次删除
  1. 1 1
      common/aliyun_log.py
  2. 1 1
      common/cover_gpt4o.py
  3. 2 4
      common/sql_help.py
  4. 22 10
      job_cover_method.py
  5. 3 3
      video_cover_method/cover_method.py

+ 1 - 1
common/aliyun_log.py

@@ -105,7 +105,7 @@ class AliyunLogger:
             # if data:
             # if data:
             #     data = dict(item.split(":", 1) for item in data.split(","))
             #     data = dict(item.split(":", 1) for item in data.split(","))
             contents = [
             contents = [
-                ("video_id", video_id),
+                ("video_id", str(video_id)),
                 ("message", message),
                 ("message", message),
                 ("code", code),
                 ("code", code),
                 ("old_cover_url", old_cover_url if old_cover_url is not None else ""),
                 ("old_cover_url", old_cover_url if old_cover_url is not None else ""),

+ 1 - 1
common/cover_gpt4o.py

@@ -264,7 +264,7 @@ class CoverAnalyzer:
 
 
                 result_sum = sum(item['result'] for item in data.values())  # 获取总和
                 result_sum = sum(item['result'] for item in data.values())  # 获取总和
                 data_dict = {
                 data_dict = {
-                    "data": data,
+                    "data": str(data),
                     "cover_url": cover,
                     "cover_url": cover,
                     "cover_sum": result_sum
                     "cover_sum": result_sum
                 }
                 }

+ 2 - 4
common/sql_help.py

@@ -11,10 +11,8 @@ class sqlCollect():
     视频信息写入库中
     视频信息写入库中
     """
     """
     @classmethod
     @classmethod
-    def insert_video_cover_method(cls, video_id: str, cover_id: str, old_cover_url: str, cover_url_list: str, new_cover_url: str):
-        cover_url_list_json = json.dumps( cover_url_list, ensure_ascii=False )
-
-        insert_sql = f"""INSERT INTO video_cover_method (video_id, cover_id, old_cover_url, cover_url_list, new_cover_url) values ('{video_id}' ,'{cover_id}','{old_cover_url}', '{cover_url_list_json}', '{new_cover_url}')"""
+    def insert_video_cover_method(cls, video_id: str, cover_id: str, old_cover_url: str, new_cover_url: str):
+        insert_sql = f"""INSERT INTO video_cover_method (video_id, cover_id, old_cover_url, new_cover_url) values ("{video_id}" ,"{cover_id}","{old_cover_url}", "{new_cover_url}")"""
         MysqlHelper.update_values(
         MysqlHelper.update_values(
             sql=insert_sql
             sql=insert_sql
         )
         )

+ 22 - 10
job_cover_method.py

@@ -1,18 +1,30 @@
+import asyncio
 import time
 import time
 from common.redis import get_pq_id
 from common.redis import get_pq_id
 from video_cover_method.cover_method import CoverMethod
 from video_cover_method.cover_method import CoverMethod
-def video_cover_task_start():
+
+semaphore = asyncio.Semaphore(10)  # 限制并发为 10 个
+
+async def get_video_id():
     while True:
     while True:
+        video_id = get_pq_id()
+        if video_id:
+            return video_id
+        else:
+            print("没有获取待更改封面的视频ID,等待10秒")
+            await asyncio.sleep(5)
+
+async def process_video_cover(video_id):
+    async with semaphore:  # 限制并发
         try:
         try:
-            video_id = get_pq_id()
-            if video_id:
-                CoverMethod.cover_method(video_id)
-            else:
-                print("没有获取待更改封面的视频ID,等待10秒")
-                time.sleep(10)
+            await CoverMethod.cover_method(int(video_id))
         except Exception as e:
         except Exception as e:
             print("处理任务时出现异常:", e)
             print("处理任务时出现异常:", e)
-            time.sleep(10)
-            continue
+
+async def video_cover_task_start():
+    while True:
+        video_id = await get_video_id()
+        asyncio.create_task(process_video_cover(video_id))  # 创建异步任务
+
 if __name__ == '__main__':
 if __name__ == '__main__':
-    video_cover_task_start()
+    asyncio.run(video_cover_task_start())

+ 3 - 3
video_cover_method/cover_method.py

@@ -29,7 +29,6 @@ class CoverMethod:
 
 
     @staticmethod
     @staticmethod
     def cover_method(video_id):
     def cover_method(video_id):
-        # video_id = "25521693"
         video_id_status = sqlCollect.select_video_cover_method(video_id)  # 判断该视频id是否处理过
         video_id_status = sqlCollect.select_video_cover_method(video_id)  # 判断该视频id是否处理过
         if video_id_status:
         if video_id_status:
             AliyunLogger.logging(video_id, "重复视频ID,不做封面处理", "2001")
             AliyunLogger.logging(video_id, "重复视频ID,不做封面处理", "2001")
@@ -61,6 +60,7 @@ class CoverMethod:
                                    "【 封面修改通知 】" )
                                    "【 封面修改通知 】" )
                 return
                 return
             cover_id, old_cover_url = PQ.get_pq_cover_id(video_id)  # 获取原封面 和 封面ID
             cover_id, old_cover_url = PQ.get_pq_cover_id(video_id)  # 获取原封面 和 封面ID
+
             if cover_id == None:
             if cover_id == None:
                 AliyunLogger.logging( video_id, "获取视频原封面和封面ID失败", "3002", cover_all_data, old_cover_url, highest_cover_url)
                 AliyunLogger.logging( video_id, "获取视频原封面和封面ID失败", "3002", cover_all_data, old_cover_url, highest_cover_url)
                 insert_pq_data( [video_id] )
                 insert_pq_data( [video_id] )
@@ -92,7 +92,7 @@ class CoverMethod:
                 Feishu.finish_bot( text,
                 Feishu.finish_bot( text,
                                    "https://open.feishu.cn/open-apis/bot/v2/hook/63745308-c53e-4030-90b9-77383b057252",
                                    "https://open.feishu.cn/open-apis/bot/v2/hook/63745308-c53e-4030-90b9-77383b057252",
                                    "【 封面修改通知 】" )
                                    "【 封面修改通知 】" )
-                sqlCollect.insert_video_cover_method(video_id, cover_id, old_cover_url, cover_all_data, highest_cover_url)
+                sqlCollect.insert_video_cover_method(video_id, cover_id, old_cover_url, highest_cover_url)
                 return
                 return
             else:
             else:
                 text = (
                 text = (
@@ -121,4 +121,4 @@ class CoverMethod:
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
-    CoverMethod.cover_method()
+    CoverMethod.cover_method("")