mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-27 21:44:27 -04:00
Only import echo, secho, and style from click
This commit is contained in:
parent
328879584d
commit
54f4ab99af
6 changed files with 71 additions and 71 deletions
36
rip/cli.py
36
rip/cli.py
|
@ -68,7 +68,7 @@ def cli(ctx, **kwargs):
|
|||
logger.debug("Starting debug log")
|
||||
|
||||
if ctx.invoked_subcommand is None and not ctx.params["urls"]:
|
||||
click.echo(cli.get_help(ctx))
|
||||
echo(cli.get_help(ctx))
|
||||
|
||||
if ctx.invoked_subcommand not in {
|
||||
None,
|
||||
|
@ -90,13 +90,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
|
||||
|
@ -108,7 +108,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
|
||||
|
@ -126,7 +126,7 @@ 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()
|
||||
|
@ -206,7 +206,7 @@ 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()
|
||||
|
@ -333,10 +333,10 @@ 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")
|
||||
secho(f"Opening {CONFIG_PATH}", fg="green")
|
||||
click.launch(CONFIG_PATH)
|
||||
|
||||
if kwargs["open_vim"]:
|
||||
|
@ -347,41 +347,41 @@ def config(ctx, **kwargs):
|
|||
|
||||
if kwargs["directory"]:
|
||||
config_dir = os.path.dirname(CONFIG_PATH)
|
||||
click.secho(f"Opening {config_dir}", fg="green")
|
||||
secho(f"Opening {config_dir}", fg="green")
|
||||
click.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()
|
||||
|
||||
|
||||
|
@ -481,7 +481,7 @@ 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()
|
||||
|
@ -503,7 +503,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():
|
||||
|
|
|
@ -56,7 +56,7 @@ class Config:
|
|||
if os.path.isfile(self._path):
|
||||
self.load()
|
||||
if self.file["misc"]["version"] != self.defaults["misc"]["version"]:
|
||||
click.secho(
|
||||
secho(
|
||||
"Updating config file to new version. Some settings may be lost.",
|
||||
fg="yellow",
|
||||
)
|
||||
|
|
52
rip/core.py
52
rip/core.py
|
@ -162,8 +162,8 @@ class RipCore(list):
|
|||
if not parsed and len(self) == 0:
|
||||
if "last.fm" in url:
|
||||
message = (
|
||||
f"For last.fm urls, use the {click.style('lastfm', fg='yellow')} "
|
||||
f"command. See {click.style('rip lastfm --help', fg='yellow')}."
|
||||
f"For last.fm urls, use the {style('lastfm', fg='yellow')} "
|
||||
f"command. See {style('rip lastfm --help', fg='yellow')}."
|
||||
)
|
||||
else:
|
||||
message = f"Cannot find urls in text: {url}"
|
||||
|
@ -175,7 +175,7 @@ class RipCore(list):
|
|||
logger.info(
|
||||
f"ID {item_id} already downloaded, use --no-db to override."
|
||||
)
|
||||
click.secho(
|
||||
secho(
|
||||
f"ID {item_id} already downloaded, use --no-db to override.",
|
||||
fg="magenta",
|
||||
)
|
||||
|
@ -248,7 +248,7 @@ class RipCore(list):
|
|||
max_items = float("inf")
|
||||
|
||||
if self.failed_db.is_dummy:
|
||||
click.secho(
|
||||
secho(
|
||||
"Failed downloads database must be enabled in the config file "
|
||||
"to repair!",
|
||||
fg="red",
|
||||
|
@ -304,7 +304,7 @@ class RipCore(list):
|
|||
item.load_meta(**arguments)
|
||||
except NonStreamable:
|
||||
self.failed_db.add((item.client.source, item.type, item.id))
|
||||
click.secho(f"{item!s} is not available, skipping.", fg="red")
|
||||
secho(f"{item!s} is not available, skipping.", fg="red")
|
||||
continue
|
||||
|
||||
try:
|
||||
|
@ -321,7 +321,7 @@ class RipCore(list):
|
|||
self.failed_db.add(failed_item_info)
|
||||
continue
|
||||
except ItemExists as e:
|
||||
click.secho(f'"{e!s}" already exists. Skipping.', fg="yellow")
|
||||
secho(f'"{e!s}" already exists. Skipping.', fg="yellow")
|
||||
continue
|
||||
|
||||
if hasattr(item, "id"):
|
||||
|
@ -366,13 +366,13 @@ class RipCore(list):
|
|||
creds = self.config.creds(client.source)
|
||||
if client.source == "deezer" and creds["arl"] == "":
|
||||
if self.config.session["deezer"]["deezloader_warnings"]:
|
||||
click.secho(
|
||||
secho(
|
||||
"Falling back to Deezloader (max 320kbps MP3). If you have a subscription, run ",
|
||||
nl=False,
|
||||
fg="yellow",
|
||||
)
|
||||
click.secho("rip config --deezer ", nl=False, bold=True)
|
||||
click.secho("to download FLAC files.\n\n", fg="yellow")
|
||||
secho("rip config --deezer ", nl=False, bold=True)
|
||||
secho("to download FLAC files.\n\n", fg="yellow")
|
||||
raise DeezloaderFallback
|
||||
|
||||
while True:
|
||||
|
@ -380,7 +380,7 @@ class RipCore(list):
|
|||
client.login(**creds)
|
||||
break
|
||||
except AuthenticationError:
|
||||
click.secho("Invalid credentials, try again.", fg="yellow")
|
||||
secho("Invalid credentials, try again.", fg="yellow")
|
||||
self.prompt_creds(client.source)
|
||||
creds = self.config.creds(client.source)
|
||||
except MissingCredentials:
|
||||
|
@ -419,7 +419,7 @@ class RipCore(list):
|
|||
|
||||
interpreter_urls = QOBUZ_INTERPRETER_URL_REGEX.findall(url)
|
||||
if interpreter_urls:
|
||||
click.secho(
|
||||
secho(
|
||||
"Extracting IDs from Qobuz interpreter urls. Use urls "
|
||||
"that include the artist ID for faster preprocessing.",
|
||||
fg="yellow",
|
||||
|
@ -432,7 +432,7 @@ class RipCore(list):
|
|||
|
||||
dynamic_urls = DEEZER_DYNAMIC_LINK_REGEX.findall(url)
|
||||
if dynamic_urls:
|
||||
click.secho(
|
||||
secho(
|
||||
"Extracting IDs from Deezer dynamic link. Use urls "
|
||||
"of the form https://www.deezer.com/{country}/{type}/{id} for "
|
||||
"faster processing.",
|
||||
|
@ -524,7 +524,7 @@ class RipCore(list):
|
|||
return True
|
||||
|
||||
for purl in lastfm_urls:
|
||||
click.secho(f"Fetching playlist at {purl}", fg="blue")
|
||||
secho(f"Fetching playlist at {purl}", fg="blue")
|
||||
title, queries = self.get_lastfm_playlist(purl)
|
||||
|
||||
pl = Playlist(client=self.get_client(lastfm_source), name=title)
|
||||
|
@ -550,7 +550,7 @@ class RipCore(list):
|
|||
pl.loaded = True
|
||||
|
||||
if tracks_not_found > 0:
|
||||
click.secho(f"{tracks_not_found} tracks not found.", fg="yellow")
|
||||
secho(f"{tracks_not_found} tracks not found.", fg="yellow")
|
||||
self.append(pl)
|
||||
|
||||
def handle_txt(self, filepath: Union[str, os.PathLike]):
|
||||
|
@ -815,9 +815,9 @@ class RipCore(list):
|
|||
:type source: str
|
||||
"""
|
||||
if source == "qobuz":
|
||||
click.secho("Enter Qobuz email:", fg="green")
|
||||
secho("Enter Qobuz email:", fg="green")
|
||||
self.config.file[source]["email"] = input()
|
||||
click.secho(
|
||||
secho(
|
||||
"Enter Qobuz password (will not show on screen):",
|
||||
fg="green",
|
||||
)
|
||||
|
@ -826,27 +826,27 @@ class RipCore(list):
|
|||
).hexdigest()
|
||||
|
||||
self.config.save()
|
||||
click.secho(
|
||||
secho(
|
||||
f'Credentials saved to config file at "{self.config._path}"',
|
||||
fg="green",
|
||||
)
|
||||
elif source == "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",
|
||||
)
|
||||
|
||||
self.config.file["deezer"]["arl"] = input(click.style("ARL: ", fg="green"))
|
||||
self.config.file["deezer"]["arl"] = input(style("ARL: ", fg="green"))
|
||||
self.config.save()
|
||||
click.secho(
|
||||
secho(
|
||||
f'Credentials saved to config file at "{self.config._path}"',
|
||||
fg="green",
|
||||
)
|
||||
|
@ -854,19 +854,19 @@ class RipCore(list):
|
|||
raise Exception
|
||||
|
||||
def _config_updating_message(self):
|
||||
click.secho(
|
||||
secho(
|
||||
"Updating config file... Some settings may be lost. Please run the "
|
||||
"command again.",
|
||||
fg="magenta",
|
||||
)
|
||||
|
||||
def _config_corrupted_message(self, err: Exception):
|
||||
click.secho(
|
||||
secho(
|
||||
"There was a problem with your config file. This happens "
|
||||
"sometimes after updates. Run ",
|
||||
nl=False,
|
||||
fg="red",
|
||||
)
|
||||
click.secho("rip config --reset ", fg="yellow", nl=False)
|
||||
click.secho("to reset it. You will need to log in again.", fg="red")
|
||||
click.secho(str(err), fg="red")
|
||||
secho("rip config --reset ", fg="yellow", nl=False)
|
||||
secho("to reset it. You will need to log in again.", fg="red")
|
||||
secho(str(err), fg="red")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue