Add more options to config file

This commit is contained in:
vitiko98 2020-12-18 17:17:20 -04:00
parent 17c8ff5ece
commit f370b5c0b0
5 changed files with 44 additions and 19 deletions

View File

@ -5,7 +5,7 @@ import os
import sys
import qobuz_dl.spoofbuz as spoofbuz
from qobuz_dl.color import DF, GREEN, CYAN, RED, YELLOW
from qobuz_dl.color import CYAN, DF, GREEN, RED, YELLOW
from qobuz_dl.commands import qobuz_dl_args
from qobuz_dl.core import QobuzDL
@ -45,13 +45,23 @@ def reset_config(config_file):
or "6"
)
config["DEFAULT"]["default_limit"] = "20"
config["DEFAULT"]["no_m3u"] = "false"
config["DEFAULT"]["albums_only"] = "false"
config["DEFAULT"]["no_fallback"] = "false"
config["DEFAULT"]["og_cover"] = "false"
config["DEFAULT"]["embed_art"] = "false"
config["DEFAULT"]["no_cover"] = "false"
logging.info(f"{YELLOW}Getting tokens. Please wait...")
spoofer = spoofbuz.Spoofer()
config["DEFAULT"]["app_id"] = str(spoofer.getAppId())
config["DEFAULT"]["secrets"] = ",".join(spoofer.getSecrets().values())
with open(config_file, "w") as configfile:
config.write(configfile)
logging.info(f"{GREEN}Config file updated.")
logging.info(
f"{GREEN}Config file updated. Edit more options in {config_file}"
"\nso you don't have to call custom flags every time you run "
"a qobuz-dl command."
)
def main():
@ -62,11 +72,6 @@ def main():
if len(sys.argv) < 2:
sys.exit(qobuz_dl_args().print_help())
email = None
password = None
app_id = None
secrets = None
config = configparser.ConfigParser()
config.read(CONFIG_FILE)
@ -76,6 +81,12 @@ def main():
default_folder = config["DEFAULT"]["default_folder"]
default_limit = config["DEFAULT"]["default_limit"]
default_quality = config["DEFAULT"]["default_quality"]
no_m3u = config["DEFAULT"]["no_m3u"]
albums_only = config["DEFAULT"]["albums_only"]
no_fallback = config["DEFAULT"]["no_fallback"]
og_cover = config["DEFAULT"]["og_cover"]
embed_art = config["DEFAULT"]["embed_art"]
no_cover = config["DEFAULT"]["no_cover"]
app_id = config["DEFAULT"]["app_id"]
secrets = [
secret for secret in config["DEFAULT"]["secrets"].split(",") if secret
@ -83,10 +94,10 @@ def main():
arguments = qobuz_dl_args(
default_quality, default_limit, default_folder
).parse_args()
except (KeyError, UnicodeDecodeError):
except (KeyError, UnicodeDecodeError, configparser.Error):
arguments = qobuz_dl_args().parse_args()
if not arguments.reset:
logging.warning(
sys.exit(
f"{RED}Your config file is corrupted! Run 'qobuz-dl -r' to fix this"
)
if arguments.reset:
@ -95,12 +106,14 @@ def main():
qobuz = QobuzDL(
arguments.directory,
arguments.quality,
arguments.embed_art,
ignore_singles_eps=arguments.albums_only,
no_m3u_for_playlists=arguments.no_m3u,
quality_fallback=not arguments.no_fallback,
cover_og_quality=arguments.og_cover,
arguments.embed_art or embed_art,
ignore_singles_eps=arguments.albums_only or albums_only,
no_m3u_for_playlists=arguments.no_m3u or no_m3u,
quality_fallback=not arguments.no_fallback or not no_fallback,
cover_og_quality=arguments.og_cover or og_cover,
no_cover=arguments.no_cover or no_cover,
)
qobuz.initialize_client(email, password, app_id, secrets)
try:

View File

@ -61,7 +61,7 @@ def add_common_arg(custom_parser, default_folder, default_quality):
"--directory",
metavar="PATH",
default=default_folder,
help='directory for downloads (default: "{}")'.format(default_folder),
help=f'directory for downloads (default: "{default_folder}")'
)
custom_parser.add_argument(
"-q",
@ -70,7 +70,7 @@ def add_common_arg(custom_parser, default_folder, default_quality):
default=default_quality,
help=(
'audio "quality" (5, 6, 7, 27)\n'
"[320, LOSSLESS, 24B <96KHZ, 24B >96KHZ] (default: 6)"
f"[320, LOSSLESS, 24B<=96KHZ, 24B>96KHZ] (default: {default_quality})"
),
)
custom_parser.add_argument(
@ -94,6 +94,9 @@ def add_common_arg(custom_parser, default_folder, default_quality):
custom_parser.add_argument(
"--og-cover", action="store_true", help="download cover art in its original quality (bigger file)"
)
custom_parser.add_argument(
"--no-cover", action="store_true", help="don't download cover art"
)
def qobuz_dl_args(

View File

@ -59,6 +59,7 @@ class QobuzDL:
no_m3u_for_playlists=False,
quality_fallback=True,
cover_og_quality=False,
no_cover=False
):
self.directory = self.create_dir(directory)
self.quality = quality
@ -70,6 +71,7 @@ class QobuzDL:
self.no_m3u_for_playlists = no_m3u_for_playlists
self.quality_fallback = quality_fallback
self.cover_og_quality = cover_og_quality
self.no_cover = no_cover
def initialize_client(self, email, pwd, app_id, secrets):
self.client = qopy.Client(email, pwd, app_id, secrets)
@ -107,6 +109,7 @@ class QobuzDL:
self.ignore_singles_eps,
self.quality_fallback,
self.cover_og_quality,
self.no_cover,
)
except requests.exceptions.RequestException as e:
logger.error(f"Error getting release: {e}")

View File

@ -175,6 +175,7 @@ def download_id_by_type(
albums_only=False,
downgrade_quality=True,
cover_og_quality=False,
no_cover=False,
):
"""
Download and get metadata by ID and type (album or track)
@ -188,6 +189,7 @@ def download_id_by_type(
:param bool albums_only: Ignore Singles, EPs and VA releases
:param bool downgrade: Skip releases not available in set quality
:param bool cover_og_quality: Download cover in its original quality
:param bool no_cover: Don't download cover art
"""
count = 0
@ -219,7 +221,8 @@ def download_id_by_type(
sanitized_title = sanitize_filename("{} - {} [{}] [{}]".format(*dirT))
dirn = os.path.join(path, sanitized_title)
os.makedirs(dirn, exist_ok=True)
get_extra(meta["image"]["large"], dirn, og_quality=cover_og_quality)
if not no_cover:
get_extra(meta["image"]["large"], dirn, og_quality=cover_og_quality)
if "goodies" in meta:
try:
get_extra(meta["goodies"][0]["url"], dirn, "booklet.pdf")
@ -275,7 +278,10 @@ def download_id_by_type(
sanitized_title = sanitize_filename("{} - {} [{}] [{}]".format(*dirT))
dirn = os.path.join(path, sanitized_title)
os.makedirs(dirn, exist_ok=True)
get_extra(meta["album"]["image"]["large"], dirn, og_quality=cover_og_quality)
if not no_cover:
get_extra(
meta["album"]["image"]["large"], dirn, og_quality=cover_og_quality
)
is_mp3 = True if int(quality) == 5 else False
download_and_tag(dirn, count, parse, meta, meta, True, is_mp3, embed_art)
else:

View File

@ -13,7 +13,7 @@ requirements = read_file("requirements.txt").strip().split()
setup(
name=pkg_name,
version="0.7.2",
version="0.8.0",
author="Vitiko",
author_email="vhnz98@gmail.com",
description="The complete Lossless and Hi-Res music downloader for Qobuz",