1+ import os
2+ import sys
3+ import requests
4+ import pyperclip
5+ import zipfile
6+ import shutil
7+
8+
9+ #If program was opened by doubleclicking
10+ if (len (sys .argv )== 1 ):
11+ print ("Did you double click the file?" )
12+ temp = input ("Failed, Press ENTER to exit!" )
13+ exit ()
14+
15+ #Blacklisted exts by catbox
16+ blacklist = [".exe" ,".jar" ,".doc" ,".docx" ,".cpl" ,".scr" ]
17+ ext = os .path .splitext (sys .argv [1 ])[1 ]
18+
19+
20+ try :
21+ #if a folder is to be uploaded, zip it
22+ if os .path .isdir (sys .argv [1 ]):
23+ print ("Given path is a directory, proceeding to upload as zip" )
24+ shutil .make_archive (sys .argv [1 ],'zip' ,sys .argv [1 ])
25+ #Check if folder is > 200MB
26+ if os .path .getsize (sys .argv [1 ]+ ".zip" )> 209715200 :
27+ print ("Only files less than 200MB are allowed" )
28+ temp = input ("Failed, Press ENTER to exit!" )
29+ exit ()
30+ apidata = {
31+ 'reqtype' : (None , 'fileupload' ),
32+ 'fileToUpload' : (sys .argv [1 ]+ ".zip" , open (sys .argv [1 ]+ ".zip" , 'rb' )),
33+ }
34+ #If file with blacklisted ext is to be uploaded, zip it
35+ elif ext in blacklist :
36+ #Check if filesize>200MB
37+ if os .path .getsize (sys .argv [1 ])> 209715200 :
38+ print ("Only files less than 200MB are allowed" )
39+ temp = input ("Failed, Press ENTER to exit!" )
40+ exit ()
41+ print ("Given filetype not allowed by Catbox, so proceeding to zip and upload" )
42+ with zipfile .ZipFile (os .path .basename (sys .argv [1 ])[:- 4 ]+ ".zip" , 'w' ) as zip :
43+ zip .write (os .path .basename (sys .argv [1 ]))
44+ apidata = {
45+ 'reqtype' : (None , 'fileupload' ),
46+ 'fileToUpload' : (sys .argv [1 ][:- 4 ]+ ".zip" , open (sys .argv [1 ][:- 4 ]+ ".zip" , 'rb' )),
47+ }
48+ else :
49+ #Check if filesize>200MB
50+ if os .path .getsize (sys .argv [1 ])> 209715200 :
51+ print ("Only files less than 200MB are allowed" )
52+ temp = input ("Failed, Press ENTER to exit!" )
53+ exit ()
54+ apidata = {
55+ 'reqtype' : (None , 'fileupload' ),
56+ 'fileToUpload' : (sys .argv [1 ], open (sys .argv [1 ], 'rb' )),
57+ }
58+
59+ print ("Uploading..." )
60+ result = requests .post ('https://catbox.moe/user/api.php' , files = apidata ).content .decode ("utf-8" )
61+ print (result )
62+ pyperclip .copy (result )
63+ spam = pyperclip .paste ()
64+ temp = input ("Copied to Clipboard, Press ENTER to exit!" )
65+
66+ except Exception as e :
67+ print (e )
68+ temp = input ("Failed, Press ENTER to exit!" )
0 commit comments