From 75b235e9d8569d26972e44610696900a22921e19 Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:34:57 +0100 Subject: [PATCH 1/2] Revert "Improve title filtering and tv shows results" --- comet/api/stream.py | 7 +++---- comet/utils/general.py | 29 ++--------------------------- pyproject.toml | 1 - 3 files changed, 5 insertions(+), 32 deletions(-) diff --git a/comet/api/stream.py b/comet/api/stream.py index 6dbd6f5..eee5e70 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -120,7 +120,7 @@ async def stream(request: Request, b64config: str, type: str, id: str): name = translate(name) log_name = name if type == "series": - log_name = f"{name} S{season:02d}E{episode:02d}" + log_name = f"{name} S0{season}E0{episode}" if ( settings.PROXY_DEBRID_STREAM @@ -280,10 +280,9 @@ async def stream(request: Request, b64config: str, type: str, id: str): search_terms = [name] if type == "series": - search_terms = [] if not kitsu: - search_terms.append(f"{name} S{season:02d}E{episode:02d}") - search_terms.append(f"{name} s{season:02d}e{episode:02d}") + search_terms.append(f"{name} S0{season}E0{episode}") + search_terms.append(f"{name} s0{season}e0{episode}") else: search_terms.append(f"{name} {episode}") tasks.extend( diff --git a/comet/utils/general.py b/comet/utils/general.py index e7ecd01..4315c4d 100644 --- a/comet/utils/general.py +++ b/comet/utils/general.py @@ -7,10 +7,9 @@ import asyncio import orjson -from RTN import parse +from RTN import parse, title_match from curl_cffi import requests from fastapi import Request -from fuzzywuzzy import fuzz from comet.utils.logger import logger from comet.utils.models import settings, ConfigModel @@ -468,30 +467,6 @@ async def get_mediafusion(log_name: str, type: str, full_id: str): return results -def match_titles(imdb_title: str, torrent_title: str, threshold: int = 80) -> bool: - """ - Match movie/TV show titles using fuzzy string matching. - - Parameters: - imdb_title (str): The title from the IMDB data source. - torrent_title (str): The title from the torrent data source. - threshold (int): The minimum fuzzy match ratio to consider the titles a match. - - Returns: - bool: True if the titles match, False otherwise. - """ - # Calculate the fuzzy match ratio - # The idea is that ratio will give very low score to garbage ratio but will also give mid/average - # score to some good results. The WRatio will make sure these mid score passes the filter. - base_ratio = fuzz.ratio(imdb_title, torrent_title) # strict ratio - w_ratio = fuzz.WRatio(imdb_title, torrent_title) # less strict ratio - # The weight of the ratios needs to be adjusted because basic ratio is too strict. - match_ratio = (base_ratio*0.7 + w_ratio*1.3)/2 - - # Check if the fuzzy match ratio meets the thresholds - return match_ratio >= threshold - - async def filter(torrents: list, name: str, year: int): results = [] for torrent in torrents: @@ -503,7 +478,7 @@ async def filter(torrents: list, name: str, year: int): parsed = parse(title) - if parsed.parsed_title and not match_titles(name, parsed.parsed_title): + if parsed.parsed_title and not title_match(name, parsed.parsed_title): results.append((index, False)) continue diff --git a/pyproject.toml b/pyproject.toml index 64311c2..222dbe4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,6 @@ aiosqlite = "*" jinja2 = "*" rank-torrent-name = "*" parsett = "*" -fuzzywuzzy = {extras = ["speedup"], version = "*"} [tool.poetry.group.dev.dependencies] From eff608823959d2a2c9fa566e4a78edcf35792a24 Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:36:06 +0100 Subject: [PATCH 2/2] Update stream.py --- comet/api/stream.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/comet/api/stream.py b/comet/api/stream.py index eee5e70..25adcbf 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -280,9 +280,10 @@ async def stream(request: Request, b64config: str, type: str, id: str): search_terms = [name] if type == "series": + search_terms = [] if not kitsu: - search_terms.append(f"{name} S0{season}E0{episode}") - search_terms.append(f"{name} s0{season}e0{episode}") + search_terms.append(f"{name} S{season:02d}E{episode:02d}") + search_terms.append(f"{name} s{season:02d}e{episode:02d}") else: search_terms.append(f"{name} {episode}") tasks.extend(