2020-12-09 19:52:18 +01:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
2020-12-12 23:03:51 +01:00
|
|
|
def fun_args(subparsers, default_limit):
|
2020-12-09 19:52:18 +01:00
|
|
|
interactive = subparsers.add_parser(
|
|
|
|
"fun",
|
|
|
|
description="Interactively search for tracks and albums.",
|
|
|
|
help="interactive mode",
|
|
|
|
)
|
|
|
|
interactive.add_argument(
|
|
|
|
"-l",
|
|
|
|
"--limit",
|
|
|
|
metavar="int",
|
|
|
|
default=default_limit,
|
2020-12-15 00:48:15 +01:00
|
|
|
help="limit of search results (default: 20)",
|
2020-12-09 19:52:18 +01:00
|
|
|
)
|
2020-12-12 23:03:51 +01:00
|
|
|
return interactive
|
2020-12-09 19:52:18 +01:00
|
|
|
|
|
|
|
|
2020-12-12 23:03:51 +01:00
|
|
|
def lucky_args(subparsers):
|
2020-12-09 19:52:18 +01:00
|
|
|
lucky = subparsers.add_parser(
|
|
|
|
"lucky",
|
|
|
|
description="Download the first <n> albums returned from a Qobuz search.",
|
|
|
|
help="lucky mode",
|
|
|
|
)
|
|
|
|
lucky.add_argument(
|
|
|
|
"-t",
|
|
|
|
"--type",
|
|
|
|
default="album",
|
|
|
|
help="type of items to search (artist, album, track, playlist) (default: album)",
|
|
|
|
)
|
|
|
|
lucky.add_argument(
|
|
|
|
"-n",
|
|
|
|
"--number",
|
|
|
|
metavar="int",
|
2020-12-12 22:40:52 +01:00
|
|
|
default=1,
|
2020-12-09 19:52:18 +01:00
|
|
|
help="number of results to download (default: 1)",
|
|
|
|
)
|
|
|
|
lucky.add_argument("QUERY", nargs="+", help="search query")
|
2020-12-12 23:03:51 +01:00
|
|
|
return lucky
|
|
|
|
|
|
|
|
|
|
|
|
def dl_args(subparsers):
|
|
|
|
download = subparsers.add_parser(
|
|
|
|
"dl",
|
2020-12-15 00:48:15 +01:00
|
|
|
description="Download by album/track/artist/label/playlist/last.fm-playlist URL.",
|
2020-12-12 23:03:51 +01:00
|
|
|
help="input mode",
|
|
|
|
)
|
|
|
|
download.add_argument(
|
|
|
|
"SOURCE",
|
|
|
|
metavar="SOURCE",
|
|
|
|
nargs="+",
|
|
|
|
help=("one or more URLs (space separated) or a text file"),
|
|
|
|
)
|
|
|
|
return download
|
|
|
|
|
|
|
|
|
|
|
|
def add_common_arg(custom_parser, default_folder, default_quality):
|
|
|
|
custom_parser.add_argument(
|
|
|
|
"-d",
|
|
|
|
"--directory",
|
|
|
|
metavar="PATH",
|
|
|
|
default=default_folder,
|
2020-12-18 22:17:20 +01:00
|
|
|
help=f'directory for downloads (default: "{default_folder}")'
|
2020-12-12 23:03:51 +01:00
|
|
|
)
|
|
|
|
custom_parser.add_argument(
|
|
|
|
"-q",
|
|
|
|
"--quality",
|
|
|
|
metavar="int",
|
|
|
|
default=default_quality,
|
|
|
|
help=(
|
|
|
|
'audio "quality" (5, 6, 7, 27)\n'
|
2020-12-18 22:17:20 +01:00
|
|
|
f"[320, LOSSLESS, 24B<=96KHZ, 24B>96KHZ] (default: {default_quality})"
|
2020-12-12 23:03:51 +01:00
|
|
|
),
|
|
|
|
)
|
2020-12-15 00:48:15 +01:00
|
|
|
custom_parser.add_argument(
|
|
|
|
"--albums-only",
|
|
|
|
action="store_true",
|
|
|
|
help=("don't download singles, EPs and VA releases"),
|
|
|
|
)
|
2020-12-15 21:23:11 +01:00
|
|
|
custom_parser.add_argument(
|
|
|
|
"--no-m3u",
|
|
|
|
action="store_true",
|
|
|
|
help="don't create .m3u files when downloading playlists",
|
|
|
|
)
|
2020-12-17 00:07:40 +01:00
|
|
|
custom_parser.add_argument(
|
|
|
|
"--no-fallback",
|
|
|
|
action="store_true",
|
|
|
|
help="disable quality fallback (skip releases not available in set quality)",
|
|
|
|
)
|
|
|
|
custom_parser.add_argument(
|
|
|
|
"-e", "--embed-art", action="store_true", help="embed cover art into files"
|
|
|
|
)
|
2020-12-18 02:55:42 +01:00
|
|
|
custom_parser.add_argument(
|
|
|
|
"--og-cover", action="store_true", help="download cover art in its original quality (bigger file)"
|
|
|
|
)
|
2020-12-18 22:17:20 +01:00
|
|
|
custom_parser.add_argument(
|
|
|
|
"--no-cover", action="store_true", help="don't download cover art"
|
|
|
|
)
|
2020-12-12 23:03:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
def qobuz_dl_args(
|
2020-12-15 00:48:15 +01:00
|
|
|
default_quality=6, default_limit=20, default_folder="Qobuz Downloads"
|
2020-12-12 23:03:51 +01:00
|
|
|
):
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
prog="qobuz-dl",
|
|
|
|
description=(
|
|
|
|
"The ultimate Qobuz music downloader.\nSee usage"
|
|
|
|
" examples on https://github.com/vitiko98/qobuz-dl"
|
|
|
|
),
|
|
|
|
formatter_class=argparse.RawTextHelpFormatter,
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-r", "--reset", action="store_true", help="create/reset config file"
|
|
|
|
)
|
|
|
|
|
|
|
|
subparsers = parser.add_subparsers(
|
|
|
|
title="commands",
|
|
|
|
description="run qobuz-dl <command> --help for more info\n(e.g. qobuz-dl fun --help)",
|
|
|
|
dest="command",
|
|
|
|
)
|
|
|
|
|
|
|
|
interactive = fun_args(subparsers, default_limit)
|
|
|
|
download = dl_args(subparsers)
|
|
|
|
lucky = lucky_args(subparsers)
|
|
|
|
[
|
|
|
|
add_common_arg(i, default_folder, default_quality)
|
|
|
|
for i in (interactive, download, lucky)
|
|
|
|
]
|
2020-12-09 19:52:18 +01:00
|
|
|
|
|
|
|
return parser
|