2021-12-15 15:15:16 +01:00
|
|
|
import sys
|
2021-11-19 18:45:04 +01:00
|
|
|
from enum import Enum
|
|
|
|
from tqdm import tqdm
|
|
|
|
|
2021-12-15 14:16:30 +01:00
|
|
|
from config import *
|
2021-11-19 18:45:04 +01:00
|
|
|
from zspotify import ZSpotify
|
|
|
|
|
|
|
|
|
|
|
|
class PrintChannel(Enum):
|
|
|
|
SPLASH = PRINT_SPLASH
|
|
|
|
SKIPS = PRINT_SKIPS
|
|
|
|
DOWNLOAD_PROGRESS = PRINT_DOWNLOAD_PROGRESS
|
|
|
|
ERRORS = PRINT_ERRORS
|
2021-12-15 15:10:28 +01:00
|
|
|
WARNINGS = PRINT_WARNINGS
|
2021-11-19 18:45:04 +01:00
|
|
|
DOWNLOADS = PRINT_DOWNLOADS
|
2021-12-01 13:48:53 +01:00
|
|
|
API_ERRORS = PRINT_API_ERRORS
|
2021-12-15 14:16:30 +01:00
|
|
|
PROGRESS_INFO = PRINT_PROGRESS_INFO
|
2021-11-19 18:45:04 +01:00
|
|
|
|
|
|
|
|
2021-12-15 15:15:16 +01:00
|
|
|
ERROR_CHANNEL = [PrintChannel.ERRORS, PrintChannel.API_ERRORS]
|
|
|
|
|
|
|
|
|
2021-11-19 18:45:04 +01:00
|
|
|
class Printer:
|
|
|
|
@staticmethod
|
|
|
|
def print(channel: PrintChannel, msg: str) -> None:
|
|
|
|
if ZSpotify.CONFIG.get(channel.value):
|
2021-12-15 15:15:16 +01:00
|
|
|
if channel in ERROR_CHANNEL:
|
|
|
|
print(msg, file=sys.stderr)
|
|
|
|
else:
|
|
|
|
print(msg)
|
2021-11-19 18:45:04 +01:00
|
|
|
|
2021-12-15 14:16:30 +01:00
|
|
|
@staticmethod
|
|
|
|
def print_loader(channel: PrintChannel, msg: str) -> None:
|
|
|
|
if ZSpotify.CONFIG.get(channel.value):
|
|
|
|
print(msg, flush=True, end="")
|
|
|
|
|
2021-11-19 18:45:04 +01:00
|
|
|
@staticmethod
|
|
|
|
def progress(iterable=None, desc=None, total=None, unit='it', disable=False, unit_scale=False, unit_divisor=1000):
|
|
|
|
if not ZSpotify.CONFIG.get(PrintChannel.DOWNLOAD_PROGRESS.value):
|
|
|
|
disable = True
|
|
|
|
return tqdm(iterable=iterable, desc=desc, total=total, disable=disable, unit=unit, unit_scale=unit_scale, unit_divisor=unit_divisor)
|