"""Admin sound management routes.""" from flask import Blueprint, jsonify, request from app.services.decorators import require_admin, require_auth, require_role from app.services.error_handling_service import ErrorHandlingService from app.services.scheduler_service import scheduler_service from app.services.sound_normalizer_service import SoundNormalizerService from app.services.sound_scanner_service import SoundScannerService bp = Blueprint("admin_sounds", __name__) @bp.route("/scan", methods=["POST"]) @require_admin def scan_sounds(): """Manually trigger sound scanning.""" return ErrorHandlingService.handle_service_result( scheduler_service.trigger_sound_scan_now() ) @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