Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
doudian-py
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiquan
doudian-py
Commits
4c6547c8
Commit
4c6547c8
authored
Jul 12, 2025
by
baiquan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改上传sku图片结果的key为sku_id
parent
a6850f5e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
12 deletions
+14
-12
service/upload_image_and_video.py
+4
-3
service/upload_video.py
+6
-6
utils/errors.py
+4
-3
No files found.
service/upload_image_and_video.py
View file @
4c6547c8
...
...
@@ -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
...
...
service/upload_video.py
View file @
4c6547c8
...
...
@@ -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
Video
Duration
Error
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
Video
Duration
Error
:
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
Video
DurationError
(
"
视频时长大于60秒,上传失败"
)
raise
Video
Error
(
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
...
...
utils/errors.py
View file @
4c6547c8
...
...
@@ -35,7 +35,7 @@ class ProxyConnectionError(AppError):
def
__init__
(
self
,
msg
=
'代理连接失败'
,
data
=
None
):
super
()
.
__init__
(
code
=
403
,
msg
=
msg
,
data
=
data
)
class
Video
Duration
Error
(
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment