termoutput.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import sys
  2. from enum import Enum
  3. from tqdm import tqdm
  4. from config import *
  5. from zspotify import ZSpotify
  6. class PrintChannel(Enum):
  7. SPLASH = PRINT_SPLASH
  8. SKIPS = PRINT_SKIPS
  9. DOWNLOAD_PROGRESS = PRINT_DOWNLOAD_PROGRESS
  10. ERRORS = PRINT_ERRORS
  11. WARNINGS = PRINT_WARNINGS
  12. DOWNLOADS = PRINT_DOWNLOADS
  13. API_ERRORS = PRINT_API_ERRORS
  14. PROGRESS_INFO = PRINT_PROGRESS_INFO
  15. ERROR_CHANNEL = [PrintChannel.ERRORS, PrintChannel.API_ERRORS]
  16. class Printer:
  17. @staticmethod
  18. def print(channel: PrintChannel, msg: str) -> None:
  19. if ZSpotify.CONFIG.get(channel.value):
  20. if channel in ERROR_CHANNEL:
  21. print(msg, file=sys.stderr)
  22. else:
  23. print(msg)
  24. @staticmethod
  25. def print_loader(channel: PrintChannel, msg: str) -> None:
  26. if ZSpotify.CONFIG.get(channel.value):
  27. print(msg, flush=True, end="")
  28. @staticmethod
  29. def progress(iterable=None, desc=None, total=None, unit='it', disable=False, unit_scale=False, unit_divisor=1000):
  30. if not ZSpotify.CONFIG.get(PrintChannel.DOWNLOAD_PROGRESS.value):
  31. disable = True
  32. return tqdm(iterable=iterable, desc=desc, total=total, disable=disable, unit=unit, unit_scale=unit_scale, unit_divisor=unit_divisor)