Commit 00d8acb1 by baiquan

feat(service): 优化视频生成功能

- 为 video_toDouyin 添加重试机制,最多重试 3 次
- 修改 get_task_result 函数,返回 None 以便于上层处理重试逻辑
parent bff03e4d
......@@ -146,16 +146,23 @@ def generate_video(task: dict):
ua = headers['user-agent']
else:
raise Exception('User-Agent not found')
a_bogus = generate_a_bogus(params, json_data, ua)
params['a_bogus'] = a_bogus
logger.info("开始生成视频")
url = 'https://fxg.jinritemai.com/product/tproduct/material/imageTextVideo/submitImgOptimizeTask4PC'
response = doudian_request("POST", url, proxies, params, json=json_data, headers=headers, cookies=cookies)
task_id = response['data']['task_id']
logger.info(f"任务id --> {task_id}")
tool_source = response['data']['tool_source']
result = get_task_result(task_id, headers, tool_source, ua, proxies, cookies)
return result
retry_count = 0
while True:
if retry_count > 3:
raise Exception('生成视频失败')
a_bogus = generate_a_bogus(params, json_data, ua)
params['a_bogus'] = a_bogus
logger.info("开始生成视频")
url = 'https://fxg.jinritemai.com/product/tproduct/material/imageTextVideo/submitImgOptimizeTask4PC'
response = doudian_request("POST", url, proxies, params, json=json_data, headers=headers, cookies=cookies)
task_id = response['data']['task_id']
logger.info(f"任务id --> {task_id}")
tool_source = response['data']['tool_source']
result = get_task_result(task_id, headers, tool_source, ua, proxies, cookies)
if not result:
retry_count += 1
continue
return result
def get_task_result(task_id: str, headers: dict, tool_source: str, ua, proxies, cookies):
"""获取任务结果"""
......@@ -186,4 +193,5 @@ def get_task_result(task_id: str, headers: dict, tool_source: str, ua, proxies,
logger.success(f'视频生成成功-->{result}')
return result
else:
raise Exception(f'任务执行失败-->{msg}')
\ No newline at end of file
logger.error(f'任务执行失败-->{msg}')
return None
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment