@@ -502,6 +502,24 @@ def f_text(text: str) -> str:
502502 else :
503503 return text
504504
505+ @staticmethod
506+ async def tg_compatible (img : str | Path ) -> BinaryIO | str :
507+ """将图片转换为Tg兼容的格式"""
508+
509+ ext = Path (img ).suffix .lower ()
510+ if ext not in [".heif" , ".heic" ]:
511+ return str (img )
512+
513+ loop = asyncio .get_running_loop ()
514+ try :
515+ return await asyncio .wait_for (
516+ loop .run_in_executor (EXC , img2webp , img ),
517+ timeout = 30 ,
518+ )
519+ except Exception as e :
520+ logger .exception (e )
521+ return str (img )
522+
505523
506524class VideoParseResultOperate (ParseResultOperate ):
507525 """视频解析结果操作"""
@@ -576,7 +594,7 @@ async def chat_upload(
576594 )
577595 elif count == 1 :
578596 return await msg .reply_photo (
579- self .download_result .media [0 ].path ,
597+ await self .tg_compatible ( self . download_result .media [0 ].path ) ,
580598 quote = True ,
581599 caption = text ,
582600 reply_markup = self .button (),
@@ -616,25 +634,6 @@ async def limited_ih(path: str):
616634 f"{ self .result .desc } <br><br>" + "" .join (results ), msg
617635 )
618636
619- @staticmethod
620- async def tg_compatible (img : str | Path ) -> BinaryIO | str :
621- """将图片转换为Tg兼容的格式"""
622-
623- ext = Path (img ).suffix .lower ()
624- if ext not in [".heif" , ".heic" ]:
625- return str (img )
626-
627- loop = asyncio .get_running_loop ()
628- try :
629- r = await asyncio .wait_for (
630- loop .run_in_executor (EXC , img2webp , img ),
631- timeout = 30 ,
632- )
633- return r
634- except Exception as e :
635- logger .exception (e )
636- return str (img )
637-
638637
639638class MultimediaParseResultOperate (ParseResultOperate ):
640639 """图片视频混合解析结果操作"""
@@ -661,7 +660,7 @@ async def chat_upload(
661660 "reply_markup" : self .button (),
662661 }
663662 if isinstance (m , Image ):
664- return await msg .reply_photo (m .path , ** k )
663+ return await msg .reply_photo (await self . tg_compatible ( m .path ) , ** k )
665664 elif isinstance (m , Video ):
666665 return await msg .reply_video (
667666 m .path ,
@@ -682,7 +681,7 @@ async def chat_upload(
682681 ani_msg = []
683682 for i , v in enumerate (self .download_result .media ):
684683 if isinstance (v , Image ):
685- media .append (InputMediaPhoto (v .path ))
684+ media .append (InputMediaPhoto (await self . tg_compatible ( v .path ) ))
686685 elif isinstance (v , Video ):
687686 media .append (
688687 InputMediaVideo (
0 commit comments