summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--libs/subliminal_patch/providers/utils.py17
-rw-r--r--tests/subliminal_patch/test_utils.py8
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