use Printer class for output

- added print-options for API_ERRORS
- modified printing inside of invoke_url
- "No Genre found." is printed using SKIPS
This commit is contained in:
Leon Bohmann 2021-12-01 13:48:53 +01:00
parent 055f7ad97d
commit c9e8c0c45d
4 changed files with 9 additions and 4 deletions

View File

@ -25,6 +25,7 @@ PRINT_SKIPS = 'PRINT_SKIPS'
PRINT_DOWNLOAD_PROGRESS = 'PRINT_DOWNLOAD_PROGRESS' PRINT_DOWNLOAD_PROGRESS = 'PRINT_DOWNLOAD_PROGRESS'
PRINT_ERRORS = 'PRINT_ERRORS' PRINT_ERRORS = 'PRINT_ERRORS'
PRINT_DOWNLOADS = 'PRINT_DOWNLOADS' PRINT_DOWNLOADS = 'PRINT_DOWNLOADS'
PRINT_API_ERRORS = 'PRINT_API_ERRORS'
TEMP_DOWNLOAD_DIR = 'TEMP_DOWNLOAD_DIR' TEMP_DOWNLOAD_DIR = 'TEMP_DOWNLOAD_DIR'
MD_ALLGENRES = 'MD_ALLGENRES' MD_ALLGENRES = 'MD_ALLGENRES'
MD_GENREDELIMITER = 'MD_GENREDELIMITER' MD_GENREDELIMITER = 'MD_GENREDELIMITER'
@ -51,6 +52,7 @@ CONFIG_VALUES = {
PRINT_DOWNLOAD_PROGRESS: { 'default': 'True', 'type': bool, 'arg': '--print-download-progress' }, PRINT_DOWNLOAD_PROGRESS: { 'default': 'True', 'type': bool, 'arg': '--print-download-progress' },
PRINT_ERRORS: { 'default': 'True', 'type': bool, 'arg': '--print-errors' }, PRINT_ERRORS: { 'default': 'True', 'type': bool, 'arg': '--print-errors' },
PRINT_DOWNLOADS: { 'default': 'False', 'type': bool, 'arg': '--print-downloads' }, 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_ALLGENRES: { 'default': 'False', 'type': bool, 'arg': '--md-allgenres' },
MD_GENREDELIMITER: { 'default': ';', 'type': str, 'arg': '--md-genredelimiter' }, MD_GENREDELIMITER: { 'default': ';', 'type': str, 'arg': '--md-genredelimiter' },
TEMP_DOWNLOAD_DIR: { 'default': '', 'type': str, 'arg': '--temp-download-dir' } TEMP_DOWNLOAD_DIR: { 'default': '', 'type': str, 'arg': '--temp-download-dir' }

View File

@ -1,7 +1,7 @@
from enum import Enum from enum import Enum
from tqdm import tqdm 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 from zspotify import ZSpotify
@ -11,6 +11,7 @@ class PrintChannel(Enum):
DOWNLOAD_PROGRESS = PRINT_DOWNLOAD_PROGRESS DOWNLOAD_PROGRESS = PRINT_DOWNLOAD_PROGRESS
ERRORS = PRINT_ERRORS ERRORS = PRINT_ERRORS
DOWNLOADS = PRINT_DOWNLOADS DOWNLOADS = PRINT_DOWNLOADS
API_ERRORS = PRINT_API_ERRORS
class Printer: class Printer:

View File

@ -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]) genres.append(artistInfo[GENRES][0])
if len(genres) == 0: if len(genres) == 0:
Printer.print(PrintChannel.SKIPS, "No Genre found.") Printer.print(PrintChannel.SKIPS, '### No Genre found.')
genres.append('') genres.append('')
album_name = info[TRACKS][0][ALBUM][NAME] album_name = info[TRACKS][0][ALBUM][NAME]

View File

@ -19,7 +19,7 @@ from const import TYPE, \
PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ
from config import Config from config import Config
class ZSpotify: class ZSpotify:
SESSION: Session = None SESSION: Session = None
DOWNLOAD_QUALITY = None DOWNLOAD_QUALITY = None
CONFIG: Config = Config() CONFIG: Config = Config()
@ -82,6 +82,8 @@ class ZSpotify:
@classmethod @classmethod
def invoke_url(cls, url, tryCount = 0): 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() headers = cls.get_auth_header()
response = requests.get(url, headers=headers) response = requests.get(url, headers=headers)
responseText = response.text responseText = response.text
@ -89,7 +91,7 @@ class ZSpotify:
if 'error' in responseJson and tryCount < 20: 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) time.sleep(5)
return cls.invoke_url(url, tryCount + 1) return cls.invoke_url(url, tryCount + 1)