diff --git a/telegram_bot/handlers/audio_handler.py b/telegram_bot/handlers/audio_handler.py index 0d15825..0d9b24d 100644 --- a/telegram_bot/handlers/audio_handler.py +++ b/telegram_bot/handlers/audio_handler.py @@ -4,6 +4,15 @@ from functools import partial from aiogram import types, Dispatcher, F import ffmpeg +import logging + +logging.basicConfig( + filename="/shared_storage/bot_log.txt", + level=logging.DEBUG, + format="%(asctime)s - %(levelname)s - %(message)s" +) + + async def handle_voice_and_video(message: types.Message, redis_service, storage_path: str): file_id = None if message.content_type == types.ContentType.VOICE: @@ -14,6 +23,9 @@ async def handle_voice_and_video(message: types.Message, redis_service, storage_ if not file_id: return + if not os.path.exists(storage_path): + logging.error(f"❌ storage_path ({storage_path}) не существует!") + file = await message.bot.get_file(file_id) file_path = file.file_path @@ -28,10 +40,9 @@ async def handle_voice_and_video(message: types.Message, redis_service, storage_ await message.bot.download_file(file_path, temp_destination) if not os.path.exists(temp_destination): - print(f"❌ Ошибка: Файл {temp_destination} не был загружен!") + logging.error(f"❌ Файл {temp_destination} не был загружен!") else: - print(f"✅ Файл успешно загружен: {temp_destination}") - + logging.error(f"✅ Файл {temp_destination} был загружен!") wav_filename = f"{file_uuid}.wav" wav_destination = os.path.join(storage_path, wav_filename) @@ -39,9 +50,9 @@ async def handle_voice_and_video(message: types.Message, redis_service, storage_ convert_to_wav(temp_destination, wav_destination) if not os.path.exists(wav_destination): - print(f"❌ Ошибка: WAV-файл {wav_destination} не был создан!") + logging.error(f"❌ WAV-файл {wav_destination} не был создан!") else: - print(f"✅ WAV-файл успешно создан: {wav_destination}") + logging.error(f"✅ WAV-файл успешно создан: {wav_destination}") os.remove(temp_destination)