making simple implementation
This commit is contained in:
commit
219acfaef2
10
main.py
Executable file
10
main.py
Executable file
@ -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()
|
56
qobuzzer.py
Normal file
56
qobuzzer.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user