mirror of
https://github.com/Wojtek242/qobuz-dl.git
synced 2024-12-22 15:24:40 +01:00
Fix ValueError
Make commands.py readable
This commit is contained in:
parent
b7224d5515
commit
feeec9bb07
@ -1,6 +1,89 @@
|
||||
import argparse
|
||||
|
||||
|
||||
def fun_args(subparsers, default_limit):
|
||||
interactive = subparsers.add_parser(
|
||||
"fun",
|
||||
description="Interactively search for tracks and albums.",
|
||||
help="interactive mode",
|
||||
)
|
||||
interactive.add_argument(
|
||||
"-a",
|
||||
"--albums-only",
|
||||
action="store_true",
|
||||
help="enable albums-only search",
|
||||
)
|
||||
interactive.add_argument(
|
||||
"-l",
|
||||
"--limit",
|
||||
metavar="int",
|
||||
default=default_limit,
|
||||
help="limit of search results by type (default: 10)",
|
||||
)
|
||||
return interactive
|
||||
|
||||
|
||||
def lucky_args(subparsers):
|
||||
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",
|
||||
default=1,
|
||||
help="number of results to download (default: 1)",
|
||||
)
|
||||
lucky.add_argument("QUERY", nargs="+", help="search query")
|
||||
return lucky
|
||||
|
||||
|
||||
def dl_args(subparsers):
|
||||
download = subparsers.add_parser(
|
||||
"dl",
|
||||
description="Download by album/track/artist/label/playlist URL.",
|
||||
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(
|
||||
"-e", "--embed-art", action="store_true", help="embed cover art into files"
|
||||
)
|
||||
custom_parser.add_argument(
|
||||
"-d",
|
||||
"--directory",
|
||||
metavar="PATH",
|
||||
default=default_folder,
|
||||
help='directory for downloads (default: "{}")'.format(default_folder),
|
||||
)
|
||||
custom_parser.add_argument(
|
||||
"-q",
|
||||
"--quality",
|
||||
metavar="int",
|
||||
default=default_quality,
|
||||
help=(
|
||||
'audio "quality" (5, 6, 7, 27)\n'
|
||||
"[320, LOSSLESS, 24B <96KHZ, 24B >96KHZ] (default: 6)"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def qobuz_dl_args(
|
||||
default_quality=6, default_limit=10, default_folder="Qobuz Downloads"
|
||||
):
|
||||
@ -22,80 +105,12 @@ def qobuz_dl_args(
|
||||
dest="command",
|
||||
)
|
||||
|
||||
def add_common_arg(custom_parser):
|
||||
custom_parser.add_argument(
|
||||
"-e", "--embed-art", action="store_true", help="embed cover art into files"
|
||||
)
|
||||
custom_parser.add_argument(
|
||||
"-d",
|
||||
"--directory",
|
||||
metavar="PATH",
|
||||
default=default_folder,
|
||||
help='directory for downloads (default: "{}")'.format(default_folder),
|
||||
)
|
||||
custom_parser.add_argument(
|
||||
"-q",
|
||||
"--quality",
|
||||
metavar="int",
|
||||
default=default_quality,
|
||||
help=(
|
||||
'audio "quality" (5, 6, 7, 27)\n'
|
||||
"[320, LOSSLESS, 24B <96KHZ, 24B >96KHZ] (default: 6)"
|
||||
),
|
||||
)
|
||||
|
||||
interactive = subparsers.add_parser(
|
||||
"fun",
|
||||
description="Interactively search for tracks and albums.",
|
||||
help="interactive mode",
|
||||
)
|
||||
interactive.add_argument(
|
||||
"-a",
|
||||
"--albums-only",
|
||||
action="store_true",
|
||||
help="enable albums-only search",
|
||||
)
|
||||
interactive.add_argument(
|
||||
"-l",
|
||||
"--limit",
|
||||
metavar="int",
|
||||
default=default_limit,
|
||||
help="limit of search results by type (default: 10)",
|
||||
)
|
||||
add_common_arg(interactive)
|
||||
|
||||
download = subparsers.add_parser(
|
||||
"dl",
|
||||
description="Download by album/track/artist/label/playlist URL.",
|
||||
help="input mode",
|
||||
)
|
||||
add_common_arg(download)
|
||||
download.add_argument(
|
||||
"SOURCE",
|
||||
metavar="SOURCE",
|
||||
nargs="+",
|
||||
help=("one or more URLs (space separated) or a text file"),
|
||||
)
|
||||
|
||||
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",
|
||||
default=1,
|
||||
help="number of results to download (default: 1)",
|
||||
)
|
||||
add_common_arg(lucky)
|
||||
lucky.add_argument("QUERY", nargs="+", help="search query")
|
||||
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)
|
||||
]
|
||||
|
||||
return parser
|
||||
|
@ -26,8 +26,9 @@ def tag_flac(filename, root_dir, final_name, d, album, istrack=True, em_image=Fa
|
||||
audio["TRACKNUMBER"] = str(d["track_number"]) # TRACK NUMBER
|
||||
|
||||
try:
|
||||
audio["WORK"] = d["work"]
|
||||
except KeyError:
|
||||
if d["work"]: # not none
|
||||
audio["WORK"] = d["work"]
|
||||
except (KeyError, ValueError):
|
||||
pass
|
||||
|
||||
try:
|
||||
@ -95,8 +96,9 @@ def tag_mp3(filename, root_dir, final_name, d, album, istrack=True, em_image=Fal
|
||||
audio["tracknumber"] = str(d["track_number"])
|
||||
|
||||
try:
|
||||
audio["discsubtitle"] = d["work"]
|
||||
except KeyError:
|
||||
if d["work"]: # not none
|
||||
audio["discsubtitle"] = d["work"]
|
||||
except (KeyError, ValueError):
|
||||
pass
|
||||
try:
|
||||
audio["composer"] = d["composer"]["name"]
|
||||
|
Loading…
Reference in New Issue
Block a user