Read redis debrid cache for StremThru (#383)

This commit is contained in:
Munif Tanjim
2024-11-30 07:11:31 +06:00
committed by GitHub
parent 75c64ad88f
commit b52a7fdf7e
5 changed files with 69 additions and 3 deletions
+7
View File
@@ -140,6 +140,13 @@ class StreamingProvider(BaseModel):
"qbittorrent",
"stremthru",
] = Field(alias="sv")
stremthru_store_name: Literal[
"realdebrid",
"debridlink",
"alldebrid",
"torbox",
"premiumize",
] | None = Field(default=None, alias="stsn")
url: HttpUrl | None = Field(default=None, alias="u")
token: str | None = Field(default=None, alias="tk")
email: str | None = Field(default=None, alias="em")
+47
View File
@@ -138,6 +138,53 @@
</div>
</div>
<!-- StremThru Configuration -->
<div id="stremthru_config" style="display:none" class="mb-4">
<label for="stremthru_store_name">Store Name:</label>
{% set stremthru_stores = [
{
"value": "",
"label": "",
},
{
"value": "torbox",
"label": "Torbox",
},
{
"value": "realdebrid",
"label": "Real-Debrid",
},
{
"value": "debridlink",
"label": "Debrid-Link",
},
{
"value": "premiumize",
"label": "Premiumize",
},
{
"value": "alldebrid",
"label": "AllDebrid",
},
] %}
<select class="form-control" name="stremthru_store_name" id="stremthru_store_name">
{% for store in stremthru_stores %}
{% if store.value not in disabled_providers %}
<option
value="{{ store.value }}"
{% if (not store.value and not user_data.streaming_provider.stremthru_store_name) or
(store.value and user_data.streaming_provider.stremthru_store_name == store.value) %}
selected
{% endif %}
>
{{ store.label }}
</option>
{% endif %}
{% endfor %}
</select>
</div>
<!-- Affiliate Signup Links -->
<div id="signup_section" style="display:none" class="mb-4">
<h6>Don't have an account?</h6>
+4
View File
@@ -203,6 +203,7 @@ function updateProviderFields(isChangeEvent = false) {
}
// Toggle visibility of credentials and token input based on provider
setElementDisplay('stremthru_config', provider === 'stremthru' ? 'block' : 'none');
if (provider) {
if (servicesRequiringCredentials.includes(provider)) {
setElementDisplay('credentials', 'block');
@@ -349,6 +350,9 @@ function getUserData() {
validateInput('service_url', validateUrl(serviceUrl));
streamingProviderData.url = serviceUrl;
}
if (provider === 'stremthru') {
streamingProviderData.stremthru_store_name = document.getElementById('stremthru_store_name').value.trim() || null;
}
if (servicesRequiringCredentials.includes(provider)) {
validateInput('email', document.getElementById('email').value);
validateInput('password', document.getElementById('password').value);
+1 -1
View File
@@ -18,7 +18,7 @@ async def store_cached_info_hashes(service: str, info_hashes: List[str]) -> None
service: The debrid service name (e.g., 'realdebrid', 'alldebrid')
info_hashes: List of info hashes that are confirmed to be cached
"""
if not info_hashes:
if not info_hashes or service == "stremthru":
return
try:
+10 -2
View File
@@ -12,7 +12,7 @@ from thefuzz import fuzz
from db.config import settings
from db.models import TorrentStreams, TVStreams
from db.schemas import Stream, UserData, SortingOption
from db.schemas import Stream, StreamingProvider, UserData, SortingOption
from streaming_providers import mapper
from streaming_providers.cache_helpers import (
get_cached_status,
@@ -25,6 +25,13 @@ from utils.network import encode_mediaflow_proxy_url
from utils.runtime_const import ADULT_CONTENT_KEYWORDS, TRACKERS, MANIFEST_TEMPLATE
from utils.validation_helper import validate_m3u8_or_mpd_url_with_cache
def get_cache_service_name(streaming_provider: StreamingProvider):
"""
get service name to use for redis cache retrieval
"""
if streaming_provider.service == "stremthru" and streaming_provider.stremthru_store_name:
return streaming_provider.stremthru_store_name
return streaming_provider.service
async def filter_and_sort_streams(
streams: list[TorrentStreams], user_data: UserData, user_ip: str | None = None
@@ -87,7 +94,8 @@ async def filter_and_sort_streams(
info_hashes = [stream.id for stream in filtered_streams]
# First check Redis cache
cached_statuses = await get_cached_status(service, info_hashes)
cache_service = get_cache_service_name(user_data.streaming_provider)
cached_statuses = await get_cached_status(cache_service, info_hashes)
# Update streams with cached status from Redis
uncached_streams = []