From f63dd6ee418ba271d4f0da92f58a8dabde372bbd Mon Sep 17 00:00:00 2001 From: nex Date: Wed, 17 May 2023 20:05:18 +0100 Subject: [PATCH] Add post-processing --- cogs/other.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/cogs/other.py b/cogs/other.py index 4acd83f..d27f874 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -972,22 +972,32 @@ class OtherCog(commands.Cog): ) } - with yt_dlp.YoutubeDL( + args = { + "windowsfilenames": True, + "restrictfilenames": True, + "noplaylist": True, + "nocheckcertificate": True, + "no_color": True, + "noprogress": True, + "logger": logger, + "format": _format or None, + "paths": paths, + "outtmpl": f"{ctx.user.id}-%(title).50s.%(ext)s", + "trim_file_name": 128, + "extract_audio": extract_audio, + } + if extract_audio: + args["postprocessors"] = [ { - "windowsfilenames": True, - "restrictfilenames": True, - "noplaylist": True, - "nocheckcertificate": True, - "no_color": True, - "noprogress": True, - "logger": logger, - "format": _format or f"(bv*+ba/bv/ba/b)[filesize<={MAX_SIZE_MB}M]", - "paths": paths, - "outtmpl": f"{ctx.user.id}-%(title).50s.%(ext)s", - "trim_file_name": 128, - "extract_audio": extract_audio, + "key": "FFmpegExtractAudio", + "preferredquality": "192", } - ) as downloader: + ] + args["format"] = args["format"] or f"(ba/b)[filesize<={MAX_SIZE_MB}M]" + + if args["format"] is None: + args["format"] = f"(bv*+ba/bv/ba/b)[filesize<={MAX_SIZE_MB}M]" + with yt_dlp.YoutubeDL(args) as downloader: try: await ctx.respond( embed=discord.Embed(title="Downloading...", colour=discord.Colour.blurple())