zhangyong 6 months ago
parent
commit
e8bc8d7a0d
2 changed files with 16 additions and 4 deletions
  1. 9 0
      common/redis.py
  2. 7 4
      video_processing/video_processing.py

+ 9 - 0
common/redis.py

@@ -47,6 +47,8 @@ def install_video_data():
     client = helper.get_client()
     client.rpush(task, *data)
 
+
+
 def get_video_data():
     """获取一条需要打标签的视频"""
     task = f"task:video_ai"
@@ -54,3 +56,10 @@ def get_video_data():
     client = helper.get_client()
     ret = client.lpop(task)
     return ret
+
+def in_video_data(ret):
+    """分析失败视频重新写入redis"""
+    task = f"task:video_ai"
+    helper = SyncRedisHelper()
+    client = helper.get_client()
+    client.rpush(task, ret)

+ 7 - 4
video_processing/video_processing.py

@@ -5,22 +5,20 @@ import requests
 import json
 
 from common.aliyun_log import AliyunLogger
-from common.redis import get_video_data, install_video_data
+from common.redis import get_video_data, install_video_data, in_video_data
 
 
 class VideoProcessing:
     def get_ai_data(self, video_path):
         url = "http://8.219.186.16:8080/process_video/"
-
         payload = json.dumps( {
             "video_path": video_path
         } )
         headers = {
             'Content-Type': 'application/json'
         }
-
-        response = requests.request( "POST", url, headers=headers, data=payload )
         try:
+            response = requests.request( "POST", url, headers=headers, data=payload )
             response = response.json()
             result = response['result']
             cleaned_string = result.replace( "```json", '' ).replace( "```", '' ).strip()
@@ -44,7 +42,12 @@ class VideoProcessing:
         video_id = data_json['video_id']
         title = data_json['title']
         video_path = data_json['video_path']
+        print(video_path)
         data = self.get_ai_data(video_path)
+        if not data:
+            in_video_data(video_data)
+            print( "写入失败,需重新请求" )
+            return
         AliyunLogger.logging(str(video_id), title, video_path, data)
         print("写入日志成功")