feat(debrid/stremthru): match behavior with mediafusion

This commit is contained in:
Munif Tanjim
2025-01-08 15:49:16 +06:00
parent dea8a9041c
commit 24611a2940
6 changed files with 35 additions and 9 deletions
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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)
+13 -2
View File
@@ -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"
+6
View File
@@ -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!"
}
});
</script>
+8 -4
View File
@@ -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
+6 -1
View File
@@ -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(