From 5eaabfc55be7a355311b279c7bf23cc7826ff543 Mon Sep 17 00:00:00 2001 From: vitiko98 Date: Mon, 7 Dec 2020 11:32:37 -0400 Subject: [PATCH] Reverse config.py; formatting --- README.md | 23 +++++++++++---------- config.py | 13 ++++++------ main.py | 8 ++++---- qo_utils/downloader.py | 33 ++++++++++++++++++++++++------- qo_utils/metadata.py | 45 +++++++++++++++++++++++++----------------- qo_utils/qopy.py | 18 +++++++++++------ qo_utils/search.py | 34 +++++++++++++++---------------- requirements.txt | 1 - 8 files changed, 103 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index ddfe786..0e3d171 100644 --- a/README.md +++ b/README.md @@ -27,20 +27,19 @@ pip3 install -r requirements.txt --user pip3 install windows-curses pip3 install -r requirements.txt ``` -#### Add your credentials to a `.env` file -```none -QOBUZ_EMAIL=your@email.com -QOBUZ_PW=your_password +#### Add your credentials to `config.py` file +```python +email = "your@email.com" +password = "your_password" ``` -NB: The .env file should be in the root folder, where main.py and config.py are located. - -In addition to your credentials, you can also use the `.env` file to -change other default values by means of the following environment variables: - - - `QOBUZ_FOLDER` (location of the download folder) - - `QOBUZ_LIMIT` (results limit) - - `QOBUZ_QUALITY` (default quality for url input mode) +In addition to your credentials, you can also use the `config.py` file to +change other default values: +```python +default_folder = "Qobuz Downloads" +default_limit = 10 +default_quality = 6 +``` #### Run qobuz-dl ##### Linux / MAC OS diff --git a/config.py b/config.py index 02cfed8..cdf3e2e 100644 --- a/config.py +++ b/config.py @@ -1,16 +1,15 @@ import os -from dotenv import load_dotenv -load_dotenv() + # Qobuz credentials (Don't remove the quotes!) -email = os.getenv('QOBUZ_EMAIL') -password = os.getenv('QOBUZ_PW') +email = "your@email.com" +password = "your_password" # Default folder where the releases are downloaded -default_folder = os.getenv('QOBUZ_FOLDER', "Qobuz Downloads") +default_folder = "Qobuz Downloads" # Default per type results limit -default_limit = os.getenv('QOBUZ_LIMIT', 10) +default_limit = 10 # Default quality for url input mode. This will be ignored in interactive mode # (5, 6, 7, 27) [320, LOSSLESS, 24B <96KHZ, 24B >96KHZ] -default_quality = os.getenv('QOBUZ_QUALITY', 6) +default_quality = 6 diff --git a/main.py b/main.py index 0e5cd34..43b65f5 100644 --- a/main.py +++ b/main.py @@ -110,12 +110,12 @@ def interactive(Qz, path, limit, tracks=True): while True: query = input("\nEnter your search: [Ctrl + c to quit]\n- ") print("Searching...") - if len(query.strip())==0: + if len(query.strip()) == 0: break start = Search(Qz, query, limit) start.getResults(tracks) - if len(start.Total)==0: - break + if len(start.Total) == 0: + break Types.append(start.Types) IDs.append(start.IDs) @@ -138,7 +138,7 @@ def interactive(Qz, path, limit, tracks=True): else: break - if len(Albums)>0: + if len(Albums) > 0: desc = ( "Select [intro] the quality (the quality will be automat" "ically\ndowngraded if the selected is not found)" diff --git a/qo_utils/downloader.py b/qo_utils/downloader.py index 456369b..a86ce74 100644 --- a/qo_utils/downloader.py +++ b/qo_utils/downloader.py @@ -31,10 +31,17 @@ def mkDir(dirn): def getDesc(u, mt): - return "{}{} [{}/{}]".format(mt["title"],' (' + mt["version"] + ')' if mt["version"] is not None else '', u["bit_depth"], u["sampling_rate"]) + return "{}{} [{}/{}]".format( + mt["title"], + " (" + mt["version"] + ")" if mt["version"] is not None else "", + u["bit_depth"], + u["sampling_rate"], + ) + def getBooklet(i, dirn): - req_tqdm(i, dirn + "/booklet.pdf", "Downloading booklet") + req_tqdm(i, dirn + "/booklet.pdf", "Downloading booklet") + def getCover(i, dirn): req_tqdm(i, dirn + "/cover.jpg", "Downloading cover art") @@ -60,14 +67,19 @@ def iterateIDs(client, id, path, quality, album=False): if album: meta = client.get_album_meta(id) - print("\nDownloading: {0} {1}\n".format(meta["title"], '(' + meta["version"] + ')' if meta["version"] is not None else ' ')) + print( + "\nDownloading: {0} {1}\n".format( + meta["title"], + "(" + meta["version"] + ")" if meta["version"] is not None else " ", + ) + ) dirT = ( meta["artist"]["name"], meta["title"], - ' ' + meta["version"] if meta["version"] is not None else '', + " " + meta["version"] if meta["version"] is not None else "", meta["release_date_original"].split("-")[0], ) - sanitized_title = sanitize_filename("{} - {}{} [{}]".format(*dirT)) #aa-{} + sanitized_title = sanitize_filename("{} - {}{} [{}]".format(*dirT)) # aa-{} dirn = path + sanitized_title mkDir(dirn) getCover(meta["image"]["large"], dirn) @@ -92,11 +104,18 @@ def iterateIDs(client, id, path, quality, album=False): if "sample" not in parse: meta = client.get_track_meta(id) - print("\nDownloading: {0} {1}\n".format(meta["title"], '(' + meta["version"] + ')' if meta["version"] is not None else ' ')) + print( + "\nDownloading: {0} {1}\n".format( + meta["title"], + "(" + meta["version"] + ")" if meta["version"] is not None else " ", + ) + ) dirT = ( meta["album"]["artist"]["name"], meta["album"]["title"], - ' ' + meta["album"]["version"] if meta["album"]["version"] is not None else '', + " " + meta["album"]["version"] + if meta["album"]["version"] is not None + else "", meta["album"]["release_date_original"].split("-")[0], ) sanitized_title = sanitize_filename("{} - {}{} [{}]".format(*dirT)) diff --git a/qo_utils/metadata.py b/qo_utils/metadata.py index 0ac1c1c..bffa6e8 100644 --- a/qo_utils/metadata.py +++ b/qo_utils/metadata.py @@ -4,6 +4,7 @@ from mutagen.flac import FLAC from mutagen.mp3 import EasyMP3 from pathvalidate import sanitize_filename + def tag_flac(file, path, d, album, istrack=True): audio = FLAC(file) try: @@ -13,15 +14,15 @@ def tag_flac(file, path, d, album, istrack=True): dversion_exist = 0 else: if d["version"] is None: - audio["TITLE"] = d["title"]# TRACK TITLE + audio["TITLE"] = d["title"] # TRACK TITLE dversion_exist = 0 else: - audio["TITLE"] = d["title"] + ' ' + '(' + d["version"] + ')' + audio["TITLE"] = d["title"] + " " + "(" + d["version"] + ")" dversion_exist = 1 -# if d["version"] is None: -# audio["TITLE"] = d["title"]# TRACK TITLE -# else: -# audio["TITLE"] = d["title"] + ' ' + '(' + d["version"] + ')' + # if d["version"] is None: + # audio["TITLE"] = d["title"]# TRACK TITLE + # else: + # audio["TITLE"] = d["title"] + ' ' + '(' + d["version"] + ')' audio["TRACKNUMBER"] = str(d["track_number"]) # TRACK NUMBER try: @@ -42,13 +43,15 @@ def tag_flac(file, path, d, album, istrack=True): audio["GENRE"] = ", ".join(d["album"]["genres_list"]) # GENRE audio["ALBUMARTIST"] = d["album"]["artist"]["name"] # ALBUM ARTIST audio["TRACKTOTAL"] = str(d["album"]["tracks_count"]) # TRACK TOTAL - audio["ALBUM"] = d["album"]["title"] # ALBUM TITLE + audio["ALBUM"] = d["album"]["title"] # ALBUM TITLE audio["YEAR"] = d["album"]["release_date_original"].split("-")[0] else: audio["GENRE"] = ", ".join(d["album"]["genres_list"]) # GENRE audio["ALBUMARTIST"] = d["album"]["artist"]["name"] # ALBUM ARTIST audio["TRACKTOTAL"] = str(d["album"]["tracks_count"]) # TRACK TOTAL - audio["ALBUM"] = d["album"]["title"] + ' ' + '(' + d["album"]["version"] + ')' # ALBUM TITLE + audio["ALBUM"] = ( + d["album"]["title"] + " " + "(" + d["album"]["version"] + ")" + ) # ALBUM TITLE audio["YEAR"] = d["album"]["release_date_original"].split("-")[0] else: if dversion_exist == 0: @@ -61,12 +64,14 @@ def tag_flac(file, path, d, album, istrack=True): audio["GENRE"] = ", ".join(album["genres_list"]) # GENRE audio["ALBUMARTIST"] = album["artist"]["name"] # ALBUM ARTIST audio["TRACKTOTAL"] = str(album["tracks_count"]) # TRACK TOTAL - audio["ALBUM"] = album["title"] + ' ' + '(' + album["version"] + ')' # ALBUM TITLE + audio["ALBUM"] = ( + album["title"] + " " + "(" + album["version"] + ")" + ) # ALBUM TITLE audio["YEAR"] = album["release_date_original"].split("-")[0] # YEAR audio.save() - if dversion_exist == 1: - title = sanitize_filename(d["title"] + ' ' + '(' + d["version"] + ')') + if dversion_exist == 1: + title = sanitize_filename(d["title"] + " " + "(" + d["version"] + ")") else: title = sanitize_filename(d["title"]) try: @@ -75,19 +80,19 @@ def tag_flac(file, path, d, album, istrack=True): print("File already exists. Skipping...") -def tag_mp3(file, path, d, album, istrack=True): #needs to be fixed +def tag_mp3(file, path, d, album, istrack=True): # needs to be fixed audio = EasyMP3(file) try: - d["version"] + d["version"] except KeyError: audio["TITLE"] = d["title"] dversion_exist = 0 else: if d["version"] is None: - audio["TITLE"] = d["title"]# TRACK TITLE + audio["TITLE"] = d["title"] # TRACK TITLE dversion_exist = 0 else: - audio["TITLE"] = d["title"] + ' ' + '(' + d["version"] + ')' + audio["TITLE"] = d["title"] + " " + "(" + d["version"] + ")" dversion_exist = 1 audio["tracknumber"] = str(d["track_number"]) @@ -106,7 +111,9 @@ def tag_mp3(file, path, d, album, istrack=True): #needs to be fixed if dversion_exist == 1: audio["genre"] = ", ".join(d["album"]["genres_list"]) # GENRE audio["albumartist"] = d["album"]["artist"]["name"] # ALBUM ARTIST - audio["album"] = d["album"]["title"] + ' ' + '(' + d["album"]["version"] + ')' # ALBUM TITLE + audio["album"] = ( + d["album"]["title"] + " " + "(" + d["album"]["version"] + ")" + ) # ALBUM TITLE audio["date"] = d["album"]["release_date_original"].split("-")[0] else: audio["genre"] = ", ".join(d["album"]["genres_list"]) # GENRE @@ -122,7 +129,9 @@ def tag_mp3(file, path, d, album, istrack=True): #needs to be fixed except KeyError: audio["album"] = album["title"] else: - audio["album"] = album["title"] + ' ' + '(' + album["version"] + ')' # ALBUM TITLE + audio["album"] = ( + album["title"] + " " + "(" + album["version"] + ")" + ) # ALBUM TITLE audio["date"] = album["release_date_original"].split("-")[0] # YEAR else: audio["GENRE"] = ", ".join(album["genres_list"]) # GENRE @@ -132,7 +141,7 @@ def tag_mp3(file, path, d, album, istrack=True): #needs to be fixed audio.save() if dversion_exist == 1: - title = sanitize_filename(d["title"] + ' ' + '(' + d["version"] + ')') + title = sanitize_filename(d["title"] + " " + "(" + d["version"] + ")") else: title = sanitize_filename(d["title"]) try: diff --git a/qo_utils/qopy.py b/qo_utils/qopy.py index 2bba11f..4a26d54 100644 --- a/qo_utils/qopy.py +++ b/qo_utils/qopy.py @@ -91,7 +91,7 @@ class Client: "intent": "stream", } else: - params=kwargs + params = kwargs r = self.session.get(self.base + epoint, params=params) # Do ref header. if epoint == "user/login": @@ -157,13 +157,19 @@ class Client: return self.api_call("track/search", query=query, limit=limit) def get_favorite_albums(self, offset, limit): - return self.api_call("favorite/getUserFavorites", type="albums", offset=offset, limit=limit) - + return self.api_call( + "favorite/getUserFavorites", type="albums", offset=offset, limit=limit + ) + def get_favorite_tracks(self, offset, limit): - return self.api_call("favorite/getUserFavorites", type="tracks", offset=offset, limit=limit) - + return self.api_call( + "favorite/getUserFavorites", type="tracks", offset=offset, limit=limit + ) + def get_favorite_artists(self, offset, limit): - return self.api_call("favorite/getUserFavorites", type="artists", offset=offset, limit=limit) + return self.api_call( + "favorite/getUserFavorites", type="artists", offset=offset, limit=limit + ) def get_user_playlists(self, limit): return self.api_call("playlist/getUserPlaylists", limit=limit) diff --git a/qo_utils/search.py b/qo_utils/search.py index 8c742a7..5c4e375 100644 --- a/qo_utils/search.py +++ b/qo_utils/search.py @@ -28,23 +28,23 @@ class Search: self.Total.append("[RELEASE] {} - {} - {} [{}]".format(*items)) self.appendInfo(i, True) except KeyError: - try: - items = ( - i["performer"]["name"], - i["title"], - self.seconds(i["duration"]), - "HI-RES" if i["hires"] else "Lossless", - ) - self.Total.append("[TRACK] {} - {} - {} [{}]".format(*items)) - self.appendInfo(i, False) - except KeyError: - items = ( - i["title"], - self.seconds(i["duration"]), - "HI-RES" if i["hires"] else "Lossless", - ) - self.Total.append("[TRACK] {} [{}]".format(*items)) - self.appendInfo(i, False) + try: + items = ( + i["performer"]["name"], + i["title"], + self.seconds(i["duration"]), + "HI-RES" if i["hires"] else "Lossless", + ) + self.Total.append("[TRACK] {} - {} - {} [{}]".format(*items)) + self.appendInfo(i, False) + except KeyError: + items = ( + i["title"], + self.seconds(i["duration"]), + "HI-RES" if i["hires"] else "Lossless", + ) + self.Total.append("[TRACK] {} [{}]".format(*items)) + self.appendInfo(i, False) def getResults(self, tracks=False): self.itResults(self.Albums) diff --git a/requirements.txt b/requirements.txt index 53bb471..2b93501 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,3 @@ requests==2.24.0 mutagen==1.45.1 tqdm==4.48.2 pick==0.6.7 -python-dotenv==0.15.0