Commit 8c71164
Changed files (2)
src
preview
subtitles
src/preview/ytdlp.py
@@ -69,6 +69,7 @@ async def preview_ytdlp(
proxy: str | None = None,
append_transcription: bool = True,
ytdlp_transcription_engine: str = "gemini",
+ transcription_only: bool = False,
to_telegraph: bool = True,
**kwargs,
):
@@ -87,6 +88,7 @@ async def preview_ytdlp(
proxy (str, optional): Proxy to use. Defaults to None.
append_transcription (bool, optional): Also append transcription.
ytdlp_transcription_engine (str, optional): Method to get transcription.
+ transcription_only (str, optional): If True, skip send video and audio file.
to_telegraph (bool, optional): Whether to publish the subtitle or transcription to telegraph.
delete_files (bool, optional): Whether to delete video & audio after uploading.
"""
@@ -106,6 +108,7 @@ async def preview_ytdlp(
ytdlp_send_video = False
if not ytdlp_send_video:
ytdlp_send_audio = True
+
if proxy is None:
proxy = get_ytdlp_proxy(url)
ydl_opts = {
@@ -114,7 +117,7 @@ async def preview_ytdlp(
"simulate": False,
"skip_download": False,
"keepvideo": True,
- "format": "m4a/bestaudio/best" if ytdlp_audio_only else video_selector,
+ "format": "m4a/bestaudio/best" if ytdlp_audio_only or transcription_only else video_selector,
"writethumbnail": True,
"trim_file_name": 60, # filesystem limit for filename is 255 bytes. UFT-8 char is 1-4 bytes.
"proxy": proxy,
@@ -205,7 +208,7 @@ async def preview_ytdlp(
if not Path(thumb).is_file():
thumb = None
# split large videos into multiple parts (less than 2GB)
- if video_path.is_file():
+ if video_path.is_file() and not transcription_only:
video_path = convert_to_h264(video_path, re_encoding=True, max_file_size=YTDLP_RE_ENCODING_MAX_FILE_BYTES, skip_h264=True)
if video_path.stat().st_size > MAX_FILE_BYTES:
await modify_progress(text="🎬视频大小超过Telegram限制(2000MB), 正在切分...", **kwargs)
@@ -225,7 +228,7 @@ async def preview_ytdlp(
**video,
)
)
- if audio_path.is_file():
+ if audio_path.is_file() and not transcription_only:
audio_target_chat = target_chat if ytdlp_send_audio else TID.CHANNEL_YTDLP_BACKUP # backup to channel if not send audio, so we can save it to db
await modify_progress(text=f"🎧音频上传中: {readable_size(path=audio_path)}", force_update=True, **kwargs)
caption = (await smart_split(texts, CAPTION_LENGTH))[0]
src/subtitles/subtitle.py
@@ -71,7 +71,7 @@ async def get_subtitle(client: Client, message: Message, youtube_subtitle_provid
"show_progress": False,
"url": url,
"append_transcription": True,
- "ytdlp_audio_only": True,
+ "transcription_only": True,
"youtube_comments_provider": False,
"bilibili_comments_provider": False,
"proxy": None,