diff options
author | Vitiko <[email protected]> | 2022-05-03 23:38:55 -0400 |
---|---|---|
committer | Vitiko <[email protected]> | 2022-05-03 23:38:55 -0400 |
commit | ce33b4f5fd75450bbd54351c712b87dfe915bb29 (patch) | |
tree | 05d7fdb8164ad8b7b6e9edc1f5ff25dd7fd9cf68 | |
parent | 7423c80a28b894812b121a89f38d045f7c87d5ca (diff) | |
download | bazarr-1.0.5-beta.2.tar.gz bazarr-1.0.5-beta.2.zip |
Improve subtitles pack extractionv1.0.5-beta.2
-rw-r--r-- | libs/subliminal_patch/providers/utils.py | 18 | ||||
-rw-r--r-- | tests/subliminal_patch/test_utils.py | 2 |
2 files changed, 11 insertions, 9 deletions
diff --git a/libs/subliminal_patch/providers/utils.py b/libs/subliminal_patch/providers/utils.py index 204fc8e80..42b3ca4e5 100644 --- a/libs/subliminal_patch/providers/utils.py +++ b/libs/subliminal_patch/providers/utils.py @@ -20,27 +20,29 @@ logger = logging.getLogger(__name__) def _get_matching_sub(sub_names, forced=False, episode=None): matching_sub = None - for sub_name in sub_names: - guess = guessit(sub_name, options={"single_value": True}) - is_movie = not guess.get("episode") or not episode + guess_options = {"single_value": True} + if episode is not None: + guess_options["type"] = "episode" # type: ignore + + for sub_name in sub_names: if not forced and os.path.splitext(sub_name.lower())[0].endswith("forced"): logger.debug("Ignoring forced subtitle: %s", sub_name) continue # If it's a movie then get the first subtitle - if is_movie: + if episode is None: logger.debug("Movie subtitle found: %s", sub_name) matching_sub = sub_name break - # Get episode info - guess_episode = guess.get("episode") - if guess_episode is None: + guess = guessit(sub_name, options=guess_options) + + if guess.get("episode") is None: logger.debug("No episode info found in file: %s", sub_name) continue - if episode == guess_episode: + if episode == guess["episode"]: logger.debug("Episode matched: %s", sub_name) matching_sub = sub_name break diff --git a/tests/subliminal_patch/test_utils.py b/tests/subliminal_patch/test_utils.py index 2b89cee5e..de082a0bc 100644 --- a/tests/subliminal_patch/test_utils.py +++ b/tests/subliminal_patch/test_utils.py @@ -19,7 +19,7 @@ from rarfile import RarFile 1, "breaking.bad.s01e01.srt", ), - (("dummy.forced.srt",), True, 1, "dummy.forced.srt"), + (("dummy.forced.srt",), True, None, "dummy.forced.srt"), (("dummy.forced.srt",), False, 1, None), ], ) |