diff --git a/comet/api/core.py b/comet/api/core.py index c9243a4..fea17a0 100644 --- a/comet/api/core.py +++ b/comet/api/core.py @@ -59,7 +59,7 @@ async def manifest(b64config: str = None): if not config: config = {"debridService": None} - debrid_extension = get_debrid_extension(config["debridService"]) + debrid_extension = get_debrid_extension(config["debridService"], config["debridApiKey"]) return { "id": settings.ADDON_ID, diff --git a/comet/api/stream.py b/comet/api/stream.py index bab198c..7efb77e 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -465,7 +465,7 @@ async def stream( logger.info(f"Results have been cached for {log_name}") - debrid_extension = get_debrid_extension(config["debridService"]) + debrid_extension = get_debrid_extension(config["debridService"], config["debridApiKey"]) balanced_hashes = get_balanced_hashes(sorted_ranked_files, config) diff --git a/comet/debrid/stremthru.py b/comet/debrid/stremthru.py index ed41c6b..5b58734 100644 --- a/comet/debrid/stremthru.py +++ b/comet/debrid/stremthru.py @@ -20,10 +20,11 @@ class StremThru: if not self.is_supported_store(debrid_service): raise ValueError(f"unsupported store: {debrid_service}") - if debrid_service == "stremthru": + store, token = self.parse_store_creds(debrid_service, token) + if store == "stremthru": session.headers["Proxy-Authorization"] = f"Basic {token}" else: - session.headers["X-StremThru-Store-Name"] = debrid_service + session.headers["X-StremThru-Store-Name"] = store session.headers["X-StremThru-Store-Authorization"] = f"Bearer {token}" session.headers["User-Agent"] = "comet" @@ -33,12 +34,22 @@ class StremThru: self.name = f"StremThru[{debrid_service}]" if debrid_service else "StremThru" self.client_ip = ip + @staticmethod + def parse_store_creds(debrid_service, token: str = ""): + if debrid_service != "stremthru": + return debrid_service, token + if ":" in token: + parts = token.split(":") + return parts[0], parts[1] + return debrid_service, token + @staticmethod def is_supported_store(name: Optional[str]): return ( name == "stremthru" or name == "alldebrid" or name == "debridlink" + or name == "easydebrid" or name == "premiumize" or name == "realdebrid" or name == "torbox" diff --git a/comet/templates/index.html b/comet/templates/index.html index 40d5773..2326ade 100644 --- a/comet/templates/index.html +++ b/comet/templates/index.html @@ -575,6 +575,7 @@ document.getElementById("debridService").addEventListener("sl-change", function(event) { const selectedService = event.target.value; const apiKeyLink = document.getElementById("apiKeyLink"); + const apiKeyInput = document.getElementById("debridApiKey"); if (selectedService === "realdebrid") { apiKeyLink.href = "https://real-debrid.com/apitoken"; @@ -589,6 +590,11 @@ } else if (selectedService === "stremthru") { apiKeyLink.href = "https://github.com/MunifTanjim/stremthru?tab=readme-ov-file#configuration"; } + if (selectedService === "stremthru") { + apiKeyInput.helpText = "Enter Credential ('store_name:store_token' or base64 encoded basic token from 'STREMTHRU_PROXY_AUTH' config)" + } else { + apiKeyInput.helpText = "If no key is specified, you'll get direct torrents!" + } }); diff --git a/comet/utils/config.py b/comet/utils/config.py index 402efa9..c38c7b4 100644 --- a/comet/utils/config.py +++ b/comet/utils/config.py @@ -21,7 +21,11 @@ def should_use_stremthru(config: dict[str, Any]): def should_skip_proxy_stream(config: dict[str, Any]): - return config["stremthruUrl"] and config["debridService"] == "stremthru" + return ( + config["stremthruUrl"] + and config["debridService"] == "stremthru" + and ":" not in config["debridApiKey"] + ) def should_use_fallback_debrid_config(config: dict[str, Any]): @@ -36,8 +40,8 @@ def prepare_debrid_config(config: dict[str, Any]): config["debridService"] = settings.PROXY_DEBRID_STREAM_DEBRID_DEFAULT_SERVICE config["debridApiKey"] = settings.PROXY_DEBRID_STREAM_DEBRID_DEFAULT_APIKEY - if ( - not config["stremthruUrl"] - and config["debridService"] in settings.STREMTHRU_AUTO_ENABLED_DEBRID_SERVICES + if not config["stremthruUrl"] and ( + config["debridService"] == "stremthru" + or config["debridService"] in settings.STREMTHRU_AUTO_ENABLED_DEBRID_SERVICES ): config["stremthruUrl"] = settings.STREMTHRU_DEFAULT_URL diff --git a/comet/utils/general.py b/comet/utils/general.py index adf1f40..4cec19f 100644 --- a/comet/utils/general.py +++ b/comet/utils/general.py @@ -269,10 +269,15 @@ def get_debrid_extension(debridService: str, debridApiKey: str = None): "premiumize": "PM", "torbox": "TB", "debridlink": "DL", + "easydebrid": "ED", "stremthru": "ST", } - return debrid_extensions.get(debridService, None) + extension = debrid_extensions.get(debridService, None) + if extension == "ST" and debridApiKey and ":" in debridApiKey: + ext = debrid_extensions[debridApiKey.split(":")[0]] + return f"{extension}({ext})" if extension != ext else extension + return extension async def get_indexer_manager(