From a769cf0ac5c20a2f4b4cb72bab3ed438480d9a98 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 16 May 2026 18:07:07 +0200 Subject: fix naming not resolving things like %20 Signed-off-by: salmonik --- cogs/compression.py | 1 + cogs/conversion.py | 1 + cogs/music/play_commands.py | 24 ++++++++---------------- cogs/uploader.py | 1 + 4 files changed, 11 insertions(+), 16 deletions(-) (limited to 'cogs') diff --git a/cogs/compression.py b/cogs/compression.py index 7171abb..71348dc 100644 --- a/cogs/compression.py +++ b/cogs/compression.py @@ -62,6 +62,7 @@ class Compression(commands.Cog): return None filename = url.split('/')[-1].split('?')[0] + filename = urllib.parse.unquote(filename) file_path = os.path.join(self.temp_dir, filename) async with aiofiles.open(file_path, 'wb') as f: diff --git a/cogs/conversion.py b/cogs/conversion.py index 455bfde..f9e4c84 100644 --- a/cogs/conversion.py +++ b/cogs/conversion.py @@ -63,6 +63,7 @@ class Conversion(commands.Cog): return None filename = url.split('/')[-1].split('?')[0] + filename = urllib.parse.unquote(filename) file_path = os.path.join(self.temp_dir, filename) async with aiofiles.open(file_path, 'wb') as f: diff --git a/cogs/music/play_commands.py b/cogs/music/play_commands.py index bdb021d..80a30ef 100644 --- a/cogs/music/play_commands.py +++ b/cogs/music/play_commands.py @@ -10,6 +10,7 @@ import asyncio from os import PathLike from typing import Awaitable, Callable, List, Tuple import re +import requests from yt_dlp import YoutubeDL import discord @@ -228,8 +229,6 @@ class PlayCommands(commands.Cog): async def _upload_to_copyparty_async(self, file_path: str) -> None: """Upload file to copyparty asynchronously (fire and forget).""" - import aiohttp - try: logger.info(f"Starting async upload: {file_path}") baseurl = get_uploadurl() @@ -243,25 +242,18 @@ class PlayCommands(commands.Cog): with open(file_path, "rb") as f: content = f.read() - files = aiohttp.FormData() - files.add_field( - "f", - content, - filename=os.path.basename(file_path), - content_type="application/octet-stream", - ) + files = {"f": (os.path.basename(file_path), content, "application/octet-stream")} headers = {"Cookie": f"cppwd={password}"} params = {"j": "1", "ck": "b2"} logger.info(f"Posting to {baseurl}") - async with aiohttp.ClientSession() as session: - async with session.post(baseurl, data=files, headers=headers, params=params) as response: - text = await response.text() - logger.info(f"Upload response: {response.status} - {text[:200] if text else 'empty'}") + response = requests.post(baseurl, files=files, headers=headers, params=params) + text = response.text + logger.info(f"Upload response: {response.status_code} - {text[:200] if text else 'empty'}") - if response.status in [200, 201]: - result = await response.json() - logger.info(f"Uploaded to copyparty: {result.get('fileurl')}") + if response.status_code in [200, 201]: + result = response.json() + logger.info(f"Uploaded to copyparty: {result.get('fileurl')}") except Exception as e: logger.error(f"Async upload failed: {e}", exc_info=True) diff --git a/cogs/uploader.py b/cogs/uploader.py index df6908e..a5d0e05 100644 --- a/cogs/uploader.py +++ b/cogs/uploader.py @@ -48,6 +48,7 @@ class Uploader(commands.Cog): return None filename = url.split('/')[-1].split('?')[0] + filename = urllib.parse.unquote(filename) file_path = os.path.join(self.temp_dir, filename) async with aiofiles.open(file_path, 'wb') as f: -- cgit v1.2.3