aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cogs/downloader.py27
-rw-r--r--requirements.txt3
2 files changed, 19 insertions, 11 deletions
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):
31 url = [m.group(0) for m in self.URL_PATTERN.finditer(message.content)] 31 url = [m.group(0) for m in self.URL_PATTERN.finditer(message.content)]
32 if url: 32 if url:
33 for url in url: 33 for url in url:
34 await self.download(ctx, url, "mp4") 34 await self.download(ctx=ctx, url=url, fformat="mp4")
35 else: 35 else:
36 await ctx.respond("Brak załączników w wiadomości", ephemeral=True) 36 await ctx.respond("Brak załączników w wiadomości", ephemeral=True)
37 37
@@ -42,10 +42,10 @@ class Downloader(commands.Cog):
42 async def download( 42 async def download(
43 self, 43 self,
44 ctx: discord.ApplicationContext, 44 ctx: discord.ApplicationContext,
45 url: discord.Option(str, "URL of the video to download", required=True), 45 url: str = discord.Option(str, description="Link media", required=True),
46 fformat: discord.Option(str, "Output format (mp4, mp3, wav, etc.)", 46 catbox: bool = discord.Option(bool, description="wysłać na serwer??", required=False, default=False),
47 required=False, 47 fformat: str = discord.Option(str, description="jaki format? (mp4, mp3, wav, etc.)", required=False, default="mp4"),
48 default="mp4") 48 filename_user: str = discord.Option(str, description="jaka nazwa pliku?, required=False")
49 ): 49 ):
50 """Download and convert media from a URL to the specified format""" 50 """Download and convert media from a URL to the specified format"""
51 await ctx.defer() 51 await ctx.defer()
@@ -60,7 +60,9 @@ class Downloader(commands.Cog):
60 'm4a'] else 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', 60 'm4a'] else 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',
61 'merge_output_format': 'mp4', 61 'merge_output_format': 'mp4',
62 'postprocessors': [], 62 'postprocessors': [],
63 'remote-components': 'ejs:github' 63 'remote-components': 'ejs:github',
64 'js-runtimes': 'deno:/usr/bin/deno',
65 'o': '"%(title)s.%(ext)s"'
64 } 66 }
65 67
66 # Add post-processing for audio formats 68 # Add post-processing for audio formats
@@ -85,13 +87,18 @@ class Downloader(commands.Cog):
85 raise Exception(f"No file was downloaded") 87 raise Exception(f"No file was downloaded")
86 88
87 actual_file = os.path.join(temp_dir, files[0]) 89 actual_file = os.path.join(temp_dir, files[0])
90 extension = actual_file.split('.')[-1]
91
92 if not filename_user:
93 filename = os.path.basename(actual_file)
94 else:
95 filename = filename_user + '.' + extension
96
88 if not os.path.exists(actual_file): 97 if not os.path.exists(actual_file):
89 raise Exception(f"Downloaded file not found: {actual_file}") 98 raise Exception(f"Downloaded file not found: {actual_file}")
90 99
91 if os.path.getsize(actual_file) > 1024*1024*10: 100 if os.path.getsize(actual_file) > 1024*1024*10 or catbox:
92 try: 101 try:
93 # Get file info
94 filename = f"output.{fformat}"
95 102
96 # Upload to Copyparty 103 # Upload to Copyparty
97 with open(actual_file, 'rb') as f: 104 with open(actual_file, 'rb') as f:
@@ -140,7 +147,7 @@ class Downloader(commands.Cog):
140 logger.error(f"copyparty upload error: {upload_error}", exc_info=True) 147 logger.error(f"copyparty upload error: {upload_error}", exc_info=True)
141 148
142 else: 149 else:
143 await ctx.followup.send("wysyłon na discord\n", file=discord.File(actual_file)) 150 await ctx.followup.send("wysyłon na discord\n", file=discord.File(filename))
144 151
145 logger.info(f"File processed: {actual_file}") 152 logger.info(f"File processed: {actual_file}")
146 153
diff --git a/requirements.txt b/requirements.txt
index 3dbf13f..b809a08 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,6 +3,7 @@ aiohttp==3.13.3
3aiosignal==1.4.0 3aiosignal==1.4.0
4anyio==4.12.1 4anyio==4.12.1
5attrs==25.4.0 5attrs==25.4.0
6audioop-lts==0.2.2
6beautifulsoup4==4.14.3 7beautifulsoup4==4.14.3
7brotli==1.2.0 8brotli==1.2.0
8certifi==2026.1.4 9certifi==2026.1.4
@@ -20,7 +21,7 @@ idna==3.11
20multidict==6.7.0 21multidict==6.7.0
21mutagen==1.47.0 22mutagen==1.47.0
22propcache==0.4.1 23propcache==0.4.1
23py-cord==2.7.0 24py-cord==2.6.1
24pycparser==2.23 25pycparser==2.23
25pycryptodomex==3.23.0 26pycryptodomex==3.23.0
26PyNaCl==1.6.2 27PyNaCl==1.6.2