From de459417f789d789b84da03da460c6f35ecb8446 Mon Sep 17 00:00:00 2001 From: scayac Date: Wed, 15 Apr 2026 14:04:40 +0200 Subject: [PATCH] Bug proxy --- backend/app/audio_player.py | 12 +++++++----- backend/app/main.py | 1 + backend/systemd/pysonnerie-backend.service | 3 ++- frontend/app/backend_client.py | 6 ++++-- frontend/systemd/pysonnerie-frontend.service | 3 ++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/backend/app/audio_player.py b/backend/app/audio_player.py index 46df0d8..b124476 100644 --- a/backend/app/audio_player.py +++ b/backend/app/audio_player.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +import shutil import subprocess import threading from pathlib import Path @@ -86,12 +87,11 @@ class AudioPlayer: raise ValueError("end_seconds must be greater than start_seconds") volume_factor = max(0.0, min(1.0, float(volume) / 100.0)) - cmd = [ + base_cmd = [ "play", "-q", "-v", str(volume_factor), - str(music_path), ] effects: list[str] = [] @@ -134,14 +134,14 @@ class AudioPlayer: effects += ["repeat", str(int(repeat_count))] # If sox lacks mp3 handlers, decode with ffmpeg and stream wav to sox. - if music_path.suffix.lower() == ".mp3": + if music_path.suffix.lower() == ".mp3" and shutil.which("ffmpeg"): decoder_cmd = ["ffmpeg", "-v", "error", "-i", str(music_path), "-f", "wav", "-"] self._decoder_proc = subprocess.Popen( decoder_cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, ) - cmd += ["-t", "wav", "-"] + effects + cmd = base_cmd + ["-t", "wav", "-"] + effects self._proc = subprocess.Popen( cmd, stdin=self._decoder_proc.stdout, @@ -151,7 +151,9 @@ class AudioPlayer: if self._decoder_proc.stdout is not None: self._decoder_proc.stdout.close() else: - cmd += [str(music_path)] + effects + if music_path.suffix.lower() == ".mp3": + logger.warning("ffmpeg unavailable, falling back to direct sox playback for %s", music_path) + cmd = base_cmd + [str(music_path)] + effects self._proc = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) def stop(self) -> None: diff --git a/backend/app/main.py b/backend/app/main.py index 1ec3ce8..3ea7350 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -218,6 +218,7 @@ def force_play(trigger_id: str, repeat_count: int | None = None) -> Dict[str, st except KeyError: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Unknown trigger") except (FileNotFoundError, ValueError, RuntimeError) as exc: + logging.getLogger("pysonnerie.api").warning("Force play failed for %s: %s", trigger_id, exc) raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) return {"status": "playing"} diff --git a/backend/systemd/pysonnerie-backend.service b/backend/systemd/pysonnerie-backend.service index a8aca2f..049a230 100644 --- a/backend/systemd/pysonnerie-backend.service +++ b/backend/systemd/pysonnerie-backend.service @@ -7,9 +7,10 @@ Type=simple User=www-data WorkingDirectory=/opt/pySonnerie/backend Environment=PATH=/opt/pySonnerie/backend/.venv/bin:/usr/bin:/bin +Environment=NO_PROXY=127.0.0.1,localhost,::1 +Environment=no_proxy=127.0.0.1,localhost,::1 #Environment=http_proxy=http://proxy:port #Environment=https_proxy=http://proxy:port -#Environment=no_proxy=127.0.0.1,localhost ExecStart=/opt/pySonnerie/backend/.venv/bin/python /opt/pySonnerie/backend/run.py Restart=on-failure RestartSec=3 diff --git a/frontend/app/backend_client.py b/frontend/app/backend_client.py index 12418ff..7876041 100644 --- a/frontend/app/backend_client.py +++ b/frontend/app/backend_client.py @@ -40,11 +40,13 @@ class BackendClient: self.base_url = base_url.rstrip("/") self.auth = (username, password) self.timeout = 8 + self.session = requests.Session() + self.session.trust_env = False def _request(self, method: str, path: str, json_payload: dict[str, Any] | None = None) -> Any: url = f"{self.base_url}{path}" try: - response = requests.request( + response = self.session.request( method=method, url=url, auth=self.auth, @@ -75,7 +77,7 @@ class BackendClient: def health(self) -> dict[str, Any]: url = f"{self.base_url}/api/health" try: - response = requests.get(url, timeout=self.timeout, verify=False) + response = self.session.get(url, timeout=self.timeout, verify=False) response.raise_for_status() return response.json() except requests.RequestException as exc: diff --git a/frontend/systemd/pysonnerie-frontend.service b/frontend/systemd/pysonnerie-frontend.service index 1e7fbf0..f32b9bd 100644 --- a/frontend/systemd/pysonnerie-frontend.service +++ b/frontend/systemd/pysonnerie-frontend.service @@ -9,9 +9,10 @@ Group=www-data WorkingDirectory=/opt/pySonnerie/frontend Environment=FRONTEND_BIND=0.0.0.0:5000 Environment=PATH=/opt/pySonnerie/frontend/.venv/bin:/usr/bin:/bin +Environment=NO_PROXY=127.0.0.1,localhost,::1 +Environment=no_proxy=127.0.0.1,localhost,::1 #Environment=http_proxy=http://TON_PROXY:PORT #Environment=https_proxy=http://TON_PROXY:PORT -#Environment=no_proxy=127.0.0.1,localhost ExecStart=/opt/pySonnerie/frontend/.venv/bin/gunicorn --workers 2 --bind ${FRONTEND_BIND} wsgi:app Restart=on-failure RestartSec=3