mirror of
https://github.com/Wojtek242/qobuz-dl.git
synced 2024-11-22 02:55:25 +01:00
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:
parent
32015dca4f
commit
41cc9a5333
@ -106,10 +106,10 @@ def add_common_arg(custom_parser, default_folder, default_quality):
|
|||||||
"-ff",
|
"-ff",
|
||||||
"--folder-format",
|
"--folder-format",
|
||||||
metavar="PATTERN",
|
metavar="PATTERN",
|
||||||
help="pattern for formatting folder names, e.g "
|
help="""pattern for formatting folder names, e.g
|
||||||
'"{artist} - {album} ({year})". available keys: artist, '
|
"{artist} - {album} ({year})". available keys: artist,
|
||||||
"albumartist, album, year, sampling_rate, bit_rate, tracktitle. "
|
albumartist, album, year, sampling_rate, bit_rate, tracktitle, version.
|
||||||
"cannot contain characters used by the system, which includes /:<>",
|
cannot contain characters used by the system, which includes /:<>""",
|
||||||
)
|
)
|
||||||
custom_parser.add_argument(
|
custom_parser.add_argument(
|
||||||
"-tf",
|
"-tf",
|
||||||
@ -117,11 +117,15 @@ def add_common_arg(custom_parser, default_folder, default_quality):
|
|||||||
metavar="PATTERN",
|
metavar="PATTERN",
|
||||||
help="pattern for formatting track names. see `folder-format`.",
|
help="pattern for formatting track names. see `folder-format`.",
|
||||||
)
|
)
|
||||||
|
# TODO: add customization options
|
||||||
custom_parser.add_argument(
|
custom_parser.add_argument(
|
||||||
"-sd",
|
"-s",
|
||||||
"--smart-discography",
|
"--smart-discography",
|
||||||
action="store_true",
|
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).""",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,8 +187,8 @@ class QobuzDL:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self.smart_discography and url_type == "artist":
|
if self.smart_discography and url_type == "artist":
|
||||||
logger.info(f"{YELLOW}Filtering {content_name}'s discography")
|
# change `save_space` and `skip_extras` for customization
|
||||||
items = self.smart_discography_filter(
|
items = self._smart_discography_filter(
|
||||||
content,
|
content,
|
||||||
save_space=True,
|
save_space=True,
|
||||||
skip_extras=True,
|
skip_extras=True,
|
||||||
@ -490,8 +490,8 @@ class QobuzDL:
|
|||||||
with open(os.path.join(pl_directory, pl_name), "w") as pl:
|
with open(os.path.join(pl_directory, pl_name), "w") as pl:
|
||||||
pl.write("\n\n".join(track_list))
|
pl.write("\n\n".join(track_list))
|
||||||
|
|
||||||
def smart_discography_filter(
|
def _smart_discography_filter(
|
||||||
self, contents: list, save_space=False, skip_extras=False
|
self, contents: list, save_space: bool = False, skip_extras: bool = False
|
||||||
) -> list:
|
) -> list:
|
||||||
"""When downloading some artists' discography, many random and spam-like
|
"""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.
|
albums can get downloaded. This helps filter those out to just get the good stuff.
|
||||||
@ -508,8 +508,8 @@ class QobuzDL:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# for debugging
|
# for debugging
|
||||||
def print_album(album: dict):
|
def print_album(album: dict) -> None:
|
||||||
logger.info(
|
logger.debug(
|
||||||
f"{album['title']} - {album.get('version', '~~')} ({album['maximum_bit_depth']}/{album['maximum_sampling_rate']} by {album['artist']['name']}) {album['id']}"
|
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:
|
def is_type(album_t: str, album: dict) -> bool:
|
||||||
|
"""Check if album is of type `album_t`"""
|
||||||
version = album.get("version", "")
|
version = album.get("version", "")
|
||||||
title = album.get("title", "")
|
title = album.get("title", "")
|
||||||
regex = TYPE_REGEXES[album_t]
|
regex = TYPE_REGEXES[album_t]
|
||||||
@ -553,7 +554,7 @@ class QobuzDL:
|
|||||||
)
|
)
|
||||||
remaster_exists = any(is_type("remaster", a) for a in albums)
|
remaster_exists = any(is_type("remaster", a) for a in albums)
|
||||||
|
|
||||||
def is_valid(album):
|
def is_valid(album: dict) -> bool:
|
||||||
return (
|
return (
|
||||||
album["maximum_bit_depth"] == best_bit_depth
|
album["maximum_bit_depth"] == best_bit_depth
|
||||||
and album["maximum_sampling_rate"] == best_sampling_rate
|
and album["maximum_sampling_rate"] == best_sampling_rate
|
||||||
|
Loading…
Reference in New Issue
Block a user