feat: added color to couple error cases

This commit is contained in:
Hazel 2024-01-16 11:09:01 +01:00
parent 2c504d3123
commit 206899e48a
3 changed files with 16 additions and 14 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)