Commit 9bc12e3
Changed files (2)
src
preview
subtitles
src/preview/ytdlp.py
@@ -260,6 +260,7 @@ async def preview_ytdlp(
res = await fetch_subtitle(url=url, provider="free")
subtitles = res.get("subtitle", "")
if not subtitles:
+ ytdlp_transcription_engine = "gemini" if "youtube" in info["extractor"] else ytdlp_transcription_engine # use gemini to bypass censorship
res = await asr_file(audio_path, ytdlp_transcription_engine, duration, client=client, message=message, slient=True)
subtitles = res.get("texts", "")
if subtitles:
src/subtitles/subtitle.py
@@ -42,7 +42,8 @@ async def get_subtitle(client: Client, message: Message, youtube_subtitle_provid
return
if not (url := await match_url(client, message)):
return
-
+ matched = await match_social_media_link(url)
+ platform = matched["platform"]
msg = f"🔍**正在获取字幕**\n{url}"
if kwargs.get("show_progress"):
res = await send2tg(client, message, texts=msg, **kwargs)
@@ -63,7 +64,8 @@ async def get_subtitle(client: Client, message: Message, youtube_subtitle_provid
if this_info["mtype"] in ["audio", "video"] or reply_info.get("mtype", "") in ["audio", "video"]:
msg = message if this_info["mtype"] in ["audio", "video"] else message.reply_to_message
fpath: str = await client.download_media(message) # type: ignore
- asr_res = await asr_file(fpath, engine="gemini", client=client, message=message, **kwargs)
+ engine = "gemini" if platform == "youtube" else "" # use gemini to bypass censorship
+ asr_res = await asr_file(fpath, engine=engine, client=client, message=message, **kwargs)
if asr_res.get("error"):
await modify_progress(text=asr_res["error"], force_update=True, **kwargs)
return
@@ -89,8 +91,6 @@ async def get_subtitle(client: Client, message: Message, youtube_subtitle_provid
if not subtitles:
return
logger.success(subtitles)
- matched = await match_social_media_link(url)
- platform = matched["platform"]
vid = matched.get("vid", matched.get("bvid", url))
if platform in ["bilibili", "youtube"]:
vinfo = await fetch_youtube_video_info(vid) if platform == "youtube" else await get_bilibili_video_info(vid)