Qobuzzer/qobuzzer.py

57 lines
1.9 KiB
Python
Raw Normal View History

2022-11-19 02:12:56 -05:00
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)