diff --git a/music_kraken/cli/genre.py b/music_kraken/cli/genre.py index 78b67ef..3580495 100644 --- a/music_kraken/cli/genre.py +++ b/music_kraken/cli/genre.py @@ -1,3 +1,12 @@ +import re +from pathlib import Path +from typing import Dict, Generator, List, Set, Type, Union + +from ..download import Downloader, Page, components +from ..utils.config import main_settings +from .utils import ask_for_bool, cli_function + + class GenreIO(components.HumanIO): @staticmethod def ask_to_create(option: components.Option) -> bool: @@ -42,4 +51,3 @@ def get_genre() -> str: genre = select_genre.choose(input("> ")) return genre.value - \ No newline at end of file diff --git a/music_kraken/download/components/__init__.py b/music_kraken/download/components/__init__.py index 19d5cda..bd93939 100644 --- a/music_kraken/download/components/__init__.py +++ b/music_kraken/download/components/__init__.py @@ -49,6 +49,8 @@ class Option(Generic[P]): for key, value in kwargs.items(): setattr(self, key, value) + super(Option, self).__init__() + def _to_option_string(self, value: Any) -> str: if hasattr(value, "option_string"): return value.option_string @@ -88,6 +90,9 @@ class Option(Generic[P]): def __str__(self): return self.text + def __iter__(self) -> Generator[Option[P], None, None]: + yield self + class Select(Generic[P]): OPTION: Type[Option[P]] = Option @@ -106,6 +111,8 @@ class Select(Generic[P]): self._options: List[Option[P]] = [] self.extend(data) + super(Select, self).__init__(**kwargs) + def append(self, value: P) -> Option[P]: option = self.option(value) self._options.append(option) @@ -126,10 +133,11 @@ class Select(Generic[P]): def __iter__(self) -> Generator[Option, None, None]: _index = 0 - for i, option in enumerate(self._options_to_show): - option.index = _index - yield option - _index += 1 + for i, o in enumerate(self._options_to_show): + for option in o: + option.index = _index + yield option + _index += 1 def __contains__(self, key: Any) -> bool: for option in self._options: @@ -156,3 +164,18 @@ class Select(Generic[P]): def pprint(self) -> str: return "\n".join(str(option) for option in self) + + +class OptionGroup(Option[P], Select[P]): + ALPHABET: str = "abcdefghijklmnopqrstuvwxyz" + ATTRIBUTES_FORMATTING: Tuple[str, ...] = ("alphabetic_index", "value") + + TEXT_TEMPLATE: str = f"{BColors.HEADER.value}{{alphabetic_index}}) {{value}}{BColors.ENDC.value}" + + @property + def alphabetic_index(self) -> str: + return self.ALPHABET[self.index % len(self.ALPHABET)] + + def __init__(self, value: P, data: Generator[P, None, None] **kwargs): + super(OptionGroup, self).__init__(value=value, data=data, **kwargs) +