Refactor OAuth provider linking and unlinking logic into a dedicated service; enhance error handling and logging throughout the application; improve sound management and scanning services with better file handling and unique naming; implement centralized error and logging services for consistent API responses and application-wide logging configuration.

This commit is contained in:
JSC
2025-07-05 13:07:06 +02:00
parent 41fc197f4c
commit e2fe451e5a
17 changed files with 758 additions and 352 deletions

View File

@@ -39,7 +39,9 @@ class SoundNormalizerService:
@staticmethod
def normalize_sound(
sound_id: int, overwrite: bool = False, two_pass: bool = True
sound_id: int,
overwrite: bool = False,
two_pass: bool = True,
) -> dict:
"""Normalize a specific sound file using ffmpeg loudnorm.
@@ -250,7 +252,8 @@ class SoundNormalizerService:
logger.debug("Starting first pass (analysis)")
first_pass_result = SoundNormalizerService._run_first_pass(
source_path, params
source_path,
params,
)
if not first_pass_result["success"]:
@@ -262,7 +265,10 @@ class SoundNormalizerService:
logger.debug("Starting second pass (normalization)")
second_pass_result = SoundNormalizerService._run_second_pass(
source_path, output_path, params, measured_params
source_path,
output_path,
params,
measured_params,
)
if not second_pass_result["success"]:
@@ -297,7 +303,8 @@ class SoundNormalizerService:
@staticmethod
def _normalize_with_ffmpeg_single_pass(
source_path: str, output_path: str
source_path: str,
output_path: str,
) -> dict:
"""Run ffmpeg loudnorm on a single file using single-pass normalization.
@@ -374,6 +381,7 @@ class SoundNormalizerService:
Returns:
dict: Result with measured parameters and analysis stats
"""
try:
# Create ffmpeg input stream
@@ -389,7 +397,10 @@ class SoundNormalizerService:
# Output to null device for analysis
output_stream = ffmpeg.output(
input_stream, "/dev/null", af=loudnorm_filter, f="null"
input_stream,
"/dev/null",
af=loudnorm_filter,
f="null",
)
# Run the first pass
@@ -403,7 +414,7 @@ class SoundNormalizerService:
# Parse measured parameters from JSON output
measured_params = SoundNormalizerService._parse_measured_params(
stderr_text
stderr_text,
)
if not measured_params:
@@ -446,6 +457,7 @@ class SoundNormalizerService:
Returns:
dict: Result with normalization stats
"""
try:
# Create ffmpeg input stream
@@ -506,11 +518,14 @@ class SoundNormalizerService:
Returns:
dict: Parsed measured parameters, empty if parsing fails
"""
try:
# Find JSON block in stderr output
json_match = re.search(
r'\{[^}]*"input_i"[^}]*\}', stderr_output, re.DOTALL
r'\{[^}]*"input_i"[^}]*\}',
stderr_output,
re.DOTALL,
)
if not json_match:
logger.warning("No JSON block found in first pass output")