refactor(discord): delegate ffmpeg discovery to shared tools.transcription_tools helper
Keep one owner for PATH/local-prefix ffmpeg discovery: ffmpeg_utils now delegates to tools.transcription_tools._find_ffmpeg_binary and only adds the Discord-specific FFMPEG_PATH override and Windows winget fallback on top (follow-up to PR #60627 by @LauraGPT, fixes #60624).
This commit is contained in:
parent
9b89da23fb
commit
a4c9994837
|
|
@ -1,4 +1,11 @@
|
|||
"""Shared ffmpeg executable discovery for Discord voice paths."""
|
||||
"""Shared ffmpeg executable discovery for Discord voice paths.
|
||||
|
||||
Discovery itself is owned by ``tools.transcription_tools`` (the same helper
|
||||
the STT pipeline uses — PATH plus common Homebrew/local prefixes); this module
|
||||
only layers the Discord-voice-specific extras on top: an explicit
|
||||
``FFMPEG_PATH`` override and a Windows winget fallback for installs that
|
||||
never touch PATH.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
|
@ -7,13 +14,22 @@ import shutil
|
|||
from pathlib import Path
|
||||
|
||||
|
||||
def _shared_find_ffmpeg():
|
||||
"""Delegate to the repo-wide ffmpeg discovery helper when importable."""
|
||||
try:
|
||||
from tools.transcription_tools import _find_ffmpeg_binary
|
||||
except ImportError: # standalone plugin import (tests / sandboxes)
|
||||
return shutil.which("ffmpeg")
|
||||
return _find_ffmpeg_binary()
|
||||
|
||||
|
||||
def resolve_ffmpeg_executable() -> str:
|
||||
"""Return an ffmpeg command that also covers common Windows installs."""
|
||||
explicit = os.getenv("FFMPEG_PATH")
|
||||
if explicit and explicit.strip():
|
||||
return os.path.expandvars(os.path.expanduser(explicit.strip()))
|
||||
|
||||
discovered = shutil.which("ffmpeg")
|
||||
discovered = _shared_find_ffmpeg()
|
||||
if discovered:
|
||||
return discovered
|
||||
|
||||
|
|
|
|||
|
|
@ -757,10 +757,22 @@ class TestVoiceReceiver:
|
|||
|
||||
monkeypatch.delenv("FFMPEG_PATH", raising=False)
|
||||
monkeypatch.setenv("LOCALAPPDATA", str(tmp_path))
|
||||
monkeypatch.setattr(ffmpeg_utils.shutil, "which", lambda _cmd: None)
|
||||
# Discovery delegates to tools.transcription_tools; simulate "not found".
|
||||
monkeypatch.setattr(ffmpeg_utils, "_shared_find_ffmpeg", lambda: None)
|
||||
|
||||
assert ffmpeg_utils.resolve_ffmpeg_executable() == str(ffmpeg)
|
||||
|
||||
def test_ffmpeg_resolver_delegates_to_shared_helper(self, monkeypatch):
|
||||
"""PATH/local-prefix discovery is owned by tools.transcription_tools."""
|
||||
from plugins.platforms.discord import ffmpeg_utils
|
||||
|
||||
monkeypatch.delenv("FFMPEG_PATH", raising=False)
|
||||
monkeypatch.setattr(
|
||||
"tools.transcription_tools._find_ffmpeg_binary", lambda: "/opt/homebrew/bin/ffmpeg"
|
||||
)
|
||||
|
||||
assert ffmpeg_utils.resolve_ffmpeg_executable() == "/opt/homebrew/bin/ffmpeg"
|
||||
|
||||
def test_pcm_to_wav_uses_resolved_ffmpeg_executable(self, monkeypatch, tmp_path):
|
||||
"""Receiver conversion should use the same resolved executable as playback."""
|
||||
from plugins.platforms.discord import adapter as discord_adapter
|
||||
|
|
|
|||
Loading…
Reference in New Issue