mirror of
https://github.com/UrloMythus/UnHided.git
synced 2026-04-11 20:00:52 +00:00
92 lines
4.1 KiB
Python
92 lines
4.1 KiB
Python
from typing import Dict, Literal, Optional, Union
|
|
|
|
import httpx
|
|
from pydantic import BaseModel, Field
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class RouteConfig(BaseModel):
|
|
"""Configuration for a specific route"""
|
|
|
|
proxy: bool = True
|
|
proxy_url: Optional[str] = None
|
|
verify_ssl: bool = True
|
|
|
|
|
|
class TransportConfig(BaseSettings):
|
|
"""Main proxy configuration"""
|
|
|
|
proxy_url: Optional[str] = Field(
|
|
None, description="Primary proxy URL. Example: socks5://user:pass@proxy:1080 or http://proxy:8080"
|
|
)
|
|
all_proxy: bool = Field(False, description="Enable proxy for all routes by default")
|
|
transport_routes: Dict[str, RouteConfig] = Field(
|
|
default_factory=dict, description="Pattern-based route configuration"
|
|
)
|
|
timeout: int = Field(30, description="Timeout for HTTP requests in seconds")
|
|
|
|
def get_mounts(
|
|
self, async_http: bool = True
|
|
) -> Dict[str, Optional[Union[httpx.HTTPTransport, httpx.AsyncHTTPTransport]]]:
|
|
"""
|
|
Get a dictionary of httpx mount points to transport instances.
|
|
"""
|
|
mounts = {}
|
|
transport_cls = httpx.AsyncHTTPTransport if async_http else httpx.HTTPTransport
|
|
|
|
# Configure specific routes
|
|
for pattern, route in self.transport_routes.items():
|
|
mounts[pattern] = transport_cls(
|
|
verify=route.verify_ssl, proxy=route.proxy_url or self.proxy_url if route.proxy else None
|
|
)
|
|
|
|
# Hardcoded configuration for jxoplay.xyz domain - SSL verification disabled
|
|
mounts["all://jxoplay.xyz"] = transport_cls(
|
|
verify=False, proxy=self.proxy_url if self.all_proxy else None
|
|
)
|
|
|
|
# Set default proxy for all routes if enabled
|
|
if self.all_proxy:
|
|
mounts["all://"] = transport_cls(proxy=self.proxy_url)
|
|
|
|
return mounts
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
extra = "ignore"
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
api_password: str | None = None # The password for protecting the API endpoints.
|
|
log_level: str = "INFO" # The logging level to use.
|
|
transport_config: TransportConfig = Field(default_factory=TransportConfig) # Configuration for httpx transport.
|
|
enable_streaming_progress: bool = False # Whether to enable streaming progress tracking.
|
|
disable_home_page: bool = False # Whether to disable the home page UI.
|
|
disable_docs: bool = False # Whether to disable the API documentation (Swagger UI).
|
|
disable_speedtest: bool = False # Whether to disable the speedtest UI.
|
|
stremio_proxy_url: str | None = None # The Stremio server URL for alternative content proxying.
|
|
m3u8_content_routing: Literal["mediaflow", "stremio", "direct"] = (
|
|
"mediaflow" # Routing strategy for M3U8 content URLs: "mediaflow", "stremio", or "direct"
|
|
)
|
|
enable_hls_prebuffer: bool = False # Whether to enable HLS pre-buffering for improved streaming performance.
|
|
hls_prebuffer_segments: int = 5 # Number of segments to pre-buffer ahead.
|
|
hls_prebuffer_cache_size: int = 50 # Maximum number of segments to cache in memory.
|
|
hls_prebuffer_max_memory_percent: int = 80 # Maximum percentage of system memory to use for HLS pre-buffer cache.
|
|
hls_prebuffer_emergency_threshold: int = 90 # Emergency threshold percentage to trigger aggressive cache cleanup.
|
|
enable_dash_prebuffer: bool = False # Whether to enable DASH pre-buffering for improved streaming performance.
|
|
dash_prebuffer_segments: int = 5 # Number of segments to pre-buffer ahead.
|
|
dash_prebuffer_cache_size: int = 50 # Maximum number of segments to cache in memory.
|
|
dash_prebuffer_max_memory_percent: int = 80 # Maximum percentage of system memory to use for DASH pre-buffer cache.
|
|
dash_prebuffer_emergency_threshold: int = 90 # Emergency threshold percentage to trigger aggressive cache cleanup.
|
|
|
|
user_agent: str = (
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36" # The user agent to use for HTTP requests.
|
|
)
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
extra = "ignore"
|
|
|
|
|
|
settings = Settings()
|