From 9ebcb71ef1cd48ed9ac3079838cf4b2da1575cc2 Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:45:34 +0100 Subject: [PATCH 01/16] feat: ability to disable max connection --- comet/api/stream.py | 1 + 1 file changed, 1 insertion(+) diff --git a/comet/api/stream.py b/comet/api/stream.py index b546314..cdf8450 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -608,6 +608,7 @@ async def playback(request: Request, b64config: str, hash: str, index: str): connection["ip"] == ip and connection["connections"] >= settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS + and settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS != -1 for connection in active_ip_connections ): return FileResponse("comet/assets/proxylimit.mp4") From 412699fb55a77069ef17c0e5f826d87cca2d7c8d Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:46:12 +0100 Subject: [PATCH 02/16] feat: ability to disable max connection #2 --- .env-sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env-sample b/.env-sample index 6514472..d1f84ee 100644 --- a/.env-sample +++ b/.env-sample @@ -22,7 +22,7 @@ SCRAPE_MEDIAFUSION=False # scrape MediaFusion - has better results for Indian co MEDIAFUSION_URL=https://mediafusion.elfhosted.com # Allows you to scrape custom instances of MediaFusion 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 -PROXY_DEBRID_STREAM_MAX_CONNECTIONS=100 # IP-Based connection limit for the Debrid Stream Proxy +PROXY_DEBRID_STREAM_MAX_CONNECTIONS=-1 # IP-Based connection limit for the Debrid Stream Proxy (-1 = disabled) PROXY_DEBRID_STREAM_DEBRID_DEFAULT_SERVICE=realdebrid # if you want your users who use the Debrid Stream Proxy not to have to specify Debrid information, but to use the default one instead PROXY_DEBRID_STREAM_DEBRID_DEFAULT_APIKEY=CHANGE_ME # if you want your users who use the Debrid Stream Proxy not to have to specify Debrid information, but to use the default one instead TITLE_MATCH_CHECK=True # disable if you only use Torrentio / MediaFusion and are sure you're only scraping good titles, for example (keep it True if Zilean is enabled) From 05fe06294b0471a2cd8e7cfb3c3b96a9863e1f6a Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:46:43 +0100 Subject: [PATCH 03/16] feat: ability to disable max connection #3 --- comet/utils/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comet/utils/models.py b/comet/utils/models.py index 7d21de4..d601e67 100644 --- a/comet/utils/models.py +++ b/comet/utils/models.py @@ -37,7 +37,7 @@ class AppSettings(BaseSettings): CUSTOM_HEADER_HTML: Optional[str] = None PROXY_DEBRID_STREAM: Optional[bool] = False PROXY_DEBRID_STREAM_PASSWORD: Optional[str] = None - PROXY_DEBRID_STREAM_MAX_CONNECTIONS: Optional[int] = 100 + PROXY_DEBRID_STREAM_MAX_CONNECTIONS: Optional[int] = -1 PROXY_DEBRID_STREAM_DEBRID_DEFAULT_SERVICE: Optional[str] = "realdebrid" PROXY_DEBRID_STREAM_DEBRID_DEFAULT_APIKEY: Optional[str] = None TITLE_MATCH_CHECK: Optional[bool] = True From a18dceb01c49f4a0fee50b3afda11b5008da3085 Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:48:14 +0100 Subject: [PATCH 04/16] feat: ability to disable max connection #4 --- comet/api/stream.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/comet/api/stream.py b/comet/api/stream.py index cdf8450..28e8960 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -601,17 +601,17 @@ async def playback(request: Request, b64config: str, hash: str, index: str): and settings.PROXY_DEBRID_STREAM_PASSWORD == config["debridStreamProxyPassword"] ): - active_ip_connections = await database.fetch_all( - "SELECT ip, COUNT(*) as connections FROM active_connections GROUP BY ip" - ) - if any( - connection["ip"] == ip - and connection["connections"] - >= settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS - and settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS != -1 - for connection in active_ip_connections - ): - return FileResponse("comet/assets/proxylimit.mp4") + if settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS != -1: + active_ip_connections = await database.fetch_all( + "SELECT ip, COUNT(*) as connections FROM active_connections GROUP BY ip" + ) + if any( + connection["ip"] == ip + and connection["connections"] + >= settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS + for connection in active_ip_connections + ): + return FileResponse("comet/assets/proxylimit.mp4") proxy = None From fefc260b083e46ac062ede04abd694c9841f7c42 Mon Sep 17 00:00:00 2001 From: davidemarcoli Date: Sun, 17 Nov 2024 13:55:42 +0100 Subject: [PATCH 05/16] feat: add max results per resolution configuration option --- comet/templates/index.html | 7 +++++++ comet/utils/general.py | 7 +++++-- comet/utils/models.py | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/comet/templates/index.html b/comet/templates/index.html index 76f63c6..8cf5594 100644 --- a/comet/templates/index.html +++ b/comet/templates/index.html @@ -527,6 +527,10 @@ +
+ +
+
@@ -710,6 +714,7 @@ const languages = Array.from(document.getElementById("languages").selectedOptions).map(option => option.value); const resolutions = Array.from(document.getElementById("resolutions").selectedOptions).map(option => option.value); const maxResults = document.getElementById("maxResults").value; + const maxResultsPerResolution = document.getElementById("maxResultsPerResolution").value; const maxSize = document.getElementById("maxSize").value; const resultFormat = Array.from(document.getElementById("resultFormat").selectedOptions).map(option => option.value); const debridService = document.getElementById("debridService").value; @@ -722,6 +727,7 @@ return { indexers: indexers, maxResults: parseInt(maxResults), + maxResultsPerResolution: parseInt(maxResultsPerResolution), maxSize: parseFloat(maxSize * 1073741824), resultFormat: selectedResultFormat, resolutions: selectedResolutions, @@ -774,6 +780,7 @@ function populateFormFromSettings(settings) { document.getElementById("maxResults").value = settings.maxResults; + document.getElementById("maxResultsPerResolution").value = settings.maxResultsPerResolution; document.getElementById("maxSize").value = settings.maxSize / 1073741824; // Convert back from bytes to GB document.getElementById("debridService").value = settings.debridService; document.getElementById("debridApiKey").value = settings.debridApiKey; diff --git a/comet/utils/general.py b/comet/utils/general.py index c4c02d8..a1fbca3 100644 --- a/comet/utils/general.py +++ b/comet/utils/general.py @@ -528,6 +528,7 @@ async def get_torrent_hash(session: aiohttp.ClientSession, torrent: tuple): def get_balanced_hashes(hashes: dict, config: dict): max_results = config["maxResults"] + max_results_per_resolution = config.get("maxResultsPerResolution", 0) max_size = config["maxSize"] config_resolutions = [resolution.lower() for resolution in config["resolutions"]] @@ -565,15 +566,17 @@ def get_balanced_hashes(hashes: dict, config: dict): hashes_by_resolution[resolution].append(hash) total_resolutions = len(hashes_by_resolution) - if max_results == 0 or total_resolutions == 0: + if max_results == 0 and max_results_per_resolution == 0 or total_resolutions == 0: return hashes_by_resolution - hashes_per_resolution = max_results // total_resolutions + hashes_per_resolution = max_results // total_resolutions if max_results > 0 else max_results_per_resolution extra_hashes = max_results % total_resolutions balanced_hashes = {} for resolution, hash_list in hashes_by_resolution.items(): selected_count = hashes_per_resolution + (1 if extra_hashes > 0 else 0) + if max_results_per_resolution > 0: + selected_count = min(selected_count, max_results_per_resolution) balanced_hashes[resolution] = hash_list[:selected_count] if extra_hashes > 0: extra_hashes -= 1 diff --git a/comet/utils/models.py b/comet/utils/models.py index d601e67..1032123 100644 --- a/comet/utils/models.py +++ b/comet/utils/models.py @@ -70,6 +70,7 @@ class ConfigModel(BaseModel): resolutions: Optional[List[str]] = ["All"] resultFormat: Optional[List[str]] = ["All"] maxResults: Optional[int] = 0 + maxResultsPerResolution: Optional[int] = 0 maxSize: Optional[float] = 0 debridService: str debridApiKey: str @@ -95,6 +96,12 @@ class ConfigModel(BaseModel): if v < 0: v = 0 return v + + @field_validator("maxResultsPerResolution") + def check_max_results_per_resolution(cls, v): + if v < 0: + v = 0 + return v @field_validator("maxSize") def check_max_size(cls, v): From 58669dba3e4231cb1eee1982aae5caff6f2be1e3 Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Sun, 17 Nov 2024 14:21:50 +0100 Subject: [PATCH 06/16] .get() not needed as config is already validated by pydantic so it is 0 by default even if not defined by user --- comet/utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comet/utils/general.py b/comet/utils/general.py index a1fbca3..1a6ef02 100644 --- a/comet/utils/general.py +++ b/comet/utils/general.py @@ -528,7 +528,7 @@ async def get_torrent_hash(session: aiohttp.ClientSession, torrent: tuple): def get_balanced_hashes(hashes: dict, config: dict): max_results = config["maxResults"] - max_results_per_resolution = config.get("maxResultsPerResolution", 0) + max_results_per_resolution = config["maxResultsPerResolution"] max_size = config["maxSize"] config_resolutions = [resolution.lower() for resolution in config["resolutions"]] From ba4e17688100ec0e59ff073d8fdaa461f9f0b426 Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Sun, 17 Nov 2024 18:07:35 +0100 Subject: [PATCH 07/16] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 222dbe4..683451b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ orjson = "*" asyncpg = "*" aiosqlite = "*" jinja2 = "*" -rank-torrent-name = "*" +rank-torrent-name = "1.4.1" parsett = "*" From 5ca4aa59a0b704f77ab45190f2e03fc83e75023e Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Sun, 17 Nov 2024 22:24:33 +0100 Subject: [PATCH 08/16] fix: fix 2160p issue --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 683451b..69a4cc9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ orjson = "*" asyncpg = "*" aiosqlite = "*" jinja2 = "*" -rank-torrent-name = "1.4.1" +rank-torrent-name = "1.2.3" parsett = "*" From 6f7c79f91dffabd28bcce667be6c72837711414b Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Sun, 17 Nov 2024 22:58:07 +0100 Subject: [PATCH 09/16] feat: language unknown support --- comet/api/core.py | 3 ++- comet/api/stream.py | 19 ++++++++++--------- comet/templates/index.html | 1 + comet/utils/general.py | 8 +++++++- comet/utils/models.py | 2 +- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/comet/api/core.py b/comet/api/core.py index 1c9f7c8..1dabf54 100644 --- a/comet/api/core.py +++ b/comet/api/core.py @@ -24,7 +24,8 @@ async def health(): indexers = settings.INDEXER_MANAGER_INDEXERS languages = [language for language in PTT.parse.LANGUAGES_TRANSLATION_TABLE.values()] -languages.insert(0, "Multi") +languages.insert(0, "Unknown") +languages.insert(1, "Multi") web_config = { "indexers": [indexer.replace(" ", "_").lower() for indexer in indexers], "languages": languages, diff --git a/comet/api/stream.py b/comet/api/stream.py index 28e8960..637e371 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -39,15 +39,16 @@ streams = APIRouter() @streams.get("/stream/{type}/{id}.json") async def stream_noconfig(request: Request, type: str, id: str): - return { - "streams": [ - { - "name": "[⚠️] Comet", - "description": f"{request.url.scheme}://{request.url.netloc}/configure", - "url": "https://comet.fast", - } - ] - } + return { + "streams": [ + { + "name": "[⚠️] Comet", + "description": f"{request.url.scheme}://{request.url.netloc}/configure", + "url": "https://comet.fast", + } + ] + } + @streams.get("/{b64config}/stream/{type}/{id}.json") async def stream(request: Request, b64config: str, type: str, id: str): diff --git a/comet/templates/index.html b/comet/templates/index.html index 8cf5594..2178d15 100644 --- a/comet/templates/index.html +++ b/comet/templates/index.html @@ -598,6 +598,7 @@