mirror of
https://github.com/oskvr37/tiddl.git
synced 2026-06-13 04:05:08 +03:00
✨ add basic config
This commit is contained in:
+11
-5
@@ -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__":
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user