Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to dev
  • Loading branch information
vagabondHustler committed May 15, 2024
2 parents 08ec5c0 + 445dae1 commit 948d200
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
16 changes: 6 additions & 10 deletions src/subsearch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from subsearch.globals.dataclasses import Subtitle
from subsearch.gui import screen_manager, system_tray
from subsearch.gui.screens import download_manager
from subsearch.providers import opensubtitles, yifysubtitles
from subsearch.providers import opensubtitles, yifysubtitles
from subsearch.utils import io_file_system, io_toml, string_parser


Expand Down Expand Up @@ -102,24 +102,20 @@ def _create_threads(self, *tasks) -> None:
task_thread.start()
task_thread.join()

def start_search(self, provider, flag: str = "") -> None:
def _start_search(self, provider, flag: str) -> None:
search_provider = provider(**self.search_kwargs)
if flag:
search_provider.start_search(flag=flag)
else:
search_provider.start_search()
search_provider.start_search(flag=flag)
self.accepted_subtitles.extend(search_provider.accepted_subtitles)
self.rejected_subtitles.extend(search_provider.rejected_subtitles)

@decorators.call_func
def opensubtitles(self) -> None:
self.start_search(provider=opensubtitles.OpenSubtitles, flag="hash")
self.start_search(provider=opensubtitles.OpenSubtitles, flag="site")

self._start_search(provider=opensubtitles.OpenSubtitles, flag="hash")
self._start_search(provider=opensubtitles.OpenSubtitles, flag="site")

@decorators.call_func
def yifysubtitles(self) -> None:
self.start_search(provider=yifysubtitles.YifiSubtitles)
self._start_search(provider=yifysubtitles.YifiSubtitles, flag="site")

@decorators.call_func
def download_files(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/subsearch/globals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from ._logging import StdoutHandler
from ._logging import Logger

log = StdoutHandler()
log = Logger()
15 changes: 7 additions & 8 deletions src/subsearch/globals/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import threading
from datetime import datetime
from pathlib import Path
from typing import Optional, TypeVar
from typing import Callable, Optional

import picologging as logging

from subsearch.globals import metaclasses
from subsearch.globals.constants import APP_PATHS, FILE_PATHS
from subsearch.globals.dataclasses import GenericDataClass

DATACLASS = TypeVar("DATACLASS")


def capture_call_info(func):
def capture_call_info(func) -> Callable[..., None]:
def wrapper(*args, **kwargs):
frame = inspect.currentframe().f_back # type: ignore
current_time = datetime.now().time()
Expand All @@ -36,7 +35,7 @@ class ANSIEscapeSequences:
UNDERLINE = "\033[4m"


class Logger(metaclass=metaclasses.Singleton):
class _Logging(metaclass=metaclasses.Singleton):
def __init__(self, *args, **kwargs) -> None:
self.logger_name = kwargs.get("logger_name", "subsearch")
if not APP_PATHS.appdata_subsearch.exists():
Expand Down Expand Up @@ -98,9 +97,9 @@ def _color_print(self, message: str, hex_color: str, style: str) -> None:
print(f"{style_code}{color_code}{message}{self._ansi.RESET}")


class StdoutHandler(metaclass=metaclasses.Singleton):
class Logger(metaclass=metaclasses.Singleton):
def __init__(self) -> None:
self._logger = Logger()
self._logger = _Logging()

def __call__(self, message: str, **kwargs) -> None:
self.log(message, **kwargs)
Expand Down Expand Up @@ -153,7 +152,7 @@ def file_system_action(self, action_type: str, src: Path, dst: Optional[Path] =
self(message, **kwargs)

@capture_call_info
def dataclass(self, instance: DATACLASS, **kwargs) -> None:
def dataclass(self, instance: GenericDataClass, **kwargs) -> None:
if not dataclasses.is_dataclass(instance):
raise ValueError("Input is not a dataclass instance.")
instance_name = f"--- [{instance.__class__.__name__}] ---"
Expand Down
8 changes: 6 additions & 2 deletions src/subsearch/globals/dataclasses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from dataclasses import Field, dataclass
from pathlib import Path
from typing import Any
from typing import Any, ClassVar, Protocol


@dataclass(order=True)
Expand Down Expand Up @@ -112,3 +112,7 @@ class WindowsRegistryPaths:
shell: str
subsearch: str
subsearch_command: str


class GenericDataClass(Protocol):
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
2 changes: 1 addition & 1 deletion src/subsearch/providers/yifysubtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, **kwargs) -> None:
YifySubtitlesScraper.__init__(self, **kwargs)
self.provider_name = self.__class__.__name__.lower()

def start_search(self) -> list[Subtitle] | None:
def start_search(self, **kwargs) -> list[Subtitle] | None:
subtitle_data = self.get_subtitle(self.url_yifysubtitles, self.current_language, self.hi_sub, self.non_hi_sub)

if not subtitle_data:
Expand Down

0 comments on commit 948d200

Please sign in to comment.