From c9e8c0c45debae2084a27fb377c8539ec0c50698 Mon Sep 17 00:00:00 2001 From: Leon Bohmann Date: Wed, 1 Dec 2021 13:48:53 +0100 Subject: [PATCH] use Printer class for output - added print-options for API_ERRORS - modified printing inside of invoke_url - "No Genre found." is printed using SKIPS --- zspotify/config.py | 2 ++ zspotify/termoutput.py | 3 ++- zspotify/track.py | 2 +- zspotify/zspotify.py | 6 ++++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/zspotify/config.py b/zspotify/config.py index 0c4e9cf..be8a734 100644 --- a/zspotify/config.py +++ b/zspotify/config.py @@ -25,6 +25,7 @@ PRINT_SKIPS = 'PRINT_SKIPS' PRINT_DOWNLOAD_PROGRESS = 'PRINT_DOWNLOAD_PROGRESS' PRINT_ERRORS = 'PRINT_ERRORS' PRINT_DOWNLOADS = 'PRINT_DOWNLOADS' +PRINT_API_ERRORS = 'PRINT_API_ERRORS' TEMP_DOWNLOAD_DIR = 'TEMP_DOWNLOAD_DIR' MD_ALLGENRES = 'MD_ALLGENRES' MD_GENREDELIMITER = 'MD_GENREDELIMITER' @@ -51,6 +52,7 @@ CONFIG_VALUES = { PRINT_DOWNLOAD_PROGRESS: { 'default': 'True', 'type': bool, 'arg': '--print-download-progress' }, PRINT_ERRORS: { 'default': 'True', 'type': bool, 'arg': '--print-errors' }, PRINT_DOWNLOADS: { 'default': 'False', 'type': bool, 'arg': '--print-downloads' }, + PRINT_API_ERRORS: { 'default': 'False', 'type': bool, 'arg': '--print-api-errors' }, MD_ALLGENRES: { 'default': 'False', 'type': bool, 'arg': '--md-allgenres' }, MD_GENREDELIMITER: { 'default': ';', 'type': str, 'arg': '--md-genredelimiter' }, TEMP_DOWNLOAD_DIR: { 'default': '', 'type': str, 'arg': '--temp-download-dir' } diff --git a/zspotify/termoutput.py b/zspotify/termoutput.py index bf57e35..06eec98 100644 --- a/zspotify/termoutput.py +++ b/zspotify/termoutput.py @@ -1,7 +1,7 @@ from enum import Enum from tqdm import tqdm -from config import PRINT_SPLASH, PRINT_SKIPS, PRINT_DOWNLOAD_PROGRESS, PRINT_ERRORS, PRINT_DOWNLOADS +from config import PRINT_SPLASH, PRINT_SKIPS, PRINT_DOWNLOAD_PROGRESS, PRINT_ERRORS, PRINT_DOWNLOADS, PRINT_API_ERRORS from zspotify import ZSpotify @@ -11,6 +11,7 @@ class PrintChannel(Enum): DOWNLOAD_PROGRESS = PRINT_DOWNLOAD_PROGRESS ERRORS = PRINT_ERRORS DOWNLOADS = PRINT_DOWNLOADS + API_ERRORS = PRINT_API_ERRORS class Printer: diff --git a/zspotify/track.py b/zspotify/track.py index 3fec49a..74704ea 100644 --- a/zspotify/track.py +++ b/zspotify/track.py @@ -59,7 +59,7 @@ def get_song_info(song_id) -> Tuple[List[str], List[str], str, str, Any, Any, An genres.append(artistInfo[GENRES][0]) if len(genres) == 0: - Printer.print(PrintChannel.SKIPS, "No Genre found.") + Printer.print(PrintChannel.SKIPS, '### No Genre found.') genres.append('') album_name = info[TRACKS][0][ALBUM][NAME] diff --git a/zspotify/zspotify.py b/zspotify/zspotify.py index 868e9e2..1738507 100644 --- a/zspotify/zspotify.py +++ b/zspotify/zspotify.py @@ -19,7 +19,7 @@ from const import TYPE, \ PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ from config import Config -class ZSpotify: +class ZSpotify: SESSION: Session = None DOWNLOAD_QUALITY = None CONFIG: Config = Config() @@ -82,6 +82,8 @@ class ZSpotify: @classmethod def invoke_url(cls, url, tryCount = 0): + # we need to import that here, otherwise we will get circular imports! + from termoutput import Printer, PrintChannel headers = cls.get_auth_header() response = requests.get(url, headers=headers) responseText = response.text @@ -89,7 +91,7 @@ class ZSpotify: if 'error' in responseJson and tryCount < 20: - print(f"Spotify API Error ({responseJson['error']['status']}): {responseJson['error']['message']}") + Printer.Print(PrintChannel.API_ERROR, f"Spotify API Error ({responseJson['error']['status']}): {responseJson['error']['message']}") time.sleep(5) return cls.invoke_url(url, tryCount + 1)