Commit c3d32bf
Changed files (1)
src
others
src/others/ffmpeg.py
@@ -21,8 +21,8 @@ from utils import readable_size, seconds_to_time
async def ffmpeg_cut(client: Client, message: Message, **kwargs):
"""Cut video or audio file."""
- docs = f"""✂️**视频/音频切片**
-该功能需要使用`{PREFIX.FFMPEG_CUT}`命令回复一条视频或音频消息
+ docs = f"""✂️**视频切片**
+该功能需要使用`{PREFIX.FFMPEG_CUT}`命令回复一条视频消息
**命令格式**:
`{PREFIX.FFMPEG_CUT} start_time [end_time]`
@@ -46,8 +46,8 @@ async def ffmpeg_cut(client: Client, message: Message, **kwargs):
media_message = message.reply_to_message if message.reply_to_message else message
info = parse_msg(media_message)
- if info["mtype"] not in ["video", "audio"]:
- await send2tg(client, message, texts="❌请回复一条视频或音频消息\n\n" + docs, **kwargs)
+ if info["mtype"] != "video":
+ await send2tg(client, message, texts="❌请回复一条视频消息\n\n" + docs, **kwargs)
return
times = remove_prefix(message.content, prefix=PREFIX.FFMPEG_CUT).split()
if len(times) not in [1, 2]:
@@ -56,23 +56,23 @@ async def ffmpeg_cut(client: Client, message: Message, **kwargs):
fpath = Path(DOWNLOAD_DIR).joinpath(f"{info['mid']}-{info['cid']}-{info['file_name']}").as_posix()
if not Path(fpath).is_file():
- kwargs["progress"] = kwargs.get("progress", await message.reply_text("⏬正在下载媒体文件...", quote=True))
+ kwargs["progress"] = kwargs.get("progress", await message.reply_text("⏬正在下载视频...", quote=True))
fpath: str = await client.download_media(media_message, file_name=fpath) # type: ignore
if not Path(fpath).is_file():
- await modify_progress(text="❌媒体文件下载失败", force_update=True, **kwargs)
+ await modify_progress(text="❌视频下载失败", force_update=True, **kwargs)
return
vinfo = await parse_media_info(fpath)
- ext = Path(fpath).suffix
+ ext = Path(fpath).suffix or ".mp4"
start_time = sanitize_time(times[0])
out_path = Path(DOWNLOAD_DIR).joinpath(f"ffmpeg-cut-{info['file_name']}").as_posix()
if len(times) == 1:
end_time = sanitize_time(vinfo["duration"])
- cmd = f"✅文件下载完成 ({readable_size(path=fpath)})\n✂️执行切片命令:\n`ffmpeg -ss {start_time} -i input{ext} -c:v libx264 -c:a aac output{ext}`"
- ffmpeg = FFmpeg().option("y").input(fpath, ss=start_time).output(out_path, acodec="aac", vcodec="libx264")
+ cmd = f"✅视频下载完成 ({readable_size(path=fpath)})\n✂️执行切片命令:\n`ffmpeg -ss {start_time} -i input{ext} -c:v libx264 -c:a aac output{ext}`"
+ ffmpeg = FFmpeg().option("y").input(fpath, ss=start_time).output(out_path, acodec="aac", vcodec="libx264", f="mp4")
else:
end_time = sanitize_time(times[1])
- cmd = f"✅文件下载完成 ({readable_size(path=fpath)})\n✂️执行切片命令:\n`ffmpeg -ss {start_time} -to {end_time} -i input{ext} -c:v libx264 -c:a aac output{ext}`"
- ffmpeg = FFmpeg().option("y").input(fpath, ss=start_time, to=end_time).output(out_path, acodec="aac", vcodec="libx264")
+ cmd = f"✅视频下载完成 ({readable_size(path=fpath)})\n✂️执行切片命令:\n`ffmpeg -ss {start_time} -to {end_time} -i input{ext} -c:v libx264 -c:a aac output{ext}`"
+ ffmpeg = FFmpeg().option("y").input(fpath, ss=start_time, to=end_time).output(out_path, acodec="aac", vcodec="libx264", f="mp4")
await modify_progress(text=cmd, force_update=True, **kwargs)
@@ -101,7 +101,7 @@ async def ffmpeg_cut(client: Client, message: Message, **kwargs):
}
"""
minfo = await parse_media_info(out_path)
- media = [{"video": out_path, "thumb": generate_cover(fpath)}] if info["mtype"] == "video" else [{"audio": out_path, "thumb": generate_cover(fpath)}]
+ media = [{"video": out_path, "thumb": generate_cover(fpath)}]
start = start_time.removeprefix("00:")
end = end_time.removeprefix("00:")
duration = f"{minfo['raw_duration']:.3f}".rstrip("0").rstrip(".")