135 lines
4.0 KiB
Python
135 lines
4.0 KiB
Python
"""Admin sound management routes."""
|
|
|
|
from flask import Blueprint, request
|
|
|
|
from app.services.decorators import require_admin
|
|
from app.services.error_handling_service import ErrorHandlingService
|
|
from app.services.sound_normalizer_service import SoundNormalizerService
|
|
from app.services.sound_scanner_service import SoundScannerService
|
|
|
|
bp = Blueprint("admin_sounds", __name__, url_prefix="/api/admin/sounds")
|
|
|
|
|
|
@bp.route("/scan", methods=["POST"])
|
|
@require_admin
|
|
def scan_sounds():
|
|
"""Manually trigger sound scanning."""
|
|
return ErrorHandlingService.wrap_service_call(
|
|
SoundScannerService.scan_soundboard_directory,
|
|
request.get_json().get("directory") if request.get_json() else None,
|
|
)
|
|
|
|
|
|
@bp.route("/scan/status", methods=["GET"])
|
|
@require_admin
|
|
def get_scan_status():
|
|
"""Get current scan statistics and status."""
|
|
return ErrorHandlingService.wrap_service_call(
|
|
SoundScannerService.get_scan_statistics,
|
|
)
|
|
|
|
|
|
@bp.route("/normalize", methods=["POST"])
|
|
@require_admin
|
|
def normalize_sounds():
|
|
"""Normalize sounds (all or specific)."""
|
|
try:
|
|
data = request.get_json() or {}
|
|
sound_id = data.get("sound_id")
|
|
overwrite = data.get("overwrite", False)
|
|
two_pass = data.get("two_pass", True)
|
|
limit = data.get("limit")
|
|
|
|
if sound_id:
|
|
# Normalize specific sound
|
|
result = SoundNormalizerService.normalize_sound(
|
|
sound_id,
|
|
overwrite,
|
|
two_pass,
|
|
)
|
|
else:
|
|
# Normalize all sounds
|
|
result = SoundNormalizerService.normalize_all_sounds(
|
|
overwrite,
|
|
limit,
|
|
two_pass,
|
|
)
|
|
|
|
if result["success"]:
|
|
return jsonify(result), 200
|
|
return jsonify(result), 400
|
|
except Exception as e:
|
|
return jsonify({"error": str(e)}), 500
|
|
|
|
|
|
@bp.route("/normalize/status", methods=["GET"])
|
|
@require_admin
|
|
def get_normalization_status():
|
|
"""Get normalization statistics and status."""
|
|
try:
|
|
status = SoundNormalizerService.get_normalization_status()
|
|
return jsonify(status), 200
|
|
except Exception as e:
|
|
return jsonify({"error": str(e)}), 500
|
|
|
|
|
|
@bp.route("/ffmpeg/check", methods=["GET"])
|
|
@require_admin
|
|
def check_ffmpeg():
|
|
"""Check ffmpeg availability and capabilities."""
|
|
try:
|
|
ffmpeg_status = SoundNormalizerService.check_ffmpeg_availability()
|
|
return jsonify(ffmpeg_status), 200
|
|
except Exception as e:
|
|
return jsonify({"error": str(e)}), 500
|
|
|
|
|
|
@bp.route("/list", methods=["GET"])
|
|
@require_admin
|
|
def list_sounds():
|
|
"""Get detailed list of all sounds with normalization status."""
|
|
from app.services.sound_management_service import SoundManagementService
|
|
|
|
return ErrorHandlingService.wrap_service_call(
|
|
SoundManagementService.get_sounds_with_file_status,
|
|
request.args.get("type", "SDB"),
|
|
int(request.args.get("page", 1)),
|
|
int(request.args.get("per_page", 50)),
|
|
)
|
|
|
|
|
|
@bp.route("/<int:sound_id>", methods=["DELETE"])
|
|
@require_admin
|
|
def delete_sound(sound_id: int):
|
|
"""Delete a sound and its files."""
|
|
from app.services.sound_management_service import SoundManagementService
|
|
|
|
return ErrorHandlingService.wrap_service_call(
|
|
SoundManagementService.delete_sound_with_files,
|
|
sound_id,
|
|
)
|
|
|
|
|
|
@bp.route("/<int:sound_id>/normalize", methods=["POST"])
|
|
@require_admin
|
|
def normalize_single_sound(sound_id: int):
|
|
"""Normalize a specific sound."""
|
|
try:
|
|
from app.services.sound_management_service import SoundManagementService
|
|
|
|
data = request.get_json() or {}
|
|
overwrite = data.get("overwrite", False)
|
|
two_pass = data.get("two_pass", True)
|
|
|
|
result = SoundManagementService.normalize_sound(
|
|
sound_id,
|
|
overwrite,
|
|
two_pass,
|
|
)
|
|
|
|
if result["success"]:
|
|
return jsonify(result), 200
|
|
return jsonify(result), 400
|
|
except Exception as e:
|
|
return jsonify({"error": str(e)}), 500
|