Skip to content

Commit

Permalink
feat(debrid/stremthru): match behavior with mediafusion
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim committed Jan 8, 2025
1 parent dea8a90 commit 24611a2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion comet/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion comet/api/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 13 additions & 2 deletions comet/debrid/stremthru.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ def __init__(
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"
Expand All @@ -33,12 +34,22 @@ def __init__(
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"
Expand Down
6 changes: 6 additions & 0 deletions comet/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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>

Expand Down
12 changes: 8 additions & 4 deletions comet/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand All @@ -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
7 changes: 6 additions & 1 deletion comet/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 24611a2

Please sign in to comment.