@dp.message_handler(content_types=["video"])
async def download_video(message: types.Message):
file_id = message.video.file_id # Get file id
file = await bot.get_file(file_id) # Get file path
await bot.download_file(file.file_path, "video.mp4") # Download video and save output in file "video.mp4"
@dp.message_handler(content_types=["video"])
async def download_video(message: types.Message):
file_id = message.video.file_id # Get file id
file = await bot.get_file(file_id) # Get file path
video_number = 0 # Number video file
while(os.path.isfile(f"video{video_number}.mp4")): # If the file exists, add one to the number
video_number += 1
await bot.download_file(file.file_path, f"video{video_number}.mp4") # Download video and save output in file "video.mp4"
该数据库将帮助您将特定视频文件链接到特定用户。在其中,您可以将文件 ID 与用户 ID 相关联。以及何时需要与这些数据进行交互。
我使用这种方法
首先我们得到视频文件的id,然后我们得到文件的路径,然后我们才将结果保存到一个文件中。
video.mp4重要的是要知道MP4格式是电报的标准格式,最好不要尝试以其他格式保存。
如果您不想在每次视频上传后覆盖文件,请尝试此代码,有更优雅的解决方案,但这只是一个快速的解决方案。
该数据库将帮助您将特定视频文件链接到特定用户。在其中,您可以将文件 ID 与用户 ID 相关联。以及何时需要与这些数据进行交互。
aiogram 文档(文件下载)