diff options
| author | salmonik <raisersoft@proton.me> | 2026-01-18 16:20:33 +0100 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-01-18 16:20:33 +0100 |
| commit | cb625506be95cec4d4a402119eec0c79699142b9 (patch) | |
| tree | 7d5a60f7754d6e753a9c4f853c2fbccd9222973b /cogs/downloader.py | |
| parent | jarvis (diff) | |
| download | senator-sperma-cb625506be95cec4d4a402119eec0c79699142b9.tar.gz senator-sperma-cb625506be95cec4d4a402119eec0c79699142b9.zip | |
fix tmp dir being deleted before sending file
Diffstat (limited to '')
| -rw-r--r-- | cogs/downloader.py | 24 |
1 files changed, 15 insertions, 9 deletions
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): | |||
| 70 | try: | 70 | try: |
| 71 | logger.info(f"Downloading {url} as {fformat}") | 71 | logger.info(f"Downloading {url} as {fformat}") |
| 72 | 72 | ||
| 73 | with tempfile.TemporaryDirectory() as temp_dir: | 73 | with tempfile.TemporaryDirectory(delete=False) as temp_dir: |
| 74 | # Configure yt-dlp to use the original filename | 74 | # Configure yt-dlp to use the original filename |
| 75 | ydl_opts = { | 75 | ydl_opts = { |
| 76 | 'outtmpl': os.path.join(temp_dir, '%(title)s.%(ext)s'), | 76 | 'outtmpl': os.path.join(temp_dir, '%(title)s.%(ext)s'), |
| @@ -151,22 +151,24 @@ class Downloader(commands.Cog): | |||
| 151 | "status": "success", | 151 | "status": "success", |
| 152 | "type": "url", | 152 | "type": "url", |
| 153 | "content": dl_url, | 153 | "content": dl_url, |
| 154 | "format": fformat, | 154 | "filename": filename, |
| 155 | "filename": filename | 155 | "temp_dir": temp_dir |
| 156 | } | 156 | } |
| 157 | else: | 157 | else: |
| 158 | return { | 158 | return { |
| 159 | "status": "error", | 159 | "status": "error", |
| 160 | "type": "error", | 160 | "type": "error", |
| 161 | "content": "Invalid response from file server", | 161 | "content": "Invalid response from file server", |
| 162 | "details": str(result) | 162 | "details": str(result), |
| 163 | "temp_dir": temp_dir | ||
| 163 | } | 164 | } |
| 164 | except ValueError: | 165 | except ValueError: |
| 165 | return { | 166 | return { |
| 166 | "status": "error", | 167 | "status": "error", |
| 167 | "type": "error", | 168 | "type": "error", |
| 168 | "content": "Failed to parse server response", | 169 | "content": "Failed to parse server response", |
| 169 | "details": response.text[:200] # First 200 chars of response | 170 | "details": response.text[:200], # First 200 chars of response |
| 171 | "temp_dir": temp_dir | ||
| 170 | } | 172 | } |
| 171 | else: | 173 | else: |
| 172 | error_msg = response.text if response.text else 'Unknown error' | 174 | error_msg = response.text if response.text else 'Unknown error' |
| @@ -174,7 +176,8 @@ class Downloader(commands.Cog): | |||
| 174 | "status": "error", | 176 | "status": "error", |
| 175 | "type": "error", | 177 | "type": "error", |
| 176 | "content": f"Server returned {response.status_code}", | 178 | "content": f"Server returned {response.status_code}", |
| 177 | "details": error_msg | 179 | "details": error_msg, |
| 180 | "temp_dir": temp_dir | ||
| 178 | } | 181 | } |
| 179 | 182 | ||
| 180 | except Exception as upload_error: | 183 | except Exception as upload_error: |
| @@ -182,7 +185,8 @@ class Downloader(commands.Cog): | |||
| 182 | "status": "error", | 185 | "status": "error", |
| 183 | "type": "error", | 186 | "type": "error", |
| 184 | "content": "Upload failed", | 187 | "content": "Upload failed", |
| 185 | "details": str(upload_error) | 188 | "details": str(upload_error), |
| 189 | "temp_dir": temp_dir | ||
| 186 | } | 190 | } |
| 187 | 191 | ||
| 188 | else: | 192 | else: |
| @@ -191,7 +195,8 @@ class Downloader(commands.Cog): | |||
| 191 | "status": "success", | 195 | "status": "success", |
| 192 | "type": "file", | 196 | "type": "file", |
| 193 | "content": actual_file, | 197 | "content": actual_file, |
| 194 | "filename": filename | 198 | "filename": filename, |
| 199 | "temp_dir": temp_dir | ||
| 195 | } | 200 | } |
| 196 | 201 | ||
| 197 | except Exception as e: | 202 | except Exception as e: |
| @@ -201,7 +206,8 @@ class Downloader(commands.Cog): | |||
| 201 | "status": "error", | 206 | "status": "error", |
| 202 | "type": "error", | 207 | "type": "error", |
| 203 | "content": "Download failed", | 208 | "content": "Download failed", |
| 204 | "details": str(e) | 209 | "details": str(e), |
| 210 | "temp_dir": temp_dir | ||
| 205 | } | 211 | } |
| 206 | 212 | ||
| 207 | 213 | ||
