| … | … | @@ -429,3 +429,58 @@ class TestIdentFromOriginalId: |
| 429 | 429 | with patch("lib.clients.subtitle.submanager.get_setting", _settings()): |
| 430 | 430 | m.fetch_subtitles(folder_path=str(tmp_path)) |
| 431 | 431 | assert m.wyzie_client.get_subtitles.call_args[0][1] == "kitsu:anime-42" |
| 432 | |
| 433 | |
| 434 | class TestCachedSubtitlesAreReusedSilently: |
| 435 | """A populated cache must not turn every replay into a modal prompt. |
| 436 | |
| 437 | The "use existing subtitles?" dialog was nearly unreachable before: the |
| 438 | OpenSubtitles path needed an imdb id and shipped disabled, so the cache was |
| 439 | usually empty. Wyzie writes ~32 files on the FIRST play of every title, so |
| 440 | without this every subsequent play of anything stops on a yes/no box. |
| 441 | |
| 442 | Reusing them is also the right answer on the merits: wyzie returns every |
| 443 | language it has, so "download them again" cannot produce anything the cache |
| 444 | does not already hold. |
| 445 | """ |
| 446 | |
| 447 | def _cache(self, tmp_path, n=3): |
| 448 | for name in ("English", "French", "German")[:n]: |
| 449 | (tmp_path / (name + ".srt")).write_text("1\n00:00:01,000 --> 00:00:02,000\nx\n") |
| 450 | return sorted(str(p) for p in tmp_path.glob("*.srt")) |
| 451 | |
| 452 | def test_cached_files_are_returned_without_a_dialog(self, tmp_path): |
| 453 | cached = self._cache(tmp_path) |
| 454 | m = _manager() |
| 455 | m.wyzie_client.get_subtitles = MagicMock() |
| 456 | with patch("lib.clients.subtitle.submanager.get_setting", _settings()), \ |
| 457 | patch("lib.clients.subtitle.submanager.xbmcgui") as gui: |
| 458 | got = m.fetch_subtitles(folder_path=str(tmp_path)) |
| 459 | assert sorted(got) == cached |
| 460 | gui.Dialog.assert_not_called() |
| 461 | m.wyzie_client.get_subtitles.assert_not_called() |
| 462 | |
| 463 | def test_the_dialog_still_appears_when_wyzie_is_off(self, tmp_path): |
| 464 | """Without wyzie the cache came from OpenSubtitles, where re-downloading |
| 465 | genuinely can produce a different (better) subtitle -- so the choice |
| 466 | still belongs to the user there.""" |
| 467 | self._cache(tmp_path) |
| 468 | m = _manager() |
| 469 | m.opensub_client.get_subtitles = MagicMock(return_value=None) |
| 470 | with patch("lib.clients.subtitle.submanager.get_setting", |
| 471 | _settings(wyzie_subtitle_enabled=False, |
| 472 | stremio_subtitle_enabled=True)), \ |
| 473 | patch("lib.clients.subtitle.submanager.xbmcgui") as gui: |
| 474 | gui.Dialog.return_value.yesno.return_value = False |
| 475 | m.fetch_subtitles(folder_path=str(tmp_path)) |
| 476 | gui.Dialog.assert_called() |
| 477 | |
| 478 | def test_an_empty_cache_still_goes_to_wyzie(self, tmp_path): |
| 479 | m = _manager() |
| 480 | m.wyzie_client.get_subtitles = MagicMock(return_value=TRACKS) |
| 481 | m.wyzie_client.download_subtitles_batch = MagicMock(return_value=["/a.srt"]) |
| 482 | with patch("lib.clients.subtitle.submanager.get_setting", _settings()), \ |
| 483 | patch("lib.clients.subtitle.submanager.xbmcgui") as gui: |
| 484 | got = m.fetch_subtitles(folder_path=str(tmp_path)) |
| 485 | assert got == ["/a.srt"] |
| 486 | gui.Dialog.assert_not_called() |