|
@@ -13,8 +13,8 @@ from applications.api import GoogleAIAPI
|
|
|
from applications.db import DatabaseConnector
|
|
|
from config import long_articles_config
|
|
|
|
|
|
-# os.environ["HTTP_PROXY"] = "http://192.168.100.20:1087"
|
|
|
-# os.environ["HTTPS_PROXY"] = "http://192.168.100.20:1087"
|
|
|
+os.environ["HTTP_PROXY"] = "http://192.168.100.20:1087"
|
|
|
+os.environ["HTTPS_PROXY"] = "http://192.168.100.20:1087"
|
|
|
|
|
|
PROCESSING_MAX_VIDEO_COUNT = 10
|
|
|
|
|
@@ -81,10 +81,11 @@ class GenerateTextFromVideo(object):
|
|
|
select_sql = "select count(1) as processing_count from video_content_understanding where status = 1;"
|
|
|
count = self.db.fetch(select_sql, cursor_type=DictCursor)[0]['processing_count']
|
|
|
rest_video_count = PROCESSING_MAX_VIDEO_COUNT - count
|
|
|
+ success_upload_count = 0
|
|
|
if rest_video_count:
|
|
|
sql = f"""select pq_vid, video_oss_path from video_content_understanding where status = 0 limit {rest_video_count};"""
|
|
|
task_list = self.db.fetch(sql, cursor_type=DictCursor)
|
|
|
- for task in tqdm(task_list):
|
|
|
+ for task in tqdm(task_list, desc="upload_video_task"):
|
|
|
file_path = download_file(task['pq_vid'], task['video_oss_path'])
|
|
|
google_upload_result = self.google_ai_api.upload_file(file_path)
|
|
|
|
|
@@ -99,9 +100,12 @@ class GenerateTextFromVideo(object):
|
|
|
update_sql,
|
|
|
params=(1, file_name, file_state, expire_time, task['pq_vid'])
|
|
|
)
|
|
|
+ success_upload_count += 1
|
|
|
else:
|
|
|
continue
|
|
|
|
|
|
+ return success_upload_count
|
|
|
+
|
|
|
def get_tasks(self):
|
|
|
"""
|
|
|
获取处理视频转文本任务
|
|
@@ -116,7 +120,7 @@ class GenerateTextFromVideo(object):
|
|
|
"""
|
|
|
task_list = self.get_tasks()
|
|
|
while task_list:
|
|
|
- for task in tqdm(task_list, desc="处理视频理解任务"):
|
|
|
+ for task in tqdm(task_list, desc="convert video to text"):
|
|
|
file_name = task['file_name']
|
|
|
google_file = self.google_ai_api.get_google_file(file_name)
|
|
|
state = google_file.state.name
|
|
@@ -138,20 +142,20 @@ class GenerateTextFromVideo(object):
|
|
|
params=(2, video_text, state, task['pq_vid'])
|
|
|
)
|
|
|
os.remove("static/{}.mp4".format(task['pq_vid']))
|
|
|
- tqdm.write("识别完成,删除本地文件, 等待10s执行下一个任务")
|
|
|
+ tqdm.write("video transform to text success, delete local file, sleep 1 min...")
|
|
|
task_list.remove(task)
|
|
|
except Exception as e:
|
|
|
tqdm.write(str(e))
|
|
|
continue
|
|
|
|
|
|
case 'PROCESSING':
|
|
|
- print("video is still processing")
|
|
|
+ tqdm.write("video is still processing")
|
|
|
continue
|
|
|
|
|
|
case 'FAILED':
|
|
|
- print("video process failed")
|
|
|
+ tqdm.write("video process failed")
|
|
|
continue
|
|
|
time.sleep(10)
|
|
|
|
|
|
- print("执行完一轮任务,剩余数量:{}".format(len(task_list)))
|
|
|
- time.sleep(10)
|
|
|
+ tqdm.write("执行完一轮任务,剩余数量:{}".format(len(task_list)))
|
|
|
+ time.sleep(60)
|