From 755c4fb8d21e74576aa615c7d84b399ebedeb45a Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Wed, 24 Jul 2024 20:57:18 +0200 Subject: [PATCH] feat: ability to enable/disable title match check (TITLE_MATCH_CHECK env var) --- .env-sample | 1 + comet/api/stream.py | 41 +++++++++++++++++++++-------------------- comet/utils/models.py | 1 + 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.env-sample b/.env-sample index 1b36b8b..5104fda 100644 --- a/.env-sample +++ b/.env-sample @@ -18,3 +18,4 @@ SCRAPE_TORRENTIO=False # scrape Torrentio CUSTOM_HEADER_HTML=None # only set it if you know what it is PROXY_DEBRID_STREAM=False # Proxy Debrid Streams (very useful to use your debrid service on multiple IPs at same time) PROXY_DEBRID_STREAM_PASSWORD=CHANGE_ME # Secret password to enter on configuration page to prevent people from abusing your debrid stream proxy +TITLE_MATCH_CHECK=True # disable if you only use Jackett / Prowlarr / Torrentio and are sure you're only scraping good titles, for example (not at all recommended with Zilean enabled) \ No newline at end of file diff --git a/comet/api/stream.py b/comet/api/stream.py index c1a1d2d..3ccb2d8 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -229,30 +229,31 @@ async def stream(request: Request, b64config: str, type: str, id: str): if len(torrents) == 0: return {"streams": []} - indexed_torrents = [(i, torrents[i]["Title"]) for i in range(len(torrents))] - chunk_size = 50 - chunks = [ - indexed_torrents[i : i + chunk_size] - for i in range(0, len(indexed_torrents), chunk_size) - ] + if settings.TITLE_MATCH_CHECK: + indexed_torrents = [(i, torrents[i]["Title"]) for i in range(len(torrents))] + chunk_size = 50 + chunks = [ + indexed_torrents[i : i + chunk_size] + for i in range(0, len(indexed_torrents), chunk_size) + ] - tasks = [] - for chunk in chunks: - tasks.append(filter(chunk, name)) + tasks = [] + for chunk in chunks: + tasks.append(filter(chunk, name)) - filtered_torrents = await asyncio.gather(*tasks) - index_less = 0 - for result in filtered_torrents: - for filtered in result: - if not filtered[1]: - del torrents[filtered[0] - index_less] - index_less += 1 - continue + filtered_torrents = await asyncio.gather(*tasks) + index_less = 0 + for result in filtered_torrents: + for filtered in result: + if not filtered[1]: + del torrents[filtered[0] - index_less] + index_less += 1 + continue - logger.info(f"{len(torrents)} torrents passed title match check for {log_name}") + logger.info(f"{len(torrents)} torrents passed title match check for {log_name}") - if len(torrents) == 0: - return {"streams": []} + if len(torrents) == 0: + return {"streams": []} tasks = [] for i in range(len(torrents)): diff --git a/comet/utils/models.py b/comet/utils/models.py index e28fe37..91fa816 100644 --- a/comet/utils/models.py +++ b/comet/utils/models.py @@ -30,6 +30,7 @@ class AppSettings(BaseSettings): CUSTOM_HEADER_HTML: Optional[str] = None PROXY_DEBRID_STREAM: Optional[bool] = False PROXY_DEBRID_STREAM_PASSWORD: Optional[str] = "CHANGE_ME" + TITLE_MATCH_CHECK: Optional[bool] = True settings = AppSettings()