Skip to content

Commit

Permalink
Fix download count in log and toast (#592)
Browse files Browse the repository at this point in the history
- Fixed the reported number of downloaded subtitles in the log and displayed as a toast massage
  • Loading branch information
vagabondHustler authored Jan 23, 2024
1 parent 68bcdb0 commit 0eb3859
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/subsearch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, pref_counter: float) -> None:
io_log.stdout.dataclass(VIDEO_FILE, level="debug", print_allowed=False)
io_file_system.create_directory(VIDEO_FILE.file_directory)

self.subtitles_found = 0
self.downloaded_subtitles = 0
self.ran_download_tab = False
self.accepted_subtitles: list[Subtitle] = []
self.rejected_subtitles: list[Subtitle] = []
Expand Down Expand Up @@ -201,14 +201,14 @@ def summary_notification(self, elapsed) -> None:
self.core_state.set_state(self.core_state.state.SUMMARY_TOAST)
elapsed_summary = f"Finished in {elapsed} seconds"
tot_num_of_subtitles = len(self.accepted_subtitles) + len(self.rejected_subtitles)
download_summary = f"Matches found {self.subtitles_found}/{tot_num_of_subtitles}"
if self.subtitles_found > 0:
msg = "Search Succeeded", f"{download_summary}\n{elapsed_summary}"
io_log.stdout(download_summary, hex_color="#a6e3a1")
matches_downloaded = f"Downloaded: {self.downloaded_subtitles}/{tot_num_of_subtitles}"
if self.downloaded_subtitles > 0:
msg = "Search Succeeded", f"{matches_downloaded}\n{elapsed_summary}"
io_log.stdout(matches_downloaded, hex_color="#a6e3a1")
self.system_tray.display_toast(*msg)
elif self.subtitles_found == 0:
msg = "Search Failed", f"{download_summary}\n{elapsed_summary}"
io_log.stdout(download_summary, hex_color="#f38ba8")
elif self.downloaded_subtitles == 0:
msg = "Search Failed", f"{matches_downloaded}\n{elapsed_summary}"
io_log.stdout(matches_downloaded, hex_color="#f38ba8")
self.system_tray.display_toast(*msg)

@decorators.call_func
Expand Down
10 changes: 7 additions & 3 deletions src/subsearch/globals/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ def eval_all_true(conditions: list[bool]) -> bool:
def conditions_met(cls: Union["core.SubsearchCore", "core.Initializer"], *args, **kwargs) -> bool:
if not cls.file_exist:
return False

cfg = cls.app_config
acc_subs = cls.accepted_subtitles
rej_subs = cls.rejected_subtitles

df_senario_1 = not cfg.always_open and not cfg.no_automatic_downloads
df_senario_2 = cfg.always_open and not cfg.no_automatic_downloads

open_dm_senario_1 = len(acc_subs) == 0 and len(rej_subs) >= 1 and cfg.open_on_no_matches
open_dm_senario_2 = len(acc_subs) >= 1 and cfg.always_open and cfg.no_automatic_downloads
open_dm_senario_3 = len(rej_subs) >= 1 and cfg.always_open

func_name = kwargs["func_name"]
conditions: dict[str, list[bool]] = {
"opensubtitles": [
Expand All @@ -106,13 +110,13 @@ def conditions_met(cls: Union["core.SubsearchCore", "core.Initializer"], *args,
"download_manager": [(open_dm_senario_1 or open_dm_senario_2 or open_dm_senario_3)],
"extract_files": [len(cls.accepted_subtitles) >= 1],
"subtitle_post_processing": [],
"subtitle_rename": [cfg.subtitle_post_processing["rename"], cls.subtitles_found >= 1],
"subtitle_rename": [cfg.subtitle_post_processing["rename"], cls.downloaded_subtitles >= 1],
"subtitle_move_best": [
cfg.subtitle_post_processing["move_best"],
cls.subtitles_found >= 1,
cls.downloaded_subtitles >= 1,
not cfg.subtitle_post_processing["move_all"],
],
"subtitle_move_all": [cfg.subtitle_post_processing["move_all"], cls.subtitles_found > 1],
"subtitle_move_all": [cfg.subtitle_post_processing["move_all"], cls.downloaded_subtitles > 1],
"summary_notification": [cfg.summary_notification],
"clean_up": [],
}
Expand Down
8 changes: 4 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self) -> None:
self.provider_urls = globals_test.FAKE_PROVIDER_URLS
self.accepted_subtitles = []
self.rejected_subtitles = []
self.subtitles_found = 0
self.downloaded_subtitles = 0
self.call_func = _CoreSubsearchFuncCondtitons.conditions_met

@property
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_conditions_extract_files(fake_cls: FakeSubsearchCore) -> None:


def test_conditions_subtitle_rename(fake_cls: FakeSubsearchCore) -> None:
fake_cls.subtitles_found = 2
fake_cls.downloaded_subtitles = 2
fake_cls.app_config.subtitle_post_processing["rename"] = True
assert fake_cls.call_func(cls=fake_cls, func_name=fake_cls.func_name) is True

Expand All @@ -115,7 +115,7 @@ def test_conditions_subtitle_rename(fake_cls: FakeSubsearchCore) -> None:


def test_conditions_subtitle_move_best(fake_cls: FakeSubsearchCore) -> None:
fake_cls.subtitles_found = 2
fake_cls.downloaded_subtitles = 2
fake_cls.app_config.subtitle_post_processing["move_best"] = True
assert fake_cls.call_func(cls=fake_cls, func_name=fake_cls.func_name) is True

Expand All @@ -128,7 +128,7 @@ def test_conditions_subtitle_move_best(fake_cls: FakeSubsearchCore) -> None:


def test_conditions_subtitle_move_all(fake_cls: FakeSubsearchCore) -> None:
fake_cls.subtitles_found = 2
fake_cls.downloaded_subtitles = 2
fake_cls.app_config.subtitle_post_processing["move_all"] = True
assert fake_cls.call_func(cls=fake_cls, func_name=fake_cls.func_name) is True

Expand Down

0 comments on commit 0eb3859

Please sign in to comment.