Skip to content

Commit

Permalink
Merge pull request #29 from dimonier/19-на-mac-os-не-работает-модуль-…
Browse files Browse the repository at this point in the history
…whisper

Incorporated this change & fixed bug preventing downloads of documens and videos
  • Loading branch information
dimonier authored Oct 15, 2024
2 parents 9796d9c + b05d6c1 commit 31b7766
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tg2obsidian_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def help(message: types.Message):
@dp.message(F.voice)
async def handle_voice_message(message: Message):
if message.chat.id != config.my_chat_id: return
log_basic(f'Received voice message from @{message.from_user.username}')
log_basic(f'Received (?) voice message from @{message.from_user.username}')
log_message(message)
if not config.recognize_voice:
log_basic(f'Voice recognition is turned OFF')
Expand Down Expand Up @@ -170,7 +170,7 @@ async def handle_document(message: Message):
print(f'Got document: {file_name}')

try:
file = await message.document.get_file()
file = await bot.get_file(message.document.file_id)
await handle_file(file=file, file_name=file_name, path=config.photo_path)
except Exception as e:
log_basic(f'Exception: {e}')
Expand Down Expand Up @@ -231,12 +231,15 @@ async def handle_location(message: Message):
async def handle_animation(message: Message):
if message.chat.id != config.my_chat_id: return
log_message(message)
file_name = unique_filename(message.document.file_name, config.photo_path)
if message.document.file_name:
file_name = unique_filename(message.document.file_name, config.photo_path)
else:
file_name = unique_indexed_filename(create_media_file_name(message, 'animation', 'mp4'), config.photo_path)
log_basic(f'Received animation {file_name} from @{message.from_user.username}')
print(f'Got animation: {file_name}')
note = note_from_message(message)

file = await message.document.get_file()
file = await bot.get_file(message.document.file_id)
# file_path = file.file_path
await handle_file(file=file, file_name=file_name, path=config.photo_path)

Expand All @@ -250,12 +253,15 @@ async def handle_animation(message: Message):
async def handle_video(message: Message):
if message.chat.id != config.my_chat_id: return
log_message(message)
file_name = unique_filename(message.video.file_name, config.photo_path)
if message.video.file_name:
file_name = unique_filename(message.video.file_name, config.photo_path)
else:
file_name = unique_indexed_filename(create_media_file_name(message, 'video', 'mp4'), config.photo_path)
log_basic(f'Received video {file_name} from @{message.from_user.username}')
print(f'Got video: {file_name}')
note = note_from_message(message)

file = await message.video.get_file()
file = await bot.get_file(message.video.file_id)
# file_path = file.file_path
await handle_file(file=file, file_name=file_name, path=config.photo_path)

Expand All @@ -273,7 +279,7 @@ async def handle_video_note(message: Message):
print(f'Got video note: {file_name}')
note = note_from_message(message)

file = await message.video_note.get_file()
file = await bot.get_file(message.video_note.file_id)
# file_path = file.file_path
await handle_file(file=file, file_name=file_name, path=config.photo_path)

Expand Down

0 comments on commit 31b7766

Please sign in to comment.