Fix #23, hash Qobuz password, formatting

This commit is contained in:
nathom 2021-04-01 16:45:31 -07:00
parent ff24f87926
commit c673f8ba95
2 changed files with 22 additions and 14 deletions

View file

@ -1,9 +1,11 @@
import logging import logging
import os import os
from getpass import getpass from getpass import getpass
from hashlib import md5
import click import click
from .clients import TidalClient
from .config import Config from .config import Config
from .constants import CACHE_DIR, CONFIG_DIR, CONFIG_PATH, QOBUZ_FEATURED_KEYS from .constants import CACHE_DIR, CONFIG_DIR, CONFIG_PATH, QOBUZ_FEATURED_KEYS
from .core import MusicDL from .core import MusicDL
@ -195,34 +197,40 @@ def discover(ctx, **kwargs):
@cli.command() @cli.command()
@click.option("-o", "--open", is_flag=True, help="Open the config file") @click.option("-o", "--open", is_flag=True, help="Open the config file")
@click.option("-q", "--qobuz", is_flag=True, help="Set Qobuz credentials") @click.option("-q", "--qobuz", is_flag=True, help="Set Qobuz credentials")
@click.option("-t", "--tidal", is_flag=True, help="Re-login into Tidal")
@click.option("--reset", is_flag=True, help="RESET the config file") @click.option("--reset", is_flag=True, help="RESET the config file")
@click.pass_context @click.pass_context
def config(ctx, **kwargs): def config(ctx, **kwargs):
"""Manage the streamrip configuration.""" """Manage the streamrip configuration file."""
if kwargs["reset"]: if kwargs["reset"]:
config.reset() config.reset()
if kwargs["open"]: if kwargs["open"]:
click.secho(f"Opening {CONFIG_PATH}", fg='green')
click.launch(CONFIG_PATH) click.launch(CONFIG_PATH)
if kwargs["qobuz"]: if kwargs["qobuz"]:
config.file["qobuz"]["email"] = input("Qobuz email: ") config.file["qobuz"]["email"] = input(click.style("Qobuz email: ", fg="blue"))
config.file["qobuz"]["password"] = getpass()
click.secho("Qobuz password (will not show on screen):", fg="blue")
config.file["qobuz"]["password"] = md5(
getpass(prompt="").encode("utf-8")
).hexdigest()
config.save() config.save()
click.secho("Qobuz credentials hashed and saved to config.", fg="green")
if kwargs["tidal"]:
client = TidalClient()
client.login()
config.file["tidal"].update(client.get_tokens())
config.save()
click.secho("Credentials saved to config.", fg="green")
def none_chosen(): def none_chosen():
click.secho("No items chosen, exiting.", fg="bright_red") click.secho("No items chosen, exiting.", fg="bright_red")
def parse_urls(arg: str):
if os.path.isfile(arg):
return arg, "txt"
if "http" in arg:
return arg, "urls"
raise ValueError(f"Invalid argument {arg}")
def main(): def main():
cli(obj={}) cli(obj={})

View file

@ -126,8 +126,8 @@ class MusicDL(list):
"parent_folder": self.config.session["downloads"]["folder"], "parent_folder": self.config.session["downloads"]["folder"],
"keep_cover": self.config.session["keep_cover"], "keep_cover": self.config.session["keep_cover"],
"large_cover": self.config.session["metadata"]["large_cover"], "large_cover": self.config.session["metadata"]["large_cover"],
"folder_format": self.config.session['path_format']['folder'], "folder_format": self.config.session["path_format"]["folder"],
"track_format": self.config.session['path_format']['track'] "track_format": self.config.session["path_format"]["track"]
# TODO: fully implement this # TODO: fully implement this
# "embed_cover": self.config.session["metadata"]["embed_cover"], # "embed_cover": self.config.session["metadata"]["embed_cover"],
} }