mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-14 07:04:51 -04:00
Only use click for secho, echo, style
This commit is contained in:
parent
9970ac548f
commit
286ff502b5
8 changed files with 129 additions and 129 deletions
138
rip/cli.py
138
rip/cli.py
|
@ -9,10 +9,10 @@ logging.basicConfig(level="WARNING")
|
|||
logger = logging.getLogger("streamrip")
|
||||
|
||||
|
||||
class SkipArg(click.Group):
|
||||
class SkipArg(Group):
|
||||
def parse_args(self, ctx, args):
|
||||
if len(args) == 0:
|
||||
click.echo(self.get_help(ctx))
|
||||
echo(self.get_help(ctx))
|
||||
exit()
|
||||
|
||||
if args[0] in self.commands:
|
||||
|
@ -25,27 +25,27 @@ class SkipArg(click.Group):
|
|||
super(SkipArg, self).parse_args(ctx, args)
|
||||
|
||||
|
||||
# @click.option(
|
||||
# @option(
|
||||
# "-u",
|
||||
# "--urls",
|
||||
# metavar="URLS",
|
||||
# help="Url from Qobuz, Tidal, SoundCloud, or Deezer",
|
||||
# multiple=True,
|
||||
# )
|
||||
@click.group(cls=SkipArg, invoke_without_command=True)
|
||||
@click.option("-c", "--convert", metavar="CODEC", help="alac, mp3, flac, or ogg")
|
||||
@click.option(
|
||||
@group(cls=SkipArg, invoke_without_command=True)
|
||||
@option("-c", "--convert", metavar="CODEC", help="alac, mp3, flac, or ogg")
|
||||
@option(
|
||||
"-q",
|
||||
"--quality",
|
||||
metavar="INT",
|
||||
help="0: < 320kbps, 1: 320 kbps, 2: 16 bit/44.1 kHz, 3: 24 bit/<=96 kHz, 4: 24 bit/<=192 kHz",
|
||||
)
|
||||
@click.option("-t", "--text", metavar="PATH", help="Download urls from a text file.")
|
||||
@click.option("-nd", "--no-db", is_flag=True, help="Ignore the database.")
|
||||
@click.option("--debug", is_flag=True, help="Show debugging logs.")
|
||||
@click.argument("URLS", nargs=1)
|
||||
@click.version_option(prog_name="rip", version=__version__)
|
||||
@click.pass_context
|
||||
@option("-t", "--text", metavar="PATH", help="Download urls from a text file.")
|
||||
@option("-nd", "--no-db", is_flag=True, help="Ignore the database.")
|
||||
@option("--debug", is_flag=True, help="Show debugging logs.")
|
||||
@argument("URLS", nargs=1)
|
||||
@version_option(prog_name="rip", version=__version__)
|
||||
@pass_context
|
||||
def cli(ctx, **kwargs):
|
||||
"""Streamrip: The all-in-one Qobuz, Tidal, SoundCloud, and Deezer music
|
||||
downloader.
|
||||
|
@ -84,7 +84,7 @@ def cli(ctx, **kwargs):
|
|||
|
||||
if ctx.invoked_subcommand is None and not ctx.params["urls"]:
|
||||
print(dir(cli))
|
||||
click.echo(cli.get_help(ctx))
|
||||
echo(cli.get_help(ctx))
|
||||
|
||||
if ctx.invoked_subcommand not in {
|
||||
None,
|
||||
|
@ -106,13 +106,13 @@ def cli(ctx, **kwargs):
|
|||
r = requests.get("https://pypi.org/pypi/streamrip/json").json()
|
||||
newest = r["info"]["version"]
|
||||
if __version__ != newest:
|
||||
click.secho(
|
||||
secho(
|
||||
"A new version of streamrip is available! "
|
||||
"Run `pip3 install streamrip --upgrade` to update.",
|
||||
fg="yellow",
|
||||
)
|
||||
else:
|
||||
click.secho("streamrip is up-to-date!", fg="green")
|
||||
secho("streamrip is up-to-date!", fg="green")
|
||||
|
||||
if kwargs["no_db"]:
|
||||
config.session["database"]["enabled"] = False
|
||||
|
@ -124,7 +124,7 @@ def cli(ctx, **kwargs):
|
|||
if kwargs["quality"] is not None:
|
||||
quality = int(kwargs["quality"])
|
||||
if quality not in range(5):
|
||||
click.secho("Invalid quality", fg="red")
|
||||
secho("Invalid quality", fg="red")
|
||||
return
|
||||
|
||||
config.session["qobuz"]["quality"] = quality
|
||||
|
@ -142,21 +142,21 @@ def cli(ctx, **kwargs):
|
|||
logger.debug(f"Handling {kwargs['text']}")
|
||||
core.handle_txt(kwargs["text"])
|
||||
else:
|
||||
click.secho(f"Text file {kwargs['text']} does not exist.")
|
||||
secho(f"Text file {kwargs['text']} does not exist.")
|
||||
|
||||
if ctx.invoked_subcommand is None:
|
||||
core.download()
|
||||
|
||||
|
||||
@cli.command(name="filter")
|
||||
@click.option("--repeats", is_flag=True)
|
||||
@click.option("--non-albums", is_flag=True)
|
||||
@click.option("--extras", is_flag=True)
|
||||
@click.option("--features", is_flag=True)
|
||||
@click.option("--non-studio-albums", is_flag=True)
|
||||
@click.option("--non-remasters", is_flag=True)
|
||||
@click.argument("URLS", nargs=-1)
|
||||
@click.pass_context
|
||||
@option("--repeats", is_flag=True)
|
||||
@option("--non-albums", is_flag=True)
|
||||
@option("--extras", is_flag=True)
|
||||
@option("--features", is_flag=True)
|
||||
@option("--non-studio-albums", is_flag=True)
|
||||
@option("--non-remasters", is_flag=True)
|
||||
@argument("URLS", nargs=-1)
|
||||
@pass_context
|
||||
def filter_discography(ctx, **kwargs):
|
||||
"""Filter an artists discography (qobuz only).
|
||||
|
||||
|
@ -176,22 +176,22 @@ def filter_discography(ctx, **kwargs):
|
|||
|
||||
|
||||
@cli.command()
|
||||
@click.option(
|
||||
@option(
|
||||
"-t",
|
||||
"--type",
|
||||
default="album",
|
||||
help="album, playlist, track, or artist",
|
||||
show_default=True,
|
||||
)
|
||||
@click.option(
|
||||
@option(
|
||||
"-s",
|
||||
"--source",
|
||||
default="qobuz",
|
||||
help="qobuz, tidal, soundcloud, deezer, or deezloader",
|
||||
show_default=True,
|
||||
)
|
||||
@click.argument("QUERY", nargs=-1)
|
||||
@click.pass_context
|
||||
@argument("QUERY", nargs=-1)
|
||||
@pass_context
|
||||
def search(ctx, **kwargs):
|
||||
"""Search and download media in interactive mode.
|
||||
|
||||
|
@ -223,18 +223,18 @@ def search(ctx, **kwargs):
|
|||
if core.interactive_search(query, kwargs["source"], kwargs["type"]):
|
||||
core.download()
|
||||
else:
|
||||
click.secho("No items chosen, exiting.", fg="bright_red")
|
||||
secho("No items chosen, exiting.", fg="bright_red")
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option("-l", "--list", default="ideal-discography", show_default=True)
|
||||
@click.option(
|
||||
@option("-l", "--list", default="ideal-discography", show_default=True)
|
||||
@option(
|
||||
"-s", "--scrape", is_flag=True, help="Download all of the items in a list."
|
||||
)
|
||||
@click.option(
|
||||
@option(
|
||||
"-n", "--num-items", default=50, help="Number of items to parse.", show_default=True
|
||||
)
|
||||
@click.pass_context
|
||||
@pass_context
|
||||
def discover(ctx, **kwargs):
|
||||
"""Search for albums in Qobuz's featured lists.
|
||||
|
||||
|
@ -278,13 +278,13 @@ def discover(ctx, **kwargs):
|
|||
|
||||
|
||||
@cli.command()
|
||||
@click.option(
|
||||
@option(
|
||||
"-s",
|
||||
"--source",
|
||||
help="qobuz, tidal, deezer, deezloader, or soundcloud",
|
||||
)
|
||||
@click.argument("URL")
|
||||
@click.pass_context
|
||||
@argument("URL")
|
||||
@pass_context
|
||||
def lastfm(ctx, source, url):
|
||||
"""Search for tracks from a last.fm playlist on a given source.
|
||||
|
||||
|
@ -312,25 +312,25 @@ def lastfm(ctx, source, url):
|
|||
|
||||
|
||||
@cli.command()
|
||||
@click.option("-o", "--open", is_flag=True, help="Open the config file")
|
||||
@click.option("-d", "--directory", is_flag=True, help="Open the config directory")
|
||||
@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("-dz", "--deezer", is_flag=True, help="Set the Deezer ARL")
|
||||
@click.option("--reset", is_flag=True, help="RESET the config file")
|
||||
@click.option(
|
||||
@option("-o", "--open", is_flag=True, help="Open the config file")
|
||||
@option("-d", "--directory", is_flag=True, help="Open the config directory")
|
||||
@option("-q", "--qobuz", is_flag=True, help="Set Qobuz credentials")
|
||||
@option("-t", "--tidal", is_flag=True, help="Re-login into Tidal")
|
||||
@option("-dz", "--deezer", is_flag=True, help="Set the Deezer ARL")
|
||||
@option("--reset", is_flag=True, help="RESET the config file")
|
||||
@option(
|
||||
"--update",
|
||||
is_flag=True,
|
||||
help="Reset the config file, keeping the credentials",
|
||||
)
|
||||
@click.option("-p", "--path", is_flag=True, help="Show the config file's path")
|
||||
@click.option(
|
||||
@option("-p", "--path", is_flag=True, help="Show the config file's path")
|
||||
@option(
|
||||
"-ov",
|
||||
"--open-vim",
|
||||
is_flag=True,
|
||||
help="Open the config file in the nvim or vim text editor.",
|
||||
)
|
||||
@click.pass_context
|
||||
@pass_context
|
||||
def config(ctx, **kwargs):
|
||||
"""Manage the streamrip configuration file."""
|
||||
import os
|
||||
|
@ -350,11 +350,11 @@ def config(ctx, **kwargs):
|
|||
config.update()
|
||||
|
||||
if kwargs["path"]:
|
||||
click.echo(CONFIG_PATH)
|
||||
echo(CONFIG_PATH)
|
||||
|
||||
if kwargs["open"]:
|
||||
click.secho(f"Opening {CONFIG_PATH}", fg="green")
|
||||
click.launch(CONFIG_PATH)
|
||||
secho(f"Opening {CONFIG_PATH}", fg="green")
|
||||
launch(CONFIG_PATH)
|
||||
|
||||
if kwargs["open_vim"]:
|
||||
if shutil.which("nvim") is not None:
|
||||
|
@ -364,58 +364,58 @@ def config(ctx, **kwargs):
|
|||
|
||||
if kwargs["directory"]:
|
||||
config_dir = os.path.dirname(CONFIG_PATH)
|
||||
click.secho(f"Opening {config_dir}", fg="green")
|
||||
click.launch(config_dir)
|
||||
secho(f"Opening {config_dir}", fg="green")
|
||||
launch(config_dir)
|
||||
|
||||
if kwargs["qobuz"]:
|
||||
config.file["qobuz"]["email"] = input(click.style("Qobuz email: ", fg="blue"))
|
||||
config.file["qobuz"]["email"] = input(style("Qobuz email: ", fg="blue"))
|
||||
|
||||
click.secho("Qobuz password (will not show on screen):", fg="blue")
|
||||
secho("Qobuz password (will not show on screen):", fg="blue")
|
||||
config.file["qobuz"]["password"] = md5(
|
||||
getpass(prompt="").encode("utf-8")
|
||||
).hexdigest()
|
||||
|
||||
config.save()
|
||||
click.secho("Qobuz credentials hashed and saved to config.", fg="green")
|
||||
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")
|
||||
secho("Credentials saved to config.", fg="green")
|
||||
|
||||
if kwargs["deezer"]:
|
||||
click.secho(
|
||||
secho(
|
||||
"If you're not sure how to find the ARL cookie, see the instructions at ",
|
||||
italic=True,
|
||||
nl=False,
|
||||
dim=True,
|
||||
)
|
||||
click.secho(
|
||||
secho(
|
||||
"https://github.com/nathom/streamrip/wiki/Finding-your-Deezer-ARL-Cookie",
|
||||
underline=True,
|
||||
italic=True,
|
||||
fg="blue",
|
||||
)
|
||||
config.file["deezer"]["arl"] = input(click.style("ARL: ", fg="green"))
|
||||
config.file["deezer"]["arl"] = input(style("ARL: ", fg="green"))
|
||||
config.save()
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option(
|
||||
@option(
|
||||
"-sr", "--sampling-rate", help="Downsample the tracks to this rate, in Hz."
|
||||
)
|
||||
@click.option("-bd", "--bit-depth", help="Downsample the tracks to this bit depth.")
|
||||
@click.option(
|
||||
@option("-bd", "--bit-depth", help="Downsample the tracks to this bit depth.")
|
||||
@option(
|
||||
"-k",
|
||||
"--keep-source",
|
||||
is_flag=True,
|
||||
help="Do not delete the old file after conversion.",
|
||||
)
|
||||
@click.argument("CODEC")
|
||||
@click.argument("PATH")
|
||||
@click.pass_context
|
||||
@argument("CODEC")
|
||||
@argument("PATH")
|
||||
@pass_context
|
||||
def convert(ctx, **kwargs):
|
||||
"""Batch convert audio files.
|
||||
|
||||
|
@ -498,14 +498,14 @@ def convert(ctx, **kwargs):
|
|||
elif os.path.isfile(kwargs["path"]):
|
||||
codec_map[codec](filename=kwargs["path"], **converter_args).convert()
|
||||
else:
|
||||
click.secho(f"File {kwargs['path']} does not exist.", fg="red")
|
||||
secho(f"File {kwargs['path']} does not exist.", fg="red")
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option(
|
||||
@option(
|
||||
"-n", "--num-items", help="The number of items to atttempt downloads for."
|
||||
)
|
||||
@click.pass_context
|
||||
@pass_context
|
||||
def repair(ctx, **kwargs):
|
||||
"""Retry failed downloads.
|
||||
|
||||
|
@ -520,7 +520,7 @@ def repair(ctx, **kwargs):
|
|||
|
||||
def none_chosen():
|
||||
"""Print message if nothing was chosen."""
|
||||
click.secho("No items chosen, exiting.", fg="bright_red")
|
||||
secho("No items chosen, exiting.", fg="bright_red")
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue