diff options
author | Vitiko <[email protected]> | 2022-04-18 20:12:07 -0400 |
---|---|---|
committer | Vitiko <[email protected]> | 2022-04-18 20:12:07 -0400 |
commit | a95086555f0c799fc9072fe6a82b5141d533486a (patch) | |
tree | 1db492e8bd7a841c610ffd509ed70afc63cc5e32 | |
parent | d95d6b9d357541fccfd75011994e3983bc43a71e (diff) | |
download | bazarr-a95086555f0c799fc9072fe6a82b5141d533486a.tar.gz bazarr-a95086555f0c799fc9072fe6a82b5141d533486a.zip |
no log: add update_matches() providers util
-rw-r--r-- | libs/subliminal_patch/providers/utils.py | 17 | ||||
-rw-r--r-- | tests/subliminal_patch/test_utils.py | 8 |
2 files changed, 25 insertions, 0 deletions
diff --git a/libs/subliminal_patch/providers/utils.py b/libs/subliminal_patch/providers/utils.py index a50f60401..204fc8e80 100644 --- a/libs/subliminal_patch/providers/utils.py +++ b/libs/subliminal_patch/providers/utils.py @@ -9,8 +9,12 @@ from guessit import guessit from subliminal.subtitle import fix_line_ending +from subliminal_patch.core import Episode +from subliminal_patch.subtitle import guess_matches + from ._agent_list import FIRST_THOUSAND_OR_SO_USER_AGENTS + logger = logging.getLogger(__name__) @@ -90,3 +94,16 @@ def get_archive_from_bytes(content: bytes): logger.debug("Unknown compression format") return None + + +def update_matches(matches, video, release_info: str, **guessit_options): + "Update matches set from release info string. New lines are iterated." + guessit_options["type"] = "episode" if isinstance(video, Episode) else "movie" + logger.debug("Guessit options to update matches: %s", guessit_options) + + for release in release_info.split("\n"): + logger.debug("Updating matches from release info: %s", release) + matches |= guess_matches(video, guessit(release.strip(), guessit_options)) + logger.debug("New matches: %s", matches) + + return matches diff --git a/tests/subliminal_patch/test_utils.py b/tests/subliminal_patch/test_utils.py index 2a484660a..2b89cee5e 100644 --- a/tests/subliminal_patch/test_utils.py +++ b/tests/subliminal_patch/test_utils.py @@ -45,3 +45,11 @@ def test_get_archive_from_bytes_zip(data, filename): def test_get_archive_from_bytes_none(): assert utils.get_archive_from_bytes(bytes()) is None + + +def test_update_matches(movies): + matches = set() + utils.update_matches( + matches, movies["dune"], "Subs for dune 2021 bluray x264\nDune webrip x264" + ) + assert "source" in matches |