Пример #1
0
def main():
    if not os.path.isdir(CONFIG_PATH) or not os.path.isfile(CONFIG_FILE):
        try:
            os.makedirs(CONFIG_PATH, exist_ok=True)
        except FileExistsError:
            pass
        reset_config(CONFIG_FILE)

    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)

    try:
        email = config["DEFAULT"]["email"]
        password = base64.b64decode(config["DEFAULT"]["password"]).decode()
        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
        ]
        arguments = qobuz_dl_args(
            default_quality, default_limit, default_folder
        ).parse_args()
    except (KeyError, UnicodeDecodeError):
        arguments = qobuz_dl_args().parse_args()
        if not arguments.reset:
            print("Your config file is corrupted! Run 'qobuz-dl -r' to fix this\n")
    if arguments.reset:
        sys.exit(reset_config(CONFIG_FILE))

    directory = musicDir(arguments.directory)

    Qz = qopy.Client(email, password, app_id, secrets)

    try:
        quality_str = QUALITIES[int(arguments.quality)]
        print("Quality set: " + quality_str)
    except KeyError:
        sys.exit("Invalid quality!")

    if arguments.command == "fun":
        sys.exit(
            interactive(
                Qz,
                directory,
                arguments.limit,
                not arguments.albums_only,
                arguments.embed_art,
            )
        )
    if arguments.command == "dl":
        for url in arguments.SOURCE:
            if os.path.isfile(url):
                download_by_txt_file(
                    Qz, url, directory, arguments.quality, arguments.embed_art
                )
            else:
                handle_urls(url, Qz, directory, arguments.quality, arguments.embed_art)
    else:
        download_lucky_mode(
            Qz,
            arguments.type,
            " ".join(arguments.QUERY),
            arguments.number,
            directory,
            arguments.quality,
            arguments.embed_art,
        )
Пример #2
0
 def initialize_client(self, email, pwd, app_id, secrets):
     self.client = qopy.Client(email, pwd, app_id, secrets)
     logger.info(
         f"{YELLOW}Set max quality: {QUALITIES[int(self.quality)]}\n")
Пример #3
0
 def initialize_client(self, email, pwd, app_id, secrets):
     self.client = qopy.Client(email, pwd, app_id, secrets)