introduced: requirements.txt, colored output (with ANSI escape codes), baked in failsafe when config file does not exist, slight improvements to ythdd.py
This commit is contained in:
@@ -1,17 +1,39 @@
|
||||
#!/usr/bin/python3
|
||||
import time, toml
|
||||
import time, toml, os
|
||||
|
||||
global starttime, apiRequests, apiFailedRequests, outsideApiHits, config, version, apiVersion
|
||||
global starttime, apiRequests, apiFailedRequests, outsideApiHits, config, version, apiVersion, colors
|
||||
|
||||
#def init():
|
||||
# starttime = int(time.time())
|
||||
class colors:
|
||||
HEADER = '\033[95m'
|
||||
OKBLUE = '\033[94m'
|
||||
OKCYAN = '\033[96m'
|
||||
OKGREEN = '\033[92m'
|
||||
WARNING = '\033[93m'
|
||||
FAIL = '\033[91m'
|
||||
ENDC = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
ENDL = '\n'
|
||||
|
||||
#def notImplemented(data):
|
||||
# return 501, f"not recognised/implemented: {data[0]}", []
|
||||
def notImplemented(name):
|
||||
return 501, f"not recognised/implemented: {name}", []
|
||||
|
||||
config = toml.load("config.toml")
|
||||
configfile = "config.toml" # TODO: implement a way to specify alternative config file path
|
||||
version = "0.0.1"
|
||||
apiVersion = "1"
|
||||
|
||||
# TODO: turn this into function, to make setting configfile with argparser (and effectively using a custom config file) possible
|
||||
if not os.path.exists(configfile):
|
||||
# use dummy default config, TODO: update this in the near future
|
||||
config = {'general': {'db_file_path': 'ythdd_db.sqlite', 'video_storage_directory_path': 'videos/', 'is_proxied': False}, 'api': {'api_key': 'CHANGEME', 'api_key_admin': str(int(time.time()*1337 % 899_999 + 100_000))}, 'extractor': {'user-agent': '', 'cookies_path': ''}, 'admin': {'admins': ['admin']}, 'yt_dlp': {}, 'postprocessing': {'presets': [{'name': 'recommended: [N][<=720p] best V+A', 'format': 'bv[height<=720]+ba', 'reencode': ''}, {'name': '[N][1080p] best V+A', 'format': 'bv[height=1080]+ba', 'reencode': ''}, {'name': '[R][1080p] webm', 'format': 'bv[height=1080]+ba', 'reencode': 'webm'}, {'name': '[N][720p] best V+A', 'format': 'bv[height=720]+ba', 'reencode': ''}, {'name': '[R][720p] webm', 'format': 'bv[height=720]+ba', 'reencode': 'webm'}, {'name': '[N][480p] best V+A', 'format': 'bv[height=480]+ba', 'reencode': ''}, {'name': '[480p] VP9 webm/reencode', 'format': 'bv*[height=480][ext=webm]+ba/bv[height=480]+ba', 'reencode': 'webm'}, {'name': '[N][1080p] best video only', 'format': 'bv[height=1080]', 'reencode': ''}, {'name': '[N][opus] best audio only', 'format': 'ba', 'reencode': 'opus'}]}}
|
||||
print(f"{colors.WARNING}WARNING{colors.ENDC}: Using default, baked in config data. {colors.ENDL}"
|
||||
f"Consider copying and editing the provided example file ({colors.OKCYAN}config.default.toml{colors.ENDC}).")
|
||||
print(f"{colors.WARNING}WARNING{colors.ENDC}: Default config populated with one-time, insecure pseudorandom admin API key: {colors.OKCYAN}{config['api']['api_key_admin']}{colors.ENDC}."
|
||||
f" {colors.ENDL}You need to provide a config file for persistence!{colors.ENDL}")
|
||||
#with open(configfile, "w") as file:
|
||||
# file.write(toml.dumps(config))
|
||||
else:
|
||||
config = toml.load(configfile)
|
||||
|
||||
def getUptime():
|
||||
return int(time.time()) - starttime
|
||||
return int(time.time()) - starttime
|
||||
|
||||
Reference in New Issue
Block a user