2020-12-10 04:39:16 +01:00
|
|
|
import base64
|
2020-12-07 20:58:51 +01:00
|
|
|
import configparser
|
2020-12-18 02:27:08 +01:00
|
|
|
import logging
|
2020-12-07 20:58:51 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import qobuz_dl.spoofbuz as spoofbuz
|
2020-12-18 02:27:08 +01:00
|
|
|
from qobuz_dl.color import DF, GREEN, MAGENTA, RED, YELLOW
|
2020-12-09 19:52:18 +01:00
|
|
|
from qobuz_dl.commands import qobuz_dl_args
|
2020-12-18 02:27:08 +01:00
|
|
|
from qobuz_dl.core import QobuzDL
|
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO,
|
|
|
|
format="%(message)s",
|
|
|
|
)
|
2020-12-07 20:58:51 +01:00
|
|
|
|
2020-12-07 21:37:51 +01:00
|
|
|
if os.name == "nt":
|
|
|
|
OS_CONFIG = os.environ.get("APPDATA")
|
|
|
|
else:
|
|
|
|
OS_CONFIG = os.path.join(os.environ["HOME"], ".config")
|
|
|
|
|
2020-12-07 20:58:51 +01:00
|
|
|
CONFIG_PATH = os.path.join(OS_CONFIG, "qobuz-dl")
|
|
|
|
CONFIG_FILE = os.path.join(CONFIG_PATH, "config.ini")
|
|
|
|
|
|
|
|
|
|
|
|
def reset_config(config_file):
|
2020-12-18 02:27:08 +01:00
|
|
|
logging.info(f"{YELLOW}Creating config file: {config_file}")
|
2020-12-07 20:58:51 +01:00
|
|
|
config = configparser.ConfigParser()
|
2020-12-18 02:27:08 +01:00
|
|
|
config["DEFAULT"]["email"] = input(f"{MAGENTA}Enter your email:\n-{DF} ")
|
2020-12-10 04:39:16 +01:00
|
|
|
config["DEFAULT"]["password"] = base64.b64encode(
|
2020-12-18 02:27:08 +01:00
|
|
|
input(f"{MAGENTA}Enter your password\n-{DF} ").encode()
|
2020-12-10 04:39:16 +01:00
|
|
|
).decode()
|
2020-12-07 20:58:51 +01:00
|
|
|
config["DEFAULT"]["default_folder"] = (
|
2020-12-18 02:27:08 +01:00
|
|
|
input(
|
|
|
|
f"{MAGENTA}Folder for downloads (leave empy for default 'Qobuz Downloads')\n-{DF} "
|
|
|
|
)
|
2020-12-07 20:58:51 +01:00
|
|
|
or "Qobuz Downloads"
|
|
|
|
)
|
|
|
|
config["DEFAULT"]["default_quality"] = (
|
|
|
|
input(
|
2020-12-18 02:27:08 +01:00
|
|
|
f"{MAGENTA}Download quality (5, 6, 7, 27) "
|
2020-12-07 20:58:51 +01:00
|
|
|
"[320, LOSSLESS, 24B <96KHZ, 24B >96KHZ]"
|
2020-12-18 02:27:08 +01:00
|
|
|
f"\n(leave empy for default '6')\n-{DF} "
|
2020-12-07 20:58:51 +01:00
|
|
|
)
|
|
|
|
or "6"
|
|
|
|
)
|
2020-12-15 00:48:15 +01:00
|
|
|
config["DEFAULT"]["default_limit"] = "20"
|
2020-12-18 02:27:08 +01:00
|
|
|
logging.info(f"{YELLOW}Getting tokens. Please wait...")
|
2020-12-07 20:58:51 +01:00
|
|
|
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)
|
2020-12-18 02:27:08 +01:00
|
|
|
logging.info(f"{GREEN}Config file updated.")
|
2020-12-07 20:58:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if not os.path.isdir(CONFIG_PATH) or not os.path.isfile(CONFIG_FILE):
|
2020-12-15 00:48:15 +01:00
|
|
|
os.makedirs(CONFIG_PATH, exist_ok=True)
|
2020-12-07 20:58:51 +01:00
|
|
|
reset_config(CONFIG_FILE)
|
|
|
|
|
2020-12-09 19:52:18 +01:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
sys.exit(qobuz_dl_args().print_help())
|
|
|
|
|
2020-12-07 20:58:51 +01:00
|
|
|
email = None
|
|
|
|
password = None
|
|
|
|
app_id = None
|
|
|
|
secrets = None
|
|
|
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read(CONFIG_FILE)
|
|
|
|
|
|
|
|
try:
|
|
|
|
email = config["DEFAULT"]["email"]
|
2020-12-10 04:39:16 +01:00
|
|
|
password = base64.b64decode(config["DEFAULT"]["password"]).decode()
|
2020-12-07 20:58:51 +01:00
|
|
|
default_folder = config["DEFAULT"]["default_folder"]
|
|
|
|
default_limit = config["DEFAULT"]["default_limit"]
|
|
|
|
default_quality = config["DEFAULT"]["default_quality"]
|
|
|
|
app_id = config["DEFAULT"]["app_id"]
|
|
|
|
secrets = [
|
|
|
|
secret for secret in config["DEFAULT"]["secrets"].split(",") if secret
|
|
|
|
]
|
2020-12-09 19:52:18 +01:00
|
|
|
arguments = qobuz_dl_args(
|
|
|
|
default_quality, default_limit, default_folder
|
|
|
|
).parse_args()
|
2020-12-10 04:39:16 +01:00
|
|
|
except (KeyError, UnicodeDecodeError):
|
2020-12-09 19:52:18 +01:00
|
|
|
arguments = qobuz_dl_args().parse_args()
|
|
|
|
if not arguments.reset:
|
2020-12-18 02:27:08 +01:00
|
|
|
logging.warning(
|
|
|
|
f"{RED}Your config file is corrupted! Run 'qobuz-dl -r' to fix this"
|
|
|
|
)
|
2020-12-09 19:52:18 +01:00
|
|
|
if arguments.reset:
|
2020-12-07 20:58:51 +01:00
|
|
|
sys.exit(reset_config(CONFIG_FILE))
|
|
|
|
|
2020-12-15 00:48:15 +01:00
|
|
|
qobuz = QobuzDL(
|
|
|
|
arguments.directory,
|
|
|
|
arguments.quality,
|
|
|
|
arguments.embed_art,
|
|
|
|
ignore_singles_eps=arguments.albums_only,
|
2020-12-15 21:23:11 +01:00
|
|
|
no_m3u_for_playlists=arguments.no_m3u,
|
2020-12-17 00:07:40 +01:00
|
|
|
quality_fallback=not arguments.no_fallback,
|
2020-12-18 02:55:42 +01:00
|
|
|
cover_og_quality=arguments.og_cover,
|
2020-12-15 00:48:15 +01:00
|
|
|
)
|
|
|
|
qobuz.initialize_client(email, password, app_id, secrets)
|
2020-12-09 19:52:18 +01:00
|
|
|
|
2020-12-18 02:27:08 +01:00
|
|
|
try:
|
|
|
|
if arguments.command == "dl":
|
|
|
|
qobuz.download_list_of_urls(arguments.SOURCE)
|
|
|
|
elif arguments.command == "lucky":
|
|
|
|
query = " ".join(arguments.QUERY)
|
|
|
|
qobuz.lucky_type = arguments.type
|
|
|
|
qobuz.lucky_limit = arguments.number
|
|
|
|
qobuz.lucky_mode(query)
|
|
|
|
else:
|
|
|
|
qobuz.interactive_limit = arguments.limit
|
|
|
|
qobuz.interactive()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
logging.info(
|
|
|
|
f"{RED}Interrupted by user\n{MAGENTA}Already downloaded items will "
|
|
|
|
"be skipped if you try to download the same releases again"
|
|
|
|
)
|
2020-12-07 20:58:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|