From 206899e48a2816a87dd1f84d7f7a3dfbd3195125 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Tue, 16 Jan 2024 11:09:01 +0100 Subject: [PATCH] feat: added color to couple error cases --- src/music_kraken/__init__.py | 3 ++- src/music_kraken/cli/main_downloader.py | 11 ++++++----- .../utils/support_classes/download_result.py | 16 ++++++++-------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index 8eb5e9b..5a32f8d 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -7,7 +7,8 @@ from .utils.config import logging_settings, main_settings, read_config read_config() from . import cli -if True: + +if DEBUG: import sys sys.setrecursionlimit(100) diff --git a/src/music_kraken/cli/main_downloader.py b/src/music_kraken/cli/main_downloader.py index a7bf5a4..ce048ca 100644 --- a/src/music_kraken/cli/main_downloader.py +++ b/src/music_kraken/cli/main_downloader.py @@ -1,3 +1,4 @@ +import random from typing import Set, Type, Dict, List from pathlib import Path import re @@ -134,7 +135,7 @@ def get_genre(): def help_message(): print() - print(main_settings["happy_messages"]) + print(random.choice(main_settings["happy_messages"])) print() @@ -173,7 +174,7 @@ class Downloader: page_count = 0 for option in self.current_results.formated_generator(max_items_per_page=self.max_displayed_options): if isinstance(option, Option): - color = BColors.BOLD if self.pages.is_downloadable(option.music_object) else BColors.ENDC + color = BColors.BOLD if self.pages.is_downloadable(option.music_object) else BColors.GREY print(f"{color}{option.index:0{self.option_digits}} {option.music_object.option_string}{BColors.ENDC}") else: prefix = ALPHABET[page_count % len(ALPHABET)] @@ -378,7 +379,7 @@ class Downloader: return False if processed_input != "help": - print("Invalid input.") + print(f"{BColors.WARNING}Invalid input.{BColors.ENDC}") help_message() return False @@ -401,9 +402,9 @@ def download( if code == 0: main_settings["hasnt_yet_started"] = False write_config() - print("Restart the programm to use it.") + print(f"{BColors.OKGREEN}Restart the programm to use it.{BColors.ENDC}") else: - print("Something went wrong configuring.") + print(f"{BColors.FAIL}Something went wrong configuring.{BColors.ENDC}") shell = Downloader(genre=genre, process_metadata_anyway=process_metadata_anyway) diff --git a/src/music_kraken/utils/support_classes/download_result.py b/src/music_kraken/utils/support_classes/download_result.py index 11f3417..7180b12 100644 --- a/src/music_kraken/utils/support_classes/download_result.py +++ b/src/music_kraken/utils/support_classes/download_result.py @@ -2,12 +2,12 @@ from dataclasses import dataclass, field from typing import List, Tuple from ...utils.config import main_settings, logging_settings +from ...utils.enums.colors import BColors from ...objects import Target UNIT_PREFIXES: List[str] = ["", "k", "m", "g", "t"] UNIT_DIVISOR = 1024 - LOGGER = logging_settings["download_logger"] @@ -83,16 +83,16 @@ class DownloadResult: def __str__(self): if self.is_fatal_error: return self.error_message - head = f"{self.fail} from {self.total} downloads failed:\n" \ - f"successrate:\t{int(self.success_percentage * 100)}%\n" \ - f"failrate:\t{int(self.failure_percentage * 100)}%\n" \ - f"total size:\t{self.formated_size}\n" \ - f"skipped segments:\t{self.sponsor_segments}\n" \ - f"found on disc:\t{self.found_on_disk}" + head = f"{self.fail} from {self.total} downloads failed:\n" \ + f"success-rate:\t{int(self.success_percentage * 100)}%\n" \ + f"fail-rate:\t{int(self.failure_percentage * 100)}%\n" \ + f"total size:\t{self.formated_size}\n" \ + f"skipped segments:\t{self.sponsor_segments}\n" \ + f"found on disc:\t{self.found_on_disk}" if not self.is_mild_failure: return head _lines = [head] - _lines.extend(self._error_message_list) + _lines.extend(BColors.FAIL + s + BColors.ENDC for s in self._error_message_list) return "\n".join(_lines)