Skip to content

Instantly share code, notes, and snippets.

@chiyochichi
Created April 9, 2023 14:56
Show Gist options
  • Save chiyochichi/b5a517cb14a35c1cbf473ce266fb393b to your computer and use it in GitHub Desktop.
Save chiyochichi/b5a517cb14a35c1cbf473ce266fb393b to your computer and use it in GitHub Desktop.
import os
import hashlib
import threading
import httpx
import queue
import sqlite3
q = queue.Queue()
r = httpx.Client(limits=httpx.Limits(max_keepalive_connections=None, max_connections=None))
dbl = threading.Lock()
con = sqlite3.connect("aof.sqlite3", check_same_thread = False)
cur = con.cursor()
def download(fid):
if len(fid) < 6: return False
for _ in range(1, 30):
try:
rsp = r.get('https://api.anonfiles.com/v2/file/'+fid+'/info').json()
if 'error' in rsp and rsp['error'].get('code') == 404: return False
rsp = rsp['data']['file']['metadata']
if rsp['size']['bytes'] > 70000000: return False
print(rsp['size']['readable'])
#name = rsp['name']
break
except Exception as e:
print(e)
dbl.acquire()
if cur.execute("SELECT aurl FROM anonfiles WHERE fid=?", (fid,)).fetchone():
print('exists')
dbl.release()
return False
dbl.release()
while True:
try:
rsp = r.get('https://anonfiles.com/'+fid).text
if 'POTENTIAL VIRUS!' in rsp: return False
#print(rsp)
name = rsp.split('<h1 class="text-center text-wordwrap">')[1].split('<')[0]
link = rsp.split('href="https://cdn')[1].split('"')[0]
print(name,link)
print('...downloading',name)
with open('tmp', 'wb+') as f:
with r.stream('GET', 'https://cdn'+link) as rsp:
for chunk in rsp.iter_bytes():
f.write(chunk)
break
except Exception as e:
print(e)
return fid+'_'+name
def upload(fid, fname):
with open('tmp', 'rb') as f:
sha1 = hashlib.sha1()
sha1.update(f.read())
fhash = sha1.hexdigest()
while True:
try:
print('...uploading',fname)
rsp = r.post('https://discord.com/api/v10/channels/chid/messages', timeout=None, files={'upload-file': (fname, f)},
data={"content": 'https://anonfiles.com/'+fid+' - '+fid+' - `'+fname.replace(fid+'_', '')+'` - '+fhash, "channel_id":"chid", "type":0},
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0",
"Authorization": "nopee"
})
print(rsp)
aurl = rsp.json()['attachments'][0]['url']
dbl.acquire()
cur.execute("INSERT INTO anonfiles VALUES(?,?,?,?)", (fid,fname,aurl,fhash))
con.commit()
dbl.release()
break
except Exception as e:
print(e)
def worker():
while True:
fid = q.get()
dl = download(fid)
print(dl)
if dl:
new = upload(fid, dl)
print('saved',fid)
else:
print('didn\'t save',fid)
q.task_done()
threading.Thread(target=worker, daemon=True).start()
while True:
fid = input()
if 'anonfiles.com' in fid:
fid = fid.split('anonfiles.com/')[1].split('/')[0]
q.put(fid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment