Commit 663617e
Changed files (4)
src
subtitles
src/subtitles/subtitle.py
@@ -103,7 +103,9 @@ async def get_subtitle(
res |= {"subtitles": res["texts"], "num_chars": count_subtitles(res["texts"]), "reading_minutes": count_subtitles(res["texts"]) / READING_SPEED}
else:
await modify_progress(text=error + "\n正在通过下载音频后ASR识别字幕", force_update=True, **kwargs)
- downloaded = await ytdlp_download(url, platform, ytdlp_download_video=False)
+ kwargs |= {"ytdlp_download_video": False}
+ downloaded = await ytdlp_download(url, platform, **kwargs)
+
if not downloaded["audio_path"].is_file():
await modify_progress(text="❌下载音频失败", force_update=True, **kwargs)
return
src/ytdlp/download.py
@@ -24,6 +24,8 @@ async def ytdlp_download(
url: str,
platform: Literal["youtube", "bilibili", "ytdlp"] | None = None,
proxy: str | None = None,
+ *,
+ use_aria2: bool = False,
**kwargs,
) -> dict:
"""Download video from url.
@@ -45,7 +47,7 @@ async def ytdlp_download(
}
"""
placeholder = {"video_path": Path("/non-exist"), "audio_path": Path("/non-exist"), "thumb": None}
- ytdlp_opts = await get_ytdlp_opts(url=url, platform=platform, proxy=proxy, video=true(kwargs.get("ytdlp_download_video")))
+ ytdlp_opts = await get_ytdlp_opts(url=url, platform=platform, proxy=proxy, video=true(kwargs.get("ytdlp_download_video")), use_aria2=use_aria2)
if kwargs.get("show_progress"):
loop = asyncio.get_running_loop()
hook = create_hook(kwargs.get("progress"), loop, detail_progress=true(kwargs.get("detail_progress")))
src/ytdlp/main.py
@@ -38,6 +38,7 @@ async def preview_ytdlp(
bvid: str = "",
use_db: bool = True,
ytdlp_download_video: bool = True,
+ use_aria2: bool = False,
ytdlp_send_video: bool = True,
ytdlp_send_audio: bool = True,
bilibili_comments: bool = True,
@@ -69,6 +70,7 @@ async def preview_ytdlp(
bvid (str, optional): The Bilibili video id.
use_db (bool, optional): Whether to use database to cache the result. Defaults to True.
ytdlp_download_video (bool, optional): Download video. Defaults to True.
+ use_aria2 (bool, optional): Whether to use aria2 to download the video. Defaults to False.
ytdlp_send_video (bool, optional): Send video. Defaults to True.
ytdlp_send_audio (bool, optional): Send audio. Defaults to False.
bilibili_comments (bool, optional): Enable bilibili comments
@@ -105,7 +107,14 @@ async def preview_ytdlp(
await modify_progress(text=vinfo.get("error_msg") or "❌视频无法下载", force_update=True, **kwargs)
return []
- info = await ytdlp_download(url, proxy=proxy, platform=platform, ytdlp_download_video=ytdlp_download_video, **kwargs)
+ info = await ytdlp_download(
+ url,
+ proxy=proxy,
+ platform=platform,
+ ytdlp_download_video=ytdlp_download_video,
+ use_aria2=use_aria2,
+ **kwargs,
+ )
if not (info["video_path"].is_file() or info["audio_path"].is_file()):
return []
info |= vinfo # merge video info
src/ytdlp/utils.py
@@ -48,7 +48,7 @@ def get_ytdlp_proxy(platform: Literal["youtube", "bilibili", "ytdlp"] | None = N
return proxy
-async def get_ytdlp_opts(platform: Literal["youtube", "bilibili", "ytdlp"] | None = None, url: str = "", proxy: str | None = None, *, video: bool = True) -> dict:
+async def get_ytdlp_opts(platform: Literal["youtube", "bilibili", "ytdlp"] | None = None, url: str = "", proxy: str | None = None, *, video: bool = True, use_aria2: bool = False) -> dict:
"""Get ytdlp options."""
if not proxy:
proxy = get_ytdlp_proxy(platform=platform, url=url, proxy=proxy)
@@ -83,7 +83,8 @@ async def get_ytdlp_opts(platform: Literal["youtube", "bilibili", "ytdlp"] | Non
cookiefile = await ytdlp_bilibili_cookie()
logger.trace(f"Use cookie file: {cookiefile}")
ytdlp_opts["cookiefile"] = cookiefile
- ytdlp_opts["external_downloader"] = {"default": "aria2c"}
+ if use_aria2:
+ ytdlp_opts["external_downloader"] = {"default": "aria2c"}
return ytdlp_opts