funapi / routes /helpers.py
imperialwool
upd: rewrite audio downloading
a39dd78
raw history blame
No virus
1.01 kB
import os
import json
import random
import string
from time import sleep
# Deleting audio
def deleteAudio(path: str, waitInSeconds: int = 0):
if waitInSeconds:
sleep(waitInSeconds)
config = configFile()
os.system("rm {}/{}".format(config['static-path'], path))
# Config file reading
def configFile():
with open("/app/routes/config.json", "r") as file:
config = json.loads(file.read())
return config
# Hook for yt-dlp
def thisIsHook(d):
try:
if d['total_bytes'] > 52428800:
print("\nFILE IS BIG, ABORT!!!\n")
raise Exception(f"Too long file (recieved {d['total_bytes']/1048576}MB, max is 50MB)")
except: pass
# Get variable from request
def getFromRequest(request, thing: str):
return request.json.get(thing) if request.is_json else request.form.get(thing)
def randString(len: int = 16):
return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(len))