From 77883faaaa8343ca4df49627816be1ef779a039f Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 18 Jan 2026 13:30:04 +0100 Subject: jarvis --- cogs/downloader.py | 82 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 16 deletions(-) (limited to 'cogs/downloader.py') diff --git a/cogs/downloader.py b/cogs/downloader.py index 7925f2d..42acc1d 100644 --- a/cogs/downloader.py +++ b/cogs/downloader.py @@ -5,6 +5,7 @@ import requests import discord import re import yt_dlp +import json from discord.ext import commands from dotenv import load_dotenv @@ -49,6 +50,23 @@ class Downloader(commands.Cog): ): """Download and convert media from a URL to the specified format""" await ctx.defer() + # Call the function and get the response + response = await self.download_standalone(url=url, catbox=catbox, fformat=fformat, filename_user=filename_user) + if isinstance(response, dict): + if response["status"] == "success": + if response["type"] == "url": + await ctx.respond(f"pobioron i wysyłon: {response['content']}") + elif response["type"] == "file": + file_data = response["content"] + await ctx.respond(file=discord.File(file_data)) + else: + logger.error(f"Error: {response['content']}") + if 'details' in response: + logger.error(f"Details: {response['details']}") + + + @staticmethod + async def download_standalone(url: str, catbox: bool = False, fformat: str = "mp4", filename_user: str = None): try: logger.info(f"Downloading {url} as {fformat}") @@ -93,6 +111,7 @@ class Downloader(commands.Cog): filename = os.path.basename(actual_file) else: filename = filename_user + '.' + extension + actual_file = os.path.join(temp_dir, filename) if not os.path.exists(actual_file): raise Exception(f"Downloaded file not found: {actual_file}") @@ -128,32 +147,63 @@ class Downloader(commands.Cog): result = response.json() if 'fileurl' in result: dl_url = result['fileurl'] - await ctx.followup.send( - f"wysyłon\n" - f"{dl_url}\n" - ) + return { + "status": "success", + "type": "url", + "content": dl_url, + "format": fformat, + "filename": filename + } else: - await ctx.followup.send( - f"Odpowiedź serwera nie zawiera wymaganych danych: {result}") + return { + "status": "error", + "type": "error", + "content": "Invalid response from file server", + "details": str(result) + } except ValueError: - await ctx.followup.send(f"Nieprawidłowa odpowiedź z serwera: {response.text}") + return { + "status": "error", + "type": "error", + "content": "Failed to parse server response", + "details": response.text[:200] # First 200 chars of response + } else: error_msg = response.text if response.text else 'Unknown error' - await ctx.followup.send( - f"nie udało się wysłać pliku (HTTP {response.status_code}): {error_msg}") + return { + "status": "error", + "type": "error", + "content": f"Server returned {response.status_code}", + "details": error_msg + } except Exception as upload_error: - await ctx.followup.send(f"copyparty mnie nienawidzi :cccc\n {str(upload_error)}") - logger.error(f"copyparty upload error: {upload_error}", exc_info=True) + return { + "status": "error", + "type": "error", + "content": "Upload failed", + "details": str(upload_error) + } else: - await ctx.followup.send("wysyłon na discord\n", file=discord.File(filename)) - - logger.info(f"File processed: {actual_file}") + # If we have a file to return directly + return { + "status": "success", + "type": "file", + "content": actual_file, + "filename": filename + } except Exception as e: - await ctx.followup.send(f":(\n{str(e)}") - logger.error(f"Error in download command: {e}", exc_info=True) + error_msg = f"Error in download command: {e}" + logger.error(error_msg, exc_info=True) + return { + "status": "error", + "type": "error", + "content": "Download failed", + "details": str(e) + } + def setup(bot): -- cgit v1.2.3