mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-11-26 09:53:17 +01:00
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:
parent
055f7ad97d
commit
c9e8c0c45d
@ -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' }
|
||||
|
@ -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:
|
||||
|
@ -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]
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user