From 219acfaef282438762ca414c2b60bba41b60e7a9 Mon Sep 17 00:00:00 2001 From: Michael Scalzetti Date: Sat, 19 Nov 2022 02:12:56 -0500 Subject: [PATCH] making simple implementation --- main.py | 10 ++++++++++ qobuzzer.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100755 main.py create mode 100644 qobuzzer.py diff --git a/main.py b/main.py new file mode 100755 index 0000000..4b26ac7 --- /dev/null +++ b/main.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 + +from qobuzzer import Qobuzzer + +def main(): + qb = Qobuzzer("secrets.json") + qb.download_items_from_file("items.txt") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/qobuzzer.py b/qobuzzer.py new file mode 100644 index 0000000..c1bbd60 --- /dev/null +++ b/qobuzzer.py @@ -0,0 +1,56 @@ +import logging, json +from qobuz_dl.core import QobuzDL +from qobuz_dl.exceptions import AuthenticationError + + +class Qobuzzer: + def __init__(self, email, password, log_level=logging.INFO): + self.__setup_qobuzzer(email, password, log_level=log_level) + self.email = email + self.password = password + + self.qobuz = QobuzDL() + self.qobuz.get_tokens() + self.qobuz.initialize_client(self.email, self.password, + self.qobuz.app_id, self.qobuz.secrets) + + logging.basicConfig(level=log_level) + + + def __init__(self, json_file, log_level=logging.INFO): + with open(json_file, 'r') as file: + data = json.load(file) + + if not "password" in data or not data["password"] == "": + self.__setup_qobuzzer(data["email"], + data["password"], log_level=log_level) + else: + self.__setup_qobuzzer(data["email"], + input("Please enter your password: "), log_level=log_level) + + def __setup_qobuzzer(self, email, password, log_level=logging.INFO): + self.email = email + self.password = password + + self.qobuz = QobuzDL() + self.qobuz.get_tokens() + while True: + try: + self.qobuz.initialize_client(self.email, self.password, + self.qobuz.app_id, self.qobuz.secrets) + break + except AuthenticationError: + self.password = input("Authentication Error\nPlease enter your password: ") + + logging.basicConfig(level=log_level) + + def download_item(self, item_url): + self.qobuz.handle_url(item_url) + + + def download_items(self, item_urls): + self.qobuz.download_list_of_urls(item_urls) + + + def download_items_from_file(self, filename): + self.qobuz.download_from_txt_file(filename)