Skip to content

Commit

Permalink
added command line option
Browse files Browse the repository at this point in the history
also:
- replaced multiple concatenated help strings with one multiline string
- type hints

Signed-off-by: nathannathant <[email protected]>
  • Loading branch information
nathom committed Mar 5, 2021
1 parent 32015dc commit 41cc9a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
16 changes: 10 additions & 6 deletions qobuz_dl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,26 @@ 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",
"--track-format",
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).""",
)


Expand Down
15 changes: 8 additions & 7 deletions qobuz_dl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def handle_url(self, url):
)

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,
Expand Down Expand Up @@ -490,8 +490,8 @@ def make_m3u(self, pl_directory):
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.
Expand All @@ -508,8 +508,8 @@ def smart_discography_filter(
"""

# 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']}"
)

Expand All @@ -519,6 +519,7 @@ def print_album(album: dict):
}

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]
Expand Down Expand Up @@ -553,7 +554,7 @@ def essence(album: dict) -> str:
)
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
Expand Down

0 comments on commit 41cc9a5

Please sign in to comment.