2024-12-26 18:03:21 -05:00
#!/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 = {
2025-04-21 21:03:52 -04:00
" 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 " ,
}
2024-12-26 18:03:21 -05:00
2025-04-21 21:03:52 -04:00
class Catbox :
2024-12-26 18:03:21 -05:00
2025-04-21 21:03:52 -04:00
def generateRandomFileName ( self , fileExt = " " ) :
2024-12-26 18:03:21 -05:00
if len ( fileExt ) < 1 :
2025-04-21 21:03:52 -04:00
fileExt = " db "
2024-12-26 18:03:21 -05:00
return f " { random . getrandbits ( 32 ) } . { fileExt } "
2025-04-21 21:03:52 -04:00
2024-12-26 18:03:21 -05:00
def __init__ ( self ) :
self . PROXIES = None
try :
2025-04-21 21:03:52 -04:00
with open (
os . path . join ( os . path . expanduser ( " ~ " ) , " .catprox " ) , " r "
) as proxfile :
2024-12-26 18:03:21 -05:00
self . PROXIES = json . loads ( " " . join ( str ( x ) for x in proxfile . readlines ( ) ) )
except :
pass
2025-04-21 21:03:52 -04:00
def upload ( self , filePath = " " ) :
2024-12-26 18:03:21 -05:00
global CATBOX_API_PATH
global HEADERS
try :
if len ( filePath ) == 0 :
return False
2025-04-21 21:03:52 -04:00
if not ( os . path . exists ( filePath ) ) :
2024-12-26 18:03:21 -05:00
print ( f " Could not find { filePath } " )
2025-04-21 21:03:52 -04:00
fileExt = " "
2024-12-26 18:03:21 -05:00
if filePath . find ( " . " ) > 0 :
fileExt = " " . join ( filePath . split ( " . " ) [ - 1 : ] )
2025-04-21 21:03:52 -04:00
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 ,
)
} ,
)
2024-12-26 18:03:21 -05:00
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