From 9c22b50d5fd2cf7e090ddefb0c7a2979f2567f51 Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 15 Jan 2026 14:36:57 +0100 Subject: more yt-dlp improvements --- cogs/downloader.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'cogs/downloader.py') diff --git a/cogs/downloader.py b/cogs/downloader.py index 30ddd2a..90ff803 100644 --- a/cogs/downloader.py +++ b/cogs/downloader.py @@ -31,7 +31,7 @@ class Downloader(commands.Cog): url = [m.group(0) for m in self.URL_PATTERN.finditer(message.content)] if url: for url in url: - await self.download(ctx, url, "mp4") + await self.download(ctx=ctx, url=url, fformat="mp4") else: await ctx.respond("Brak załączników w wiadomości", ephemeral=True) @@ -42,10 +42,10 @@ class Downloader(commands.Cog): async def download( self, ctx: discord.ApplicationContext, - url: discord.Option(str, "URL of the video to download", required=True), - fformat: discord.Option(str, "Output format (mp4, mp3, wav, etc.)", - required=False, - default="mp4") + url: str = discord.Option(str, description="Link media", required=True), + catbox: bool = discord.Option(bool, description="wysłać na serwer??", required=False, default=False), + fformat: str = discord.Option(str, description="jaki format? (mp4, mp3, wav, etc.)", required=False, default="mp4"), + filename_user: str = discord.Option(str, description="jaka nazwa pliku?, required=False") ): """Download and convert media from a URL to the specified format""" await ctx.defer() @@ -60,7 +60,9 @@ class Downloader(commands.Cog): 'm4a'] else 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', 'merge_output_format': 'mp4', 'postprocessors': [], - 'remote-components': 'ejs:github' + 'remote-components': 'ejs:github', + 'js-runtimes': 'deno:/usr/bin/deno', + 'o': '"%(title)s.%(ext)s"' } # Add post-processing for audio formats @@ -85,13 +87,18 @@ class Downloader(commands.Cog): raise Exception(f"No file was downloaded") actual_file = os.path.join(temp_dir, files[0]) + extension = actual_file.split('.')[-1] + + if not filename_user: + filename = os.path.basename(actual_file) + else: + filename = filename_user + '.' + extension + if not os.path.exists(actual_file): raise Exception(f"Downloaded file not found: {actual_file}") - if os.path.getsize(actual_file) > 1024*1024*10: + if os.path.getsize(actual_file) > 1024*1024*10 or catbox: try: - # Get file info - filename = f"output.{fformat}" # Upload to Copyparty with open(actual_file, 'rb') as f: @@ -140,7 +147,7 @@ class Downloader(commands.Cog): logger.error(f"copyparty upload error: {upload_error}", exc_info=True) else: - await ctx.followup.send("wysyłon na discord\n", file=discord.File(actual_file)) + await ctx.followup.send("wysyłon na discord\n", file=discord.File(filename)) logger.info(f"File processed: {actual_file}") -- cgit v1.2.3