|
@@ -211,6 +211,15 @@ async def _download_video(url: str, dest: Path, timeout: float) -> None:
|
|
|
file_obj.write(chunk)
|
|
file_obj.write(chunk)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _safe_unlink(path: Path) -> None:
|
|
|
|
|
+ """删除临时视频文件,失败时仅记录日志。"""
|
|
|
|
|
+ try:
|
|
|
|
|
+ if path.is_file():
|
|
|
|
|
+ path.unlink()
|
|
|
|
|
+ except OSError as exc:
|
|
|
|
|
+ logger.warning("failed to delete temp video file %s: %s", path, exc)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _upload_clip(local_path: Path, source_url: str, max_duration_seconds: float) -> str:
|
|
def _upload_clip(local_path: Path, source_url: str, max_duration_seconds: float) -> str:
|
|
|
url_hash = hashlib.sha256(source_url.encode()).hexdigest()[:16]
|
|
url_hash = hashlib.sha256(source_url.encode()).hexdigest()[:16]
|
|
|
client = OssClient()
|
|
client = OssClient()
|
|
@@ -263,6 +272,7 @@ async def _prepare_analysis_url(
|
|
|
"downloaded video within limit, skip truncate: duration=%.1fs",
|
|
"downloaded video within limit, skip truncate: duration=%.1fs",
|
|
|
duration,
|
|
duration,
|
|
|
)
|
|
)
|
|
|
|
|
+ _safe_unlink(source_path)
|
|
|
return video_url, meta
|
|
return video_url, meta
|
|
|
|
|
|
|
|
_ensure_oss_configured()
|
|
_ensure_oss_configured()
|
|
@@ -273,12 +283,15 @@ async def _prepare_analysis_url(
|
|
|
clipped_path,
|
|
clipped_path,
|
|
|
max_duration_seconds,
|
|
max_duration_seconds,
|
|
|
)
|
|
)
|
|
|
|
|
+ _safe_unlink(source_path)
|
|
|
|
|
+
|
|
|
analysis_url = await asyncio.to_thread(
|
|
analysis_url = await asyncio.to_thread(
|
|
|
_upload_clip,
|
|
_upload_clip,
|
|
|
clipped_path,
|
|
clipped_path,
|
|
|
video_url,
|
|
video_url,
|
|
|
max_duration_seconds,
|
|
max_duration_seconds,
|
|
|
)
|
|
)
|
|
|
|
|
+ _safe_unlink(clipped_path)
|
|
|
|
|
|
|
|
meta["truncated"] = True
|
|
meta["truncated"] = True
|
|
|
meta["analysis_video_url"] = analysis_url
|
|
meta["analysis_video_url"] = analysis_url
|