import json from urllib.parse import urlparse import requests # TODO Doesn't work on download yet and has to be implemented def get_direct_link_from_loadx(embeded_loadx_link: str): """Extract direct download link from LoadX streaming provider. Args: embeded_loadx_link: Embedded LoadX link Returns: str: Direct video URL Raises: ValueError: If link extraction fails """ # Default timeout for network requests timeout = 30 response = requests.head( embeded_loadx_link, allow_redirects=True, verify=True, timeout=timeout ) parsed_url = urlparse(response.url) path_parts = parsed_url.path.split("/") if len(path_parts) < 3: raise ValueError("Invalid path!") id_hash = path_parts[2] host = parsed_url.netloc post_url = f"https://{host}/player/index.php?data={id_hash}&do=getVideo" headers = {"X-Requested-With": "XMLHttpRequest"} response = requests.post( post_url, headers=headers, verify=True, timeout=timeout ) data = json.loads(response.text) print(data) video_url = data.get("videoSource") if not video_url: raise ValueError("No Video link found!") return video_url if __name__ == '__main__': url = input("Enter Loadx Link: ") print(get_direct_link_from_loadx(url))