added command line option

also:
- replaced multiple concatenated help strings with one multiline string
- type hints

Signed-off-by: nathannathant <74019033+pynathanthomas@users.noreply.github.com>
This commit is contained in:
nathannathant 2021-03-05 12:02:05 -08:00
parent 32015dca4f
commit 41cc9a5333
2 changed files with 18 additions and 13 deletions

View File

@ -106,10 +106,10 @@ def add_common_arg(custom_parser, default_folder, default_quality):
"-ff",
"--folder-format",
metavar="PATTERN",
help="pattern for formatting folder names, e.g "
'"{artist} - {album} ({year})". available keys: artist, '
"albumartist, album, year, sampling_rate, bit_rate, tracktitle. "
"cannot contain characters used by the system, which includes /:<>",
help="""pattern for formatting folder names, e.g
"{artist} - {album} ({year})". available keys: artist,
albumartist, album, year, sampling_rate, bit_rate, tracktitle, version.
cannot contain characters used by the system, which includes /:<>""",
)
custom_parser.add_argument(
"-tf",
@ -117,11 +117,15 @@ def add_common_arg(custom_parser, default_folder, default_quality):
metavar="PATTERN",
help="pattern for formatting track names. see `folder-format`.",
)
# TODO: add customization options
custom_parser.add_argument(
"-sd",
"-s",
"--smart-discography",
action="store_true",
help="Try to filter out unrelated albums when requesting an artists discography.",
help="""Try to filter out spam-like albums when requesting an artist's
discography, and other optimizations. Filters albums not made by requested
artist, and deluxe/live/collection albums. Gives preference to remastered
albums, high bit depth/dynamic range, and low sampling rates (to save space).""",
)

View File

@ -187,8 +187,8 @@ class QobuzDL:
)
if self.smart_discography and url_type == "artist":
logger.info(f"{YELLOW}Filtering {content_name}'s discography")
items = self.smart_discography_filter(
# change `save_space` and `skip_extras` for customization
items = self._smart_discography_filter(
content,
save_space=True,
skip_extras=True,
@ -490,8 +490,8 @@ class QobuzDL:
with open(os.path.join(pl_directory, pl_name), "w") as pl:
pl.write("\n\n".join(track_list))
def smart_discography_filter(
self, contents: list, save_space=False, skip_extras=False
def _smart_discography_filter(
self, contents: list, save_space: bool = False, skip_extras: bool = False
) -> list:
"""When downloading some artists' discography, many random and spam-like
albums can get downloaded. This helps filter those out to just get the good stuff.
@ -508,8 +508,8 @@ class QobuzDL:
"""
# for debugging
def print_album(album: dict):
logger.info(
def print_album(album: dict) -> None:
logger.debug(
f"{album['title']} - {album.get('version', '~~')} ({album['maximum_bit_depth']}/{album['maximum_sampling_rate']} by {album['artist']['name']}) {album['id']}"
)
@ -519,6 +519,7 @@ class QobuzDL:
}
def is_type(album_t: str, album: dict) -> bool:
"""Check if album is of type `album_t`"""
version = album.get("version", "")
title = album.get("title", "")
regex = TYPE_REGEXES[album_t]
@ -553,7 +554,7 @@ class QobuzDL:
)
remaster_exists = any(is_type("remaster", a) for a in albums)
def is_valid(album):
def is_valid(album: dict) -> bool:
return (
album["maximum_bit_depth"] == best_bit_depth
and album["maximum_sampling_rate"] == best_sampling_rate