diff options
Diffstat (limited to '')
| -rw-r--r-- | cogs/downloader.py | 27 |
1 files changed, 17 insertions, 10 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 | ||
