86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
#!/usr/bin/env python3.11
|
|
|
|
# Catbox Uploader
|
|
|
|
import requests
|
|
import traceback
|
|
import random
|
|
import os
|
|
import json
|
|
|
|
CATBOX_API_PATH = "https://catbox.moe/user/api.php"
|
|
HEADERS = {
|
|
"accept": "*/*",
|
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53",
|
|
"Accept-Language": "en-US,en;q=0.9,it;q=0.8,es;q=0.7",
|
|
"referer": "https://www.google.com/",
|
|
"cookie": "DSID=AAO-7r4OSkS76zbHUkiOpnI0kk-X19BLDFF53G8gbnd21VZV2iehu-w_2v14cxvRvrkd_NjIdBWX7wUiQ66f-D8kOkTKD1BhLVlqrFAaqDP3LodRK2I0NfrObmhV9HsedGE7-mQeJpwJifSxdchqf524IMh9piBflGqP0Lg0_xjGmLKEQ0F4Na6THgC06VhtUG5infEdqMQ9otlJENe3PmOQTC_UeTH5DnENYwWC8KXs-M4fWmDADmG414V0_X0TfjrYu01nDH2Dcf3TIOFbRDb993g8nOCswLMi92LwjoqhYnFdf1jzgK0",
|
|
}
|
|
|
|
|
|
class Catbox:
|
|
|
|
def generateRandomFileName(self, fileExt=""):
|
|
|
|
if len(fileExt) < 1:
|
|
fileExt = "db"
|
|
|
|
return f"{random.getrandbits(32)}.{fileExt}"
|
|
|
|
def __init__(self):
|
|
self.PROXIES = None
|
|
|
|
try:
|
|
with open(
|
|
os.path.join(os.path.expanduser("~"), ".catprox"), "r"
|
|
) as proxfile:
|
|
self.PROXIES = json.loads("".join(str(x) for x in proxfile.readlines()))
|
|
except:
|
|
pass
|
|
|
|
def upload(self, filePath=""):
|
|
global CATBOX_API_PATH
|
|
global HEADERS
|
|
try:
|
|
if len(filePath) == 0:
|
|
return False
|
|
|
|
if not (os.path.exists(filePath)):
|
|
print(f"Could not find {filePath}")
|
|
|
|
fileExt = ""
|
|
|
|
if filePath.find(".") > 0:
|
|
fileExt = "".join(filePath.split(".")[-1:])
|
|
|
|
with open(filePath, "rb") as fileContents:
|
|
postData = {"reqtype": "fileupload", "userhash": ""}
|
|
|
|
r = requests.post(
|
|
CATBOX_API_PATH,
|
|
headers=HEADERS,
|
|
proxies=self.PROXIES,
|
|
data=postData,
|
|
timeout=(2, 8),
|
|
files={
|
|
"fileToUpload": (
|
|
self.generateRandomFileName(fileExt),
|
|
fileContents,
|
|
)
|
|
},
|
|
)
|
|
|
|
if r.status_code in [200, 301, 302]:
|
|
return r.text.strip()
|
|
else:
|
|
print(f"FAILED - Status Code: {r.status_code}")
|
|
return False
|
|
except:
|
|
print(traceback.format_exc())
|
|
return False
|
|
finally:
|
|
try:
|
|
fileContents.close()
|
|
except:
|
|
pass
|