diff options
Diffstat (limited to 'cogs')
| -rw-r--r-- | cogs/conversion.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/cogs/conversion.py b/cogs/conversion.py index 2bfd3e9..6566ece 100644 --- a/cogs/conversion.py +++ b/cogs/conversion.py | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | import discord | 1 | import discord |
| 2 | import requests | ||
| 2 | from discord.ext import commands | 3 | from discord.ext import commands |
| 3 | import logging | 4 | import logging |
| 4 | import os | 5 | import os |
| @@ -64,7 +65,56 @@ class Conversion(commands.Cog): | |||
| 64 | try: | 65 | try: |
| 65 | subprocess.run(ffmpeg_command, check=True, shell=True) | 66 | subprocess.run(ffmpeg_command, check=True, shell=True) |
| 66 | # Upload the compressed file | 67 | # Upload the compressed file |
| 67 | await ctx.respond(file=discord.File(output_path)) | 68 | if os.path.getsize(output_path) > 1024*1024*10: |
| 69 | try: | ||
| 70 | |||
| 71 | # Upload to Copyparty | ||
| 72 | with open(output_path, 'rb') as f: | ||
| 73 | files = { | ||
| 74 | 'f': (output_path, f, 'application/octet-stream') | ||
| 75 | } | ||
| 76 | headers = { | ||
| 77 | 'Cookie': f'cppwd={os.getenv("COPYPARTY_PASSWORD")}' | ||
| 78 | } | ||
| 79 | params = { | ||
| 80 | 'j': '1', # Return JSON response | ||
| 81 | 'ck': 'b2' # Use blake2b checksum | ||
| 82 | } | ||
| 83 | |||
| 84 | # Ensure the URL ends with a single slash | ||
| 85 | base_url = "https://catbox.2137697.xyz/sperma/" | ||
| 86 | |||
| 87 | response = requests.post( | ||
| 88 | base_url, | ||
| 89 | files=files, | ||
| 90 | headers=headers, | ||
| 91 | params=params | ||
| 92 | ) | ||
| 93 | |||
| 94 | if response.status_code == 200 or response.status_code == 201: | ||
| 95 | try: | ||
| 96 | result = response.json() | ||
| 97 | if 'fileurl' in result: | ||
| 98 | dl_url = result['fileurl'] | ||
| 99 | await ctx.followup.send( | ||
| 100 | f"wysyłon\n" | ||
| 101 | f"{dl_url}\n" | ||
| 102 | ) | ||
| 103 | else: | ||
| 104 | await ctx.followup.send( | ||
| 105 | f"Odpowiedź serwera nie zawiera wymaganych danych: {result}") | ||
| 106 | except ValueError: | ||
| 107 | await ctx.followup.send(f"Nieprawidłowa odpowiedź z serwera: {response.text}") | ||
| 108 | else: | ||
| 109 | error_msg = response.text if response.text else 'Unknown error' | ||
| 110 | await ctx.followup.send( | ||
| 111 | f"nie udało się wysłać pliku (HTTP {response.status_code}): {error_msg}") | ||
| 112 | |||
| 113 | except Exception as upload_error: | ||
| 114 | await ctx.followup.send(f"copyparty mnie nienawidzi :cccc\n {str(upload_error)}") | ||
| 115 | logger.error(f"copyparty upload error: {upload_error}", exc_info=True) | ||
| 116 | else: | ||
| 117 | await ctx.respond(file=discord.File(output_path)) | ||
| 68 | logger.info(f"Conversion completed for: {file_type}") | 118 | logger.info(f"Conversion completed for: {file_type}") |
| 69 | # Delete compressed file | 119 | # Delete compressed file |
| 70 | os.remove(input_path) | 120 | os.remove(input_path) |
