Allow burning in subtitles
All checks were successful
Build and Publish Jimmy.2 / build_and_publish (push) Successful in 6s
All checks were successful
Build and Publish Jimmy.2 / build_and_publish (push) Successful in 6s
This commit is contained in:
parent
b70016326a
commit
10f8b00181
1 changed files with 26 additions and 2 deletions
|
@ -258,6 +258,14 @@ class YTDLCog(commands.Cog):
|
||||||
typing.Optional[str],
|
typing.Optional[str],
|
||||||
discord.Option(description="A start and end position to trim. e.g. 00:00:00-00:10:00.", required=False),
|
discord.Option(description="A start and end position to trim. e.g. 00:00:00-00:10:00.", required=False),
|
||||||
],
|
],
|
||||||
|
subtitles: typing.Annotated[
|
||||||
|
typing.Optional[str],
|
||||||
|
discord.Option(
|
||||||
|
str,
|
||||||
|
description="The language code of the subtitles to download. e.g. 'en', 'auto'",
|
||||||
|
required=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
):
|
):
|
||||||
"""Runs yt-dlp and outputs into discord."""
|
"""Runs yt-dlp and outputs into discord."""
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
|
@ -312,17 +320,33 @@ class YTDLCog(commands.Cog):
|
||||||
else:
|
else:
|
||||||
chosen_format = user_format
|
chosen_format = user_format
|
||||||
|
|
||||||
|
options.setdefault("postprocessors", [])
|
||||||
if audio_only:
|
if audio_only:
|
||||||
# Overwrite format here to be best audio under 25 megabytes.
|
# Overwrite format here to be best audio under 25 megabytes.
|
||||||
chosen_format = "ba[filesize<20M]"
|
chosen_format = "ba[filesize<20M]"
|
||||||
# Also force sorting by the best audio bitrate first.
|
# Also force sorting by the best audio bitrate first.
|
||||||
options["format_sort"] = ["abr", "br"]
|
options["format_sort"] = ["abr", "br"]
|
||||||
options["postprocessors"] = [
|
# noinspection PyTypeChecker
|
||||||
|
options["postprocessors"].append(
|
||||||
{"key": "FFmpegExtractAudio", "preferredquality": "96", "preferredcodec": "best"}
|
{"key": "FFmpegExtractAudio", "preferredquality": "96", "preferredcodec": "best"}
|
||||||
]
|
)
|
||||||
options["format"] = chosen_format
|
options["format"] = chosen_format
|
||||||
options["paths"] = paths
|
options["paths"] = paths
|
||||||
|
|
||||||
|
if subtitles:
|
||||||
|
subtitles, burn = subtitles.split("+", 1) if "+" in subtitles else (subtitles, False)
|
||||||
|
if subtitles.lower() == "auto":
|
||||||
|
options["writeautosubtitles"] = True
|
||||||
|
else:
|
||||||
|
options["writesubtitles"] = True
|
||||||
|
options["subtitleslangs"] = [subtitles]
|
||||||
|
|
||||||
|
if burn:
|
||||||
|
# noinspection PyTypeChecker
|
||||||
|
options["postprocessors"].append(
|
||||||
|
{"key": "FFmpegEmbedSubtitle", "already_have_subtitle": True}
|
||||||
|
)
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL(options) as downloader:
|
with yt_dlp.YoutubeDL(options) as downloader:
|
||||||
await ctx.respond(embed=discord.Embed().set_footer(text="Downloading (step 1/10)"))
|
await ctx.respond(embed=discord.Embed().set_footer(text="Downloading (step 1/10)"))
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue