Commit 4c6547c8 by baiquan

修改上传sku图片结果的key为sku_id

parent a6850f5e
......@@ -140,14 +140,15 @@ async def uploadImageAndVideo(task: dict = None):
sku_image_list = []
for sku in skus:
for key, value in sku.items():
sku_id = sku.get('skuid')
if isinstance(value, dict):
img_url = value.get('image')
if img_url:
md5_key = hashlib.md5(img_url.encode()).hexdigest()
# md5_key = hashlib.md5(img_url.encode()).hexdigest()
local_path = get_local_path(item_id, img_url)
check_image_size(local_path)
local_path = convert_rect_to_square(local_path)
sku_image_list.append({md5_key: local_path})
sku_image_list.append({sku_id: local_path})
# 准备主图上传
image_list = []
......@@ -212,7 +213,7 @@ async def upload_videos(task: dict, item_id: str):
# 合并结果
for md5_key, result in results:
if result:
video_dict[md5_key] = result['video_url']
video_dict[md5_key] = result
return video_dict
......
......@@ -19,7 +19,7 @@ from tqdm import tqdm
from service.doudian_request import doudian_request
from service.doudian_service import generate_video
from utils.common import check_proxy
from utils.errors import VideoDurationError
from utils.errors import VideoError
HEADERS = {
"Content-Type": "application/json",
......@@ -629,7 +629,7 @@ def upload_video_with_multithreading(task):
# 准备视频文件(同原逻辑)
try:
file_path = prepare_video_file(task)
except VideoDurationError:
except VideoError:
# 视频时长超过60秒, 使用生成视频
video_info = generate_video(task)
return video_info
......@@ -693,13 +693,13 @@ def prepare_video_file(task):
else:
file_path = task.get("file_path")
if not os.path.exists(file_path):
raise Exception(f"视频文件 {file_path} 不存在")
raise VideoError(f"视频文件 {file_path} 不存在")
if is_video_corrupted(file_path):
raise Exception(f"视频文件 {file_path} 已损坏")
raise VideoError(f"视频文件 {file_path} 已损坏")
video_duration = get_video_duration(file_path)
if video_duration > 60:
logger.error("视频时长大于60秒,上传失败")
raise VideoDurationError("视频时长大于60秒,上传失败")
raise VideoError(f"{file_path} 视频时长大于60秒,上传失败")
is_valid, actual_ratio, best_match = check_video_aspect_ratio(file_path)
if is_valid:
logger.info(f"视频比例验证通过! ({best_match}, 实际比例: {actual_ratio:.4f})")
......@@ -708,7 +708,7 @@ def prepare_video_file(task):
logger.error(f"实际比例: {actual_ratio:.4f} ≈ {1 / actual_ratio:.2f}:1")
logger.error(f"最接近的标准比例: {best_match}")
logger.error(f"请上传1:1、3:4或9:16比例的视频")
raise Exception("视频长宽比错误,请上传1:1比例或者3:4比例或者9:16比例的主图视频")
raise VideoError(f"{file_path} 视频长宽比错误,请上传1:1比例或者3:4比例或者9:16比例的主图视频")
return file_path
......
......@@ -35,7 +35,7 @@ class ProxyConnectionError(AppError):
def __init__(self, msg='代理连接失败', data=None):
super().__init__(code=403, msg=msg, data=data)
class VideoDurationError(AppError):
"""视频时长异常"""
def __init__(self, msg='视频时长大于60秒', data=None):
class VideoError(AppError):
"""视频异常"""
def __init__(self, msg='上传视频失败', data=None):
super().__init__(code=406, msg=msg, data=data)
\ 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