Fix ValueError

Make commands.py readable
This commit is contained in:
vitiko98 2020-12-12 18:03:51 -04:00
parent b7224d5515
commit feeec9bb07
3 changed files with 97 additions and 80 deletions

View File

@ -1,6 +1,89 @@
import argparse 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( def qobuz_dl_args(
default_quality=6, default_limit=10, default_folder="Qobuz Downloads" default_quality=6, default_limit=10, default_folder="Qobuz Downloads"
): ):
@ -22,80 +105,12 @@ def qobuz_dl_args(
dest="command", dest="command",
) )
def add_common_arg(custom_parser): interactive = fun_args(subparsers, default_limit)
custom_parser.add_argument( download = dl_args(subparsers)
"-e", "--embed-art", action="store_true", help="embed cover art into files" lucky = lucky_args(subparsers)
) [
custom_parser.add_argument( add_common_arg(i, default_folder, default_quality)
"-d", for i in (interactive, download, lucky)
"--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")
return parser return parser

View File

@ -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 audio["TRACKNUMBER"] = str(d["track_number"]) # TRACK NUMBER
try: try:
if d["work"]: # not none
audio["WORK"] = d["work"] audio["WORK"] = d["work"]
except KeyError: except (KeyError, ValueError):
pass pass
try: 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"]) audio["tracknumber"] = str(d["track_number"])
try: try:
if d["work"]: # not none
audio["discsubtitle"] = d["work"] audio["discsubtitle"] = d["work"]
except KeyError: except (KeyError, ValueError):
pass pass
try: try:
audio["composer"] = d["composer"]["name"] audio["composer"] = d["composer"]["name"]

View File

@ -16,7 +16,7 @@ if os.name == "nt" or "win" in sys.platform:
setup( setup(
name=pkg_name, name=pkg_name,
version="0.5.4.1", version="0.5.4.2",
author="Vitiko", author="Vitiko",
author_email="vhnz98@gmail.com", author_email="vhnz98@gmail.com",
description="The complete Lossless and Hi-Res music downloader for Qobuz", description="The complete Lossless and Hi-Res music downloader for Qobuz",