mirror of
https://github.com/Wojtek242/qobuz-dl.git
synced 2024-11-22 11:05:25 +01:00
Add more options to config file
This commit is contained in:
parent
17c8ff5ece
commit
f370b5c0b0
@ -5,7 +5,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import qobuz_dl.spoofbuz as spoofbuz
|
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.commands import qobuz_dl_args
|
||||||
from qobuz_dl.core import QobuzDL
|
from qobuz_dl.core import QobuzDL
|
||||||
|
|
||||||
@ -45,13 +45,23 @@ def reset_config(config_file):
|
|||||||
or "6"
|
or "6"
|
||||||
)
|
)
|
||||||
config["DEFAULT"]["default_limit"] = "20"
|
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...")
|
logging.info(f"{YELLOW}Getting tokens. Please wait...")
|
||||||
spoofer = spoofbuz.Spoofer()
|
spoofer = spoofbuz.Spoofer()
|
||||||
config["DEFAULT"]["app_id"] = str(spoofer.getAppId())
|
config["DEFAULT"]["app_id"] = str(spoofer.getAppId())
|
||||||
config["DEFAULT"]["secrets"] = ",".join(spoofer.getSecrets().values())
|
config["DEFAULT"]["secrets"] = ",".join(spoofer.getSecrets().values())
|
||||||
with open(config_file, "w") as configfile:
|
with open(config_file, "w") as configfile:
|
||||||
config.write(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():
|
def main():
|
||||||
@ -62,11 +72,6 @@ def main():
|
|||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
sys.exit(qobuz_dl_args().print_help())
|
sys.exit(qobuz_dl_args().print_help())
|
||||||
|
|
||||||
email = None
|
|
||||||
password = None
|
|
||||||
app_id = None
|
|
||||||
secrets = None
|
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(CONFIG_FILE)
|
config.read(CONFIG_FILE)
|
||||||
|
|
||||||
@ -76,6 +81,12 @@ def main():
|
|||||||
default_folder = config["DEFAULT"]["default_folder"]
|
default_folder = config["DEFAULT"]["default_folder"]
|
||||||
default_limit = config["DEFAULT"]["default_limit"]
|
default_limit = config["DEFAULT"]["default_limit"]
|
||||||
default_quality = config["DEFAULT"]["default_quality"]
|
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"]
|
app_id = config["DEFAULT"]["app_id"]
|
||||||
secrets = [
|
secrets = [
|
||||||
secret for secret in config["DEFAULT"]["secrets"].split(",") if secret
|
secret for secret in config["DEFAULT"]["secrets"].split(",") if secret
|
||||||
@ -83,10 +94,10 @@ def main():
|
|||||||
arguments = qobuz_dl_args(
|
arguments = qobuz_dl_args(
|
||||||
default_quality, default_limit, default_folder
|
default_quality, default_limit, default_folder
|
||||||
).parse_args()
|
).parse_args()
|
||||||
except (KeyError, UnicodeDecodeError):
|
except (KeyError, UnicodeDecodeError, configparser.Error):
|
||||||
arguments = qobuz_dl_args().parse_args()
|
arguments = qobuz_dl_args().parse_args()
|
||||||
if not arguments.reset:
|
if not arguments.reset:
|
||||||
logging.warning(
|
sys.exit(
|
||||||
f"{RED}Your config file is corrupted! Run 'qobuz-dl -r' to fix this"
|
f"{RED}Your config file is corrupted! Run 'qobuz-dl -r' to fix this"
|
||||||
)
|
)
|
||||||
if arguments.reset:
|
if arguments.reset:
|
||||||
@ -95,12 +106,14 @@ def main():
|
|||||||
qobuz = QobuzDL(
|
qobuz = QobuzDL(
|
||||||
arguments.directory,
|
arguments.directory,
|
||||||
arguments.quality,
|
arguments.quality,
|
||||||
arguments.embed_art,
|
arguments.embed_art or embed_art,
|
||||||
ignore_singles_eps=arguments.albums_only,
|
ignore_singles_eps=arguments.albums_only or albums_only,
|
||||||
no_m3u_for_playlists=arguments.no_m3u,
|
no_m3u_for_playlists=arguments.no_m3u or no_m3u,
|
||||||
quality_fallback=not arguments.no_fallback,
|
quality_fallback=not arguments.no_fallback or not no_fallback,
|
||||||
cover_og_quality=arguments.og_cover,
|
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)
|
qobuz.initialize_client(email, password, app_id, secrets)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -61,7 +61,7 @@ def add_common_arg(custom_parser, default_folder, default_quality):
|
|||||||
"--directory",
|
"--directory",
|
||||||
metavar="PATH",
|
metavar="PATH",
|
||||||
default=default_folder,
|
default=default_folder,
|
||||||
help='directory for downloads (default: "{}")'.format(default_folder),
|
help=f'directory for downloads (default: "{default_folder}")'
|
||||||
)
|
)
|
||||||
custom_parser.add_argument(
|
custom_parser.add_argument(
|
||||||
"-q",
|
"-q",
|
||||||
@ -70,7 +70,7 @@ def add_common_arg(custom_parser, default_folder, default_quality):
|
|||||||
default=default_quality,
|
default=default_quality,
|
||||||
help=(
|
help=(
|
||||||
'audio "quality" (5, 6, 7, 27)\n'
|
'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(
|
custom_parser.add_argument(
|
||||||
@ -94,6 +94,9 @@ def add_common_arg(custom_parser, default_folder, default_quality):
|
|||||||
custom_parser.add_argument(
|
custom_parser.add_argument(
|
||||||
"--og-cover", action="store_true", help="download cover art in its original quality (bigger file)"
|
"--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(
|
def qobuz_dl_args(
|
||||||
|
@ -59,6 +59,7 @@ class QobuzDL:
|
|||||||
no_m3u_for_playlists=False,
|
no_m3u_for_playlists=False,
|
||||||
quality_fallback=True,
|
quality_fallback=True,
|
||||||
cover_og_quality=False,
|
cover_og_quality=False,
|
||||||
|
no_cover=False
|
||||||
):
|
):
|
||||||
self.directory = self.create_dir(directory)
|
self.directory = self.create_dir(directory)
|
||||||
self.quality = quality
|
self.quality = quality
|
||||||
@ -70,6 +71,7 @@ class QobuzDL:
|
|||||||
self.no_m3u_for_playlists = no_m3u_for_playlists
|
self.no_m3u_for_playlists = no_m3u_for_playlists
|
||||||
self.quality_fallback = quality_fallback
|
self.quality_fallback = quality_fallback
|
||||||
self.cover_og_quality = cover_og_quality
|
self.cover_og_quality = cover_og_quality
|
||||||
|
self.no_cover = no_cover
|
||||||
|
|
||||||
def initialize_client(self, email, pwd, app_id, secrets):
|
def initialize_client(self, email, pwd, app_id, secrets):
|
||||||
self.client = qopy.Client(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.ignore_singles_eps,
|
||||||
self.quality_fallback,
|
self.quality_fallback,
|
||||||
self.cover_og_quality,
|
self.cover_og_quality,
|
||||||
|
self.no_cover,
|
||||||
)
|
)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
logger.error(f"Error getting release: {e}")
|
logger.error(f"Error getting release: {e}")
|
||||||
|
@ -175,6 +175,7 @@ def download_id_by_type(
|
|||||||
albums_only=False,
|
albums_only=False,
|
||||||
downgrade_quality=True,
|
downgrade_quality=True,
|
||||||
cover_og_quality=False,
|
cover_og_quality=False,
|
||||||
|
no_cover=False,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Download and get metadata by ID and type (album or track)
|
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 albums_only: Ignore Singles, EPs and VA releases
|
||||||
:param bool downgrade: Skip releases not available in set quality
|
:param bool downgrade: Skip releases not available in set quality
|
||||||
:param bool cover_og_quality: Download cover in its original quality
|
:param bool cover_og_quality: Download cover in its original quality
|
||||||
|
:param bool no_cover: Don't download cover art
|
||||||
"""
|
"""
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
@ -219,7 +221,8 @@ def download_id_by_type(
|
|||||||
sanitized_title = sanitize_filename("{} - {} [{}] [{}]".format(*dirT))
|
sanitized_title = sanitize_filename("{} - {} [{}] [{}]".format(*dirT))
|
||||||
dirn = os.path.join(path, sanitized_title)
|
dirn = os.path.join(path, sanitized_title)
|
||||||
os.makedirs(dirn, exist_ok=True)
|
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:
|
if "goodies" in meta:
|
||||||
try:
|
try:
|
||||||
get_extra(meta["goodies"][0]["url"], dirn, "booklet.pdf")
|
get_extra(meta["goodies"][0]["url"], dirn, "booklet.pdf")
|
||||||
@ -275,7 +278,10 @@ def download_id_by_type(
|
|||||||
sanitized_title = sanitize_filename("{} - {} [{}] [{}]".format(*dirT))
|
sanitized_title = sanitize_filename("{} - {} [{}] [{}]".format(*dirT))
|
||||||
dirn = os.path.join(path, sanitized_title)
|
dirn = os.path.join(path, sanitized_title)
|
||||||
os.makedirs(dirn, exist_ok=True)
|
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
|
is_mp3 = True if int(quality) == 5 else False
|
||||||
download_and_tag(dirn, count, parse, meta, meta, True, is_mp3, embed_art)
|
download_and_tag(dirn, count, parse, meta, meta, True, is_mp3, embed_art)
|
||||||
else:
|
else:
|
||||||
|
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ requirements = read_file("requirements.txt").strip().split()
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name=pkg_name,
|
name=pkg_name,
|
||||||
version="0.7.2",
|
version="0.8.0",
|
||||||
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",
|
||||||
|
Loading…
Reference in New Issue
Block a user