python-wechaty
python-wechaty copied to clipboard
怎么存储语音和图片等文件信息?
if msg.type()==MessageType.MESSAGE_TYPE_AUDIO: #语音 audio_file_box = await msg.to_file_box() print(audio_file_box.type()) print(f'保存语音文件<{audio_file_box.name}>') await audio_file_box.to_file('./files/audio_fils/'+audio_file_box.name)
if msg.type()==MessageType.MESSAGE_TYPE_IMAGE: #图片 img_file = msg.to_image() img_name = img_file.image_id print(f'保存图片文件<{img_name}>') try: img_file_box = await img_file.hd() #高清图,是filebox对象 其他还有thumbnail缩略图和 artwork print(img_file_box.type()) await img_file_box.to_file(img_name+'.png') except Exception as e: print(e)
测试:语音文件用to_file_box() 出错 图片文件,我看有to_image()方法,能获取图片id,但是没有save选项,但是可以转化为filebox来to_file。但是,nothing happened
补充:用img_file_box = await img_file.hd() 会导致整个程序卡住,慎用
I know that you have a great solution for audio message and parse it to mp3 type file. It's a great contribution If you share it at this issue comment.
Hope your sharing.
怎样判断图片类型是GIF或png?
怎样判断图片类型是GIF或png?
file_box = await msg.to_file_box()
if file_box:
await file_box.to_file(file_box.name)
Yes, as your code showing, you can get the type of image depending on the file.