Commit 2e7fc8be by wangzhiyang Committed by 胡悦

fix(meeting_minutes): 优化媒体URL清理逻辑并完善错误日志

修复媒体URL清理函数的处理逻辑,新增日志URL脱敏和FFmpeg输出摘要辅助函数,并完善媒体时长探测的错误日志记录。
1 parent 73928a6a
...@@ -33,11 +33,15 @@ _MEDIA_PROBE_TIMEOUT_SECONDS = 20 ...@@ -33,11 +33,15 @@ _MEDIA_PROBE_TIMEOUT_SECONDS = 20
def _sanitize_media_url(url: str) -> str: def _sanitize_media_url(url: str) -> str:
s = (url or "").strip() s = (url or "").strip()
if len(s) >= 2 and s[0] == s[-1] and s[0] in ("`", '"', "'"): if "\\`" in s:
s = s[1:-1].strip() s = s.replace("\\`", "`")
while s and s[0] in ("`", '"', "'"):
s = s[1:].lstrip()
while s and s[-1] in ("`", '"', "'"):
s = s[:-1].rstrip()
if len(s) >= 2 and s[0] == "<" and s[-1] == ">": if len(s) >= 2 and s[0] == "<" and s[-1] == ">":
s = s[1:-1].strip() s = s[1:-1].strip()
return s return s.strip()
def _http_open(url: str, *, method: str = "GET", headers: Optional[dict] = None): def _http_open(url: str, *, method: str = "GET", headers: Optional[dict] = None):
...@@ -85,10 +89,26 @@ def _get_ffmpeg_exe() -> Optional[str]: ...@@ -85,10 +89,26 @@ def _get_ffmpeg_exe() -> Optional[str]:
except Exception: except Exception:
return shutil.which("ffmpeg") return shutil.which("ffmpeg")
def _scrub_urls_for_log(text: str) -> str:
if not text:
return ""
return re.sub(r"https?://[^\s'\"<>]+", "[URL]", text)
def _summarize_ffmpeg_output(stdout: str, stderr: str, *, max_lines: int = 30, max_chars: int = 800) -> str:
merged = f"{stdout or ''}\n{stderr or ''}".strip()
merged = _scrub_urls_for_log(merged)
lines = [ln.strip() for ln in merged.splitlines() if ln.strip()]
if not lines:
return ""
summary = " | ".join(lines[:max_lines])
return summary[:max_chars]
def _probe_duration_seconds(url: str) -> Optional[float]: def _probe_duration_seconds(url: str) -> Optional[float]:
ffmpeg = _get_ffmpeg_exe() ffmpeg = _get_ffmpeg_exe()
if not ffmpeg: if not ffmpeg:
logger.info("ffmpeg 探测时长失败:未找到可用的 ffmpeg 可执行文件")
return None return None
cmd = [ cmd = [
...@@ -106,12 +126,18 @@ def _probe_duration_seconds(url: str) -> Optional[float]: ...@@ -106,12 +126,18 @@ def _probe_duration_seconds(url: str) -> Optional[float]:
timeout=_MEDIA_PROBE_TIMEOUT_SECONDS, timeout=_MEDIA_PROBE_TIMEOUT_SECONDS,
check=False, check=False,
) )
except Exception: except Exception as e:
logger.info("ffmpeg 探测时长异常: %s", str(e))
return None return None
output = f"{res.stdout or ''}\n{res.stderr or ''}" output = f"{res.stdout or ''}\n{res.stderr or ''}"
m = re.search(r"Duration:\s*(\d+):(\d+):(\d+(?:\.\d+)?)", output) m = re.search(r"Duration:\s*(\d+):(\d+):(\d+(?:\.\d+)?)", output)
if not m: if not m:
summary = _summarize_ffmpeg_output(res.stdout or "", res.stderr or "")
if summary:
logger.info("ffmpeg 探测时长失败:returncode=%s, 输出摘要=%s", res.returncode, summary)
else:
logger.info("ffmpeg 探测时长失败:returncode=%s, 无输出", res.returncode)
return None return None
hours = int(m.group(1)) hours = int(m.group(1))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!