From 41cc9a5333b1edfc1d8ec9128a6c4b01825e6a86 Mon Sep 17 00:00:00 2001 From: nathannathant <74019033+pynathanthomas@users.noreply.github.com> Date: Fri, 5 Mar 2021 12:02:05 -0800 Subject: [PATCH] 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> --- qobuz_dl/commands.py | 16 ++++++++++------ qobuz_dl/core.py | 15 ++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/qobuz_dl/commands.py b/qobuz_dl/commands.py index b412319..08b02dd 100644 --- a/qobuz_dl/commands.py +++ b/qobuz_dl/commands.py @@ -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).""", ) diff --git a/qobuz_dl/core.py b/qobuz_dl/core.py index 1554252..00e7990 100644 --- a/qobuz_dl/core.py +++ b/qobuz_dl/core.py @@ -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