add basic config

This commit is contained in:
oskvr37
2024-07-21 20:41:37 +02:00
parent 3a8424c4d8
commit 13b71a6f85
2 changed files with 42 additions and 5 deletions
+11 -5
View File
@@ -1,17 +1,23 @@
import argparse
from .api import TidalApi
from .auth import getDeviceAuth, getToken
from .config import Config
def main():
parser = argparse.ArgumentParser(description="TIDDL, the Tidal Downloader")
print("✅ TIDDL installed!")
auth = getDeviceAuth()
print(f"Go to https://{auth['verificationUriComplete']} and add device!")
input("Hit enter when you are ready")
token = getToken(auth["deviceCode"])
print(token)
config = Config()
if not config.config["token"]:
auth = getDeviceAuth()
print(f"Go to https://{auth['verificationUriComplete']} and add device!")
input("Hit enter when you are ready")
token = getToken(auth["deviceCode"])
print(token)
config.config.update({"token": token["access_token"]})
config.save()
if __name__ == "__main__":
+31
View File
@@ -0,0 +1,31 @@
import json
from typing import TypedDict
class Settings(TypedDict):
download_path: str
class ConfigData(TypedDict):
token: str
settings: Settings
FILENAME = ".tiddl.json"
DEFAULT_CONFIG: ConfigData = {"token": "", "settings": {"download_path": "tiddl"}}
class Config:
def __init__(self) -> None:
self.config: ConfigData = DEFAULT_CONFIG
# load config from file or create new
try:
with open(FILENAME, "r") as f:
self.config = json.load(f)
except FileNotFoundError:
self.save()
def save(self):
with open(FILENAME, "w") as f:
json.dump(self.config, f)