Skip to content

Commit

Permalink
start implementation of aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
g0ldyy committed Nov 19, 2024
1 parent eab4465 commit 7207237
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion comet/api/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions comet/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand Down Expand Up @@ -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()}

0 comments on commit 7207237

Please sign in to comment.