diff --git a/comet/api/stream.py b/comet/api/stream.py index 6dbd6f5..0ba9057 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -30,6 +30,7 @@ get_balanced_hashes, format_title, get_client_ip, + get_aliases, ) from comet.utils.logger import logger from comet.utils.models import database, rtn, settings, trackers @@ -341,6 +342,11 @@ async def stream(request: Request, b64config: str, type: str, id: str): return {"streams": []} if settings.TITLE_MATCH_CHECK: + # aliases = await get_aliases( + # session, "movies" if type == "movie" else "series", id + # ) + # print(aliases) + indexed_torrents = [(i, torrents[i]["Title"]) for i in range(len(torrents))] chunk_size = 50 chunks = [ @@ -350,7 +356,7 @@ async def stream(request: Request, b64config: str, type: str, id: str): tasks = [] for chunk in chunks: - tasks.append(filter(chunk, name, year)) + tasks.append(filter(chunk, name, year, {})) filtered_torrents = await asyncio.gather(*tasks) index_less = 0 diff --git a/comet/utils/general.py b/comet/utils/general.py index 4315c4d..caf68ea 100644 --- a/comet/utils/general.py +++ b/comet/utils/general.py @@ -467,7 +467,7 @@ async def get_mediafusion(log_name: str, type: str, full_id: str): return results -async def filter(torrents: list, name: str, year: int): +async def filter(torrents: list, name: str, year: int, aliases: dict): results = [] for torrent in torrents: index = torrent[0] @@ -478,7 +478,9 @@ async def filter(torrents: list, name: str, year: int): parsed = parse(title) - if parsed.parsed_title and not title_match(name, parsed.parsed_title): + if parsed.parsed_title and not title_match( + name, parsed.parsed_title, aliases=aliases + ): results.append((index, False)) continue @@ -668,3 +670,14 @@ def get_client_ip(request: Request): if "cf-connecting-ip" in request.headers else request.client.host ) + + +async def get_aliases(session: aiohttp.ClientSession, media_type: str, media_id: str): + response = await session.get( + f"https://api.trakt.tv/{media_type}/{media_id}/aliases" + ) + + if not response.ok: + return set() + + return {item["title"] for item in response.json()}