Commit 7808832

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-05-05 12:37:03
fix(subtitle): cache `fetch_subtitle` for 2 minutes
1 parent 18ecdee
Changed files (1)
src
subtitles
src/subtitles/base.py
@@ -9,7 +9,7 @@ from pyrogram.client import Client
 from pyrogram.types import Message
 from youtube_transcript_api import YouTubeTranscriptApi  # type: ignore
 
-from config import API, PREFIX, PROXY, READING_SPEED, TOKEN, TZ
+from config import API, PREFIX, PROXY, READING_SPEED, TOKEN, TZ, cache
 from messages.parser import parse_msg
 from messages.utils import startswith_prefix
 from networking import hx_req, match_social_media_link
@@ -47,6 +47,7 @@ async def match_url(client: Client, message: Message) -> str:
     return ""
 
 
+@cache.memoize(ttl=120)
 async def fetch_subtitle(url: str, provider: str) -> dict:
     """Fetch subtitles from YouTube."""
     succ = False