Commit 80b59db
Changed files (4)
src
messages
ytdlp
src/messages/main.py
@@ -232,7 +232,7 @@ async def preview_social_media(
return await send2tg(client, message, texts=help_msg, **kwargs)
# with reply, treat the reply_msg as the trigger to preview social media link
message = message.reply_to_message
- info = parse_msg(message, silent=True) # parse again
+ info = parse_msg(message, silent=True, use_cache=False) # parse again
# add send_from_user.
if prepend_sender_user:
@@ -241,7 +241,7 @@ async def preview_social_media(
warn_msg = None
try:
- matched = await match_social_media_link(this_texts) # match "platform" and "url" (and other info)
+ matched = await match_social_media_link(info["text"]) # match "platform" and "url" (and other info)
if matched["platform"]:
logger.success(f"Matched: {matched}")
kwargs |= matched
src/ytdlp/download.py
@@ -73,6 +73,12 @@ async def ytdlp_download(
new_path = info["audio_path"].with_suffix(".m4a")
info["audio_path"].rename(new_path)
info["audio_path"] = new_path
+
+ # delete video_only file (no audio channel), this file is no longer needed
+ format_id = info.get("format_id", "") # 299+140
+ for fmt_id in [x.strip() for x in format_id.split("+") if x.strip()]: # ['299', '140']
+ video_ext = info["video_path"].suffix # .mp4
+ Path(DOWNLOAD_DIR).joinpath(f"{info['id']}.f{fmt_id}{video_ext}").unlink(missing_ok=True)
# summary
await modify_progress(text=msg.strip(), force_update=True, **kwargs)
return info
@@ -80,10 +86,10 @@ async def ytdlp_download(
def download_video_info(url: str, ytdlp_opts: dict, json_path: str | Path) -> dict:
try:
- with YoutubeDL(ytdlp_opts) as ydl: # type: ignore
- info: dict = ydl.extract_info(url, download=False) # type: ignore
+ with YoutubeDL(ytdlp_opts) as ydl:
+ info: dict = ydl.extract_info(url, download=False)
with Path(json_path).open("w") as f:
- json.dump(ydl.sanitize_info(info), f, ensure_ascii=False, indent=2) # type: ignore
+ json.dump(ydl.sanitize_info(info), f, ensure_ascii=False, indent=2)
# add custom fields
info["extractor"] = info.get("extractor", "").lower()
info["author"] = glom(info, Coalesce("uploader", "series", "extractor"))
@@ -170,7 +176,7 @@ def retry(func, max_retries=5):
@retry
def download_video(json_path: str, ytdlp_opts: dict, result: dict) -> dict:
- with YoutubeDL(ytdlp_opts) as ydl: # type: ignore
+ with YoutubeDL(ytdlp_opts) as ydl:
error_code = ydl.download_with_info_file(json_path) # 0: success, 1: error
if error_code != 0 and not result.get("ytdlp_error"):
url = unquote_plus(Path(json_path).stem)
src/ytdlp/main.py
@@ -324,7 +324,7 @@ async def send_media(
reply_msg_id = kwargs.get("reply_msg_id", 0)
reply_parameters = get_reply_to(message.id, reply_msg_id)
- # split large videos into multiple parts (less than 2GB)
+ # split large videos into multiple parts (>= 2GB)
if true(ytdlp_send_video) and video_path.is_file():
video_path = await convert_to_h264(video_path, allow_re_encoding=True, max_file_size=YTDLP_RE_ENCODING_MAX_FILE_BYTES, skip_h264=True)
if video_path.stat().st_size > MAX_FILE_BYTES:
pyproject.toml
@@ -97,6 +97,7 @@ ignore = [
"FIX002",
"PLC0415",
"S608",
+ "ASYNC240",
]
select = ["ALL"]