diff --git a/mediaflow_proxy/extractors/uqload.py b/mediaflow_proxy/extractors/uqload.py index 03a5b98..70e66b0 100644 --- a/mediaflow_proxy/extractors/uqload.py +++ b/mediaflow_proxy/extractors/uqload.py @@ -3,12 +3,39 @@ import re from mediaflow_proxy.configs import settings -async def uqload_url(d: str, use_request_proxy: bool): - async with httpx.AsyncClient(proxy=settings.proxy_url if use_request_proxy else None) as client: +from typing import Tuple, Dict, Optional - response = await client.get(d, follow_redirects=True) - video_url_match = re.search(r'sources: \["(.*?)"\]', response.text) - if video_url_match: - final_url = video_url_match.group(1) - uqload_dict = {"Referer": "https://uqload.to/"} - return final_url, uqload_dict +async def uqload_url(d: str, use_request_proxy: bool) -> Tuple[Optional[str], Dict[str, str]]: + """ + Extract video URL from Uqload. + + Args: + d: The Uqload video URL + use_request_proxy: Whether to use proxy for the request + + Returns: + Tuple containing the extracted video URL (or None if not found) and headers dictionary + + Raises: + httpx.HTTPError: If the HTTP request fails + """ + if not d.startswith(('http://', 'https://')): + raise ValueError("Invalid URL format") + + REFERER = "https://uqload.to/" + final_url = None + + async with httpx.AsyncClient(proxy=settings.proxy_url if use_request_proxy else None) as client: + try: + response = await client.get(d, follow_redirects=True) + response.raise_for_status() + + # Look for video URL in response using a more robust pattern + video_url_match = re.search(r'sources:\s*\[(["\'])(.*?)\1\]', response.text) + if video_url_match: + final_url = video_url_match.group(2) + + return final_url, {"Referer": REFERER} + except httpx.HTTPError as e: + # Log the error here if logging is available + raise diff --git a/mediaflow_proxy/extractors_routes.py b/mediaflow_proxy/extractors_routes.py index 3b814b6..702aaed 100644 --- a/mediaflow_proxy/extractors_routes.py +++ b/mediaflow_proxy/extractors_routes.py @@ -10,7 +10,7 @@ host_map = {"Doodstream": doodstream_url, "Mixdrop": mixdrop_url, "Uqload": uqlo @extractor_router.get("/extractor") -async def doodstream_extractor( +async def extract_media_url( d: str = Query(..., description="Extract Clean Link from various Hosts"), use_request_proxy: bool = Query(False, description="Whether to use the MediaFlow proxy configuration."), host: str = Query( @@ -32,8 +32,15 @@ async def doodstream_extractor( """ try: final_url, headers_dict = await host_map[host](d, use_request_proxy) + except KeyError: + return JSONResponse( + status_code=400, + content={"error": f"Invalid host type. Available hosts: {', '.join(host_map.keys())}"} + ) + except ValueError as e: + return JSONResponse(status_code=400, content={"error": str(e)}) except Exception as e: - return JSONResponse(content={"error": str(e)}) + return JSONResponse(status_code=500, content={"error": "Internal server error"}) if redirect_stream == True: formatted_headers = format_headers(headers_dict) redirected_stream = f"/proxy/stream?api_password={settings.api_password}&d={final_url}&{formatted_headers}" diff --git a/mediaflow_proxy/static/speedtest_progress.html b/mediaflow_proxy/static/speedtest_progress.html index 9a20cf0..a180764 100644 --- a/mediaflow_proxy/static/speedtest_progress.html +++ b/mediaflow_proxy/static/speedtest_progress.html @@ -63,34 +63,56 @@