Commit 9ff57ab

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-05-29 12:05:41
fix(async): ensure video/audio validation is async
1 parent d1edd6c
Changed files (4)
src/messages/preprocess.py
@@ -72,12 +72,12 @@ async def preprocess_media(media: list[dict]) -> list[dict]:
         thumb = data.get("thumb")  # thumb is provided
         if video_path := data.get("video"):
             video_path = await fix_video_rotation(video_path)
-            if not is_valid_video_or_audio(video_path):
+            if not await is_valid_video_or_audio(video_path):
                 logger.warning(f"Video is invalid: {video_path}")
                 continue
 
             # split large video files ( < 2GB)
-            valid_videos = [x for x in await split_large_video(video_path) if is_valid_video_or_audio(x)]
+            valid_videos = [x for x in await split_large_video(video_path) if await is_valid_video_or_audio(x)]
 
             # generate thumbnails for each video if thumb is not provided
             thumbs = [valid_thumb for _ in valid_videos] if (valid_thumb := await validate_img(thumb)) else [await generate_cover(x) for x in valid_videos]
@@ -92,7 +92,7 @@ async def preprocess_media(media: list[dict]) -> list[dict]:
             done_audios.append(data)
             continue
         audio_path = Path(data.get("audio", ""))
-        if not is_valid_video_or_audio(audio_path):
+        if not await is_valid_video_or_audio(audio_path):
             logger.warning(f"Audio is invalid: {audio_path}")
             continue
         audio_info = await parse_media_info(audio_path)
src/others/download_external.py
@@ -72,7 +72,7 @@ async def download_url_in_message(client: Client, message: Message, extra_prefix
         elif path.suffix in [".m4a", ".mp3", ".wav", ".ogg", ".opus", ".flac", ".aac"]:
             await modify_progress(text=f"πŸŽ§ιŸ³ι’‘δΈ‹θ½½ζˆεŠŸ: {readable_size(path=path)}", force_update=True, **kwargs)
             success = await client.send_audio(target_chat, path.as_posix(), caption=caption, reply_parameters=reply_parameters)
-        elif is_valid_video_or_audio(path, delete=False):
+        elif await is_valid_video_or_audio(path, delete=False):
             await modify_progress(text=f"πŸŽ¬θ§†ι’‘δΈ‹θ½½ζˆεŠŸ: {readable_size(path=path)}", force_update=True, **kwargs)
             success = await send2tg(client, message, target_chat, reply_msg_id, texts=caption, media=[{"video": path}])
         elif path.stat().st_size < MAX_FILE_BYTES:
src/preview/instagram.py
@@ -150,7 +150,7 @@ async def preview_ddinstagram(client: Client, message: Message, url: str, post_t
         if video_url:
             raw_url = f"{API.DDINSTAGRAM}{video_url}"
             media["video"] = await download_file(raw_url, path=f"{DOWNLOAD_DIR}/{post_id}.mp4", proxy=PROXY.INSTAGRAM, **kwargs)
-            if not is_valid_video_or_audio(media["video"]):
+            if not await is_valid_video_or_audio(media["video"]):
                 await send_to_social_media_bridge(client, message, text=url, **kwargs)
                 return
 
src/multimedia.py
@@ -442,9 +442,9 @@ async def validate_img(path: str | Path | None, *, force_jpg: bool = True, delet
     return path.as_posix() if path.is_file() else ""
 
 
-def is_valid_video_or_audio(path: str | Path | None, *, delete: bool = True) -> bool:
+async def is_valid_video_or_audio(path: str | Path | None, *, delete: bool = True) -> bool:
     """Check if the video is valid."""
-    if parse_media_info(path):
+    if await parse_media_info(path):
         return True
 
     logger.error(f"Invalid video: {path}")