From cb625506be95cec4d4a402119eec0c79699142b9 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 18 Jan 2026 16:20:33 +0100 Subject: fix tmp dir being deleted before sending file --- cogs/downloader.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'cogs/downloader.py') diff --git a/cogs/downloader.py b/cogs/downloader.py index 42acc1d..a2e2299 100644 --- a/cogs/downloader.py +++ b/cogs/downloader.py @@ -70,7 +70,7 @@ class Downloader(commands.Cog): try: logger.info(f"Downloading {url} as {fformat}") - with tempfile.TemporaryDirectory() as temp_dir: + with tempfile.TemporaryDirectory(delete=False) as temp_dir: # Configure yt-dlp to use the original filename ydl_opts = { 'outtmpl': os.path.join(temp_dir, '%(title)s.%(ext)s'), @@ -151,22 +151,24 @@ class Downloader(commands.Cog): "status": "success", "type": "url", "content": dl_url, - "format": fformat, - "filename": filename + "filename": filename, + "temp_dir": temp_dir } else: return { "status": "error", "type": "error", "content": "Invalid response from file server", - "details": str(result) + "details": str(result), + "temp_dir": temp_dir } except ValueError: return { "status": "error", "type": "error", "content": "Failed to parse server response", - "details": response.text[:200] # First 200 chars of response + "details": response.text[:200], # First 200 chars of response + "temp_dir": temp_dir } else: error_msg = response.text if response.text else 'Unknown error' @@ -174,7 +176,8 @@ class Downloader(commands.Cog): "status": "error", "type": "error", "content": f"Server returned {response.status_code}", - "details": error_msg + "details": error_msg, + "temp_dir": temp_dir } except Exception as upload_error: @@ -182,7 +185,8 @@ class Downloader(commands.Cog): "status": "error", "type": "error", "content": "Upload failed", - "details": str(upload_error) + "details": str(upload_error), + "temp_dir": temp_dir } else: @@ -191,7 +195,8 @@ class Downloader(commands.Cog): "status": "success", "type": "file", "content": actual_file, - "filename": filename + "filename": filename, + "temp_dir": temp_dir } except Exception as e: @@ -201,7 +206,8 @@ class Downloader(commands.Cog): "status": "error", "type": "error", "content": "Download failed", - "details": str(e) + "details": str(e), + "temp_dir": temp_dir } -- cgit v1.2.3