mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-13 06:34:45 -04:00
Begin move to cleo
This commit is contained in:
parent
54f4ab99af
commit
9970ac548f
13 changed files with 528 additions and 150 deletions
76
rip/core.py
76
rip/core.py
|
@ -10,7 +10,7 @@ from hashlib import md5
|
|||
from string import Formatter
|
||||
from typing import Dict, Generator, List, Optional, Tuple, Type, Union
|
||||
|
||||
import click
|
||||
from click import style, secho
|
||||
import requests
|
||||
from tqdm import tqdm
|
||||
|
||||
|
@ -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 {style('lastfm', fg='yellow')} "
|
||||
f"command. See {style('rip lastfm --help', fg='yellow')}."
|
||||
f"For last.fm urls, use the {click.style('lastfm', fg='yellow')} "
|
||||
f"command. See {click.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."
|
||||
)
|
||||
secho(
|
||||
click.secho(
|
||||
f"ID {item_id} already downloaded, use --no-db to override.",
|
||||
fg="magenta",
|
||||
)
|
||||
|
@ -248,12 +248,12 @@ class RipCore(list):
|
|||
max_items = float("inf")
|
||||
|
||||
if self.failed_db.is_dummy:
|
||||
secho(
|
||||
click.secho(
|
||||
"Failed downloads database must be enabled in the config file "
|
||||
"to repair!",
|
||||
fg="red",
|
||||
)
|
||||
raise click.Abort
|
||||
exit()
|
||||
|
||||
for counter, (source, media_type, item_id) in enumerate(self.failed_db):
|
||||
if counter >= max_items:
|
||||
|
@ -304,7 +304,7 @@ class RipCore(list):
|
|||
item.load_meta(**arguments)
|
||||
except NonStreamable:
|
||||
self.failed_db.add((item.client.source, item.type, item.id))
|
||||
secho(f"{item!s} is not available, skipping.", fg="red")
|
||||
click.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:
|
||||
secho(f'"{e!s}" already exists. Skipping.', fg="yellow")
|
||||
click.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"]:
|
||||
secho(
|
||||
click.secho(
|
||||
"Falling back to Deezloader (max 320kbps MP3). If you have a subscription, run ",
|
||||
nl=False,
|
||||
fg="yellow",
|
||||
)
|
||||
secho("rip config --deezer ", nl=False, bold=True)
|
||||
secho("to download FLAC files.\n\n", fg="yellow")
|
||||
click.secho("rip config --deezer ", nl=False, bold=True)
|
||||
click.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:
|
||||
secho("Invalid credentials, try again.", fg="yellow")
|
||||
click.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:
|
||||
secho(
|
||||
click.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:
|
||||
secho(
|
||||
click.secho(
|
||||
"Extracting IDs from Deezer dynamic link. Use urls "
|
||||
"of the form https://www.deezer.com/{country}/{type}/{id} for "
|
||||
"faster processing.",
|
||||
|
@ -486,7 +486,7 @@ class RipCore(list):
|
|||
exit()
|
||||
except Exception as err:
|
||||
self._config_corrupted_message(err)
|
||||
raise click.Abort
|
||||
exit()
|
||||
|
||||
def search_query(title, artist, playlist) -> bool:
|
||||
"""Search for a query and add the first result to playlist.
|
||||
|
@ -523,8 +523,10 @@ class RipCore(list):
|
|||
playlist.append(track)
|
||||
return True
|
||||
|
||||
from streamrip.utils import TQDM_BAR_FORMAT
|
||||
|
||||
for purl in lastfm_urls:
|
||||
secho(f"Fetching playlist at {purl}", fg="blue")
|
||||
click.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)
|
||||
|
@ -541,8 +543,11 @@ class RipCore(list):
|
|||
# only for the progress bar
|
||||
for search_attempt in tqdm(
|
||||
concurrent.futures.as_completed(futures),
|
||||
unit="Tracks",
|
||||
dynamic_ncols=True,
|
||||
total=len(futures),
|
||||
desc="Searching",
|
||||
desc="Searching...",
|
||||
bar_format=TQDM_BAR_FORMAT,
|
||||
):
|
||||
if not search_attempt.result():
|
||||
tracks_not_found += 1
|
||||
|
@ -550,7 +555,8 @@ class RipCore(list):
|
|||
pl.loaded = True
|
||||
|
||||
if tracks_not_found > 0:
|
||||
secho(f"{tracks_not_found} tracks not found.", fg="yellow")
|
||||
click.secho(f"{tracks_not_found} tracks not found.", fg="yellow")
|
||||
|
||||
self.append(pl)
|
||||
|
||||
def handle_txt(self, filepath: Union[str, os.PathLike]):
|
||||
|
@ -602,7 +608,7 @@ class RipCore(list):
|
|||
media_type if media_type != "featured" else "album"
|
||||
].from_api(item, client)
|
||||
|
||||
if i > limit:
|
||||
if i >= limit - 1:
|
||||
return
|
||||
else:
|
||||
logger.debug("Not generator")
|
||||
|
@ -616,7 +622,7 @@ class RipCore(list):
|
|||
for i, item in enumerate(items):
|
||||
logger.debug(item["title"])
|
||||
yield MEDIA_CLASS[media_type].from_api(item, client) # type: ignore
|
||||
if i > limit:
|
||||
if i >= limit - 1:
|
||||
return
|
||||
|
||||
def preview_media(self, media) -> str:
|
||||
|
@ -795,11 +801,7 @@ class RipCore(list):
|
|||
for page in range(1, last_page + 1)
|
||||
]
|
||||
|
||||
for future in tqdm(
|
||||
concurrent.futures.as_completed(futures),
|
||||
total=len(futures),
|
||||
desc="Scraping playlist",
|
||||
):
|
||||
for future in concurrent.futures.as_completed(futures):
|
||||
get_titles(future.result().text)
|
||||
|
||||
return playlist_title, info
|
||||
|
@ -815,9 +817,9 @@ class RipCore(list):
|
|||
:type source: str
|
||||
"""
|
||||
if source == "qobuz":
|
||||
secho("Enter Qobuz email:", fg="green")
|
||||
click.secho("Enter Qobuz email:", fg="green")
|
||||
self.config.file[source]["email"] = input()
|
||||
secho(
|
||||
click.secho(
|
||||
"Enter Qobuz password (will not show on screen):",
|
||||
fg="green",
|
||||
)
|
||||
|
@ -826,27 +828,27 @@ class RipCore(list):
|
|||
).hexdigest()
|
||||
|
||||
self.config.save()
|
||||
secho(
|
||||
click.secho(
|
||||
f'Credentials saved to config file at "{self.config._path}"',
|
||||
fg="green",
|
||||
)
|
||||
elif source == "deezer":
|
||||
secho(
|
||||
click.secho(
|
||||
"If you're not sure how to find the ARL cookie, see the instructions at ",
|
||||
italic=True,
|
||||
nl=False,
|
||||
dim=True,
|
||||
)
|
||||
secho(
|
||||
click.secho(
|
||||
"https://github.com/nathom/streamrip/wiki/Finding-your-Deezer-ARL-Cookie",
|
||||
underline=True,
|
||||
italic=True,
|
||||
fg="blue",
|
||||
)
|
||||
|
||||
self.config.file["deezer"]["arl"] = input(style("ARL: ", fg="green"))
|
||||
self.config.file["deezer"]["arl"] = input(click.style("ARL: ", fg="green"))
|
||||
self.config.save()
|
||||
secho(
|
||||
click.secho(
|
||||
f'Credentials saved to config file at "{self.config._path}"',
|
||||
fg="green",
|
||||
)
|
||||
|
@ -854,19 +856,19 @@ class RipCore(list):
|
|||
raise Exception
|
||||
|
||||
def _config_updating_message(self):
|
||||
secho(
|
||||
click.secho(
|
||||
"Updating config file... Some settings may be lost. Please run the "
|
||||
"command again.",
|
||||
fg="magenta",
|
||||
)
|
||||
|
||||
def _config_corrupted_message(self, err: Exception):
|
||||
secho(
|
||||
click.secho(
|
||||
"There was a problem with your config file. This happens "
|
||||
"sometimes after updates. Run ",
|
||||
nl=False,
|
||||
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")
|
||||
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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue