Commit bd7946e

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-08-08 05:35:21
fix(subtitle): handle unexpected errors in subtitle fetching
1 parent 3ad2a13
Changed files (2)
src
src/subtitles/base.py
@@ -76,6 +76,8 @@ async def fetch_subtitle(url: str, provider: str) -> dict:
             succ = True
         except (IpBlocked, RequestBlocked):
             logger.warning(f"Subtitle API IP blocked: {video_id=}")
+        except Exception as e:
+            logger.error(f"Failed to get subtitle: {e}")
     if not succ and "tikhub" in provider:  # try tikhub
         try:
             logger.info(f"Fetch Subtitle via TikHub for {video_id=}")
@@ -90,7 +92,8 @@ async def fetch_subtitle(url: str, provider: str) -> dict:
             subtitles = resp["data"].get("subtitles", [])
         except Exception as e:
             logger.error(f"Failed to get subtitle: {e}")
-            return {"error": error}
+    if not subtitles:
+        return {"error": error}
     return to_transcription(subtitles)
 
 
src/multimedia.py
@@ -267,6 +267,8 @@ async def generate_cover(path: Path | str) -> str:
         str: cover path
     """
     logger.debug(f"Generate cover for: {path}")
+    if not Path(path).expanduser().resolve().is_file():
+        return ""
     jpg_path = Path(path).with_suffix(".jpg")
     for ext in [".jpg", ".jpeg"]:
         cover_path = Path(path).with_suffix(ext)