Download app.py from futbolx/live: direct link, hf CLI and curl.
- Browser
- Download file 3.9 kB
-
https://huggingface.co/spaces/futbolx/live/resolve/main/app.py
- Command line
-
hf download hf://spaces/futbolx/live/app.py
-
curl -L -o app.py https://huggingface.co/spaces/futbolx/live/resolve/main/app.py
3.9 kB
| import re | |
| import requests | |
| import base64 | |
| from fastapi import FastAPI, HTTPException | |
| from fastapi.responses import HTMLResponse, PlainTextResponse | |
| app = FastAPI() | |
| CLAPPR_TEMPLATE = """ | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Live Stream - {channel}</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
| <meta name="monetag" content="9bfe6270517d3fe56013a9566c99bf4a"> | |
| <script src="https://pl30129042.effectivecpmnetwork.com/e3/e9/a9/e3e9a9853f29247bab3d96cd39666af8.js"></script> | |
| <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@clappr/player@0.11.16/dist/clappr.min.js"></script> | |
| <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clappr-pip-plugin@2.0.1/dist/clappr-pip-plugin.js"></script> | |
| <style> | |
| body, html {{ margin: 0; padding: 0; width: 100%; height: 100%; background-color: black; overflow: hidden; }} | |
| #player {{ width: 100%; height: 100%; position: absolute; top: 0; left: 0; z-index: 1; }} | |
| </style> | |
| </head> | |
| <body> | |
| <div id="player"></div> | |
| <script> | |
| var hiddenUrl = "{encoded_url}"; | |
| var actualUrl = atob(hiddenUrl); | |
| var player = new Clappr.Player({{ | |
| source: actualUrl, | |
| mimeType: "application/x-mpegURL", | |
| parentId: "#player", | |
| autoPlay: true, | |
| width: '100%', | |
| height: '100%', | |
| plugins: [ClapprPIPPlugin], | |
| mediacontrol: {{ | |
| seekbar: "#E50914", | |
| buttons: "#E50914" | |
| }} | |
| }}); | |
| </script> | |
| </body> | |
| </html> | |
| """ | |
| async def get_embed(channel: str): | |
| target_url = f"https://wc.ppvtv.top/embed/{channel}" | |
| headers = { | |
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", | |
| "Referer": "https://ppvtv.top/" | |
| } | |
| try: | |
| response = requests.get(target_url, headers=headers, timeout=10) | |
| response.raise_for_status() | |
| html_content = response.text | |
| match = re.search(r'(/stream/[a-f0-9]+)', html_content) | |
| if match: | |
| path = match.group(1) | |
| stream_url = f"https://wc.ppvtv.top{path}" | |
| encoded_url = base64.b64encode(stream_url.encode('utf-8')).decode('utf-8') | |
| html_response = CLAPPR_TEMPLATE.format(channel=channel.upper(), encoded_url=encoded_url) | |
| return HTMLResponse(content=html_response, status_code=200) | |
| else: | |
| # Removed the debug text that leaks the stream URL layout | |
| raise HTTPException(status_code=404, detail="Stream link not found or channel is currently offline.") | |
| except requests.exceptions.HTTPError as http_err: | |
| # Handles 404, 500, etc., from the target source securely | |
| status_code = http_err.response.status_code if http_err.response else 502 | |
| raise HTTPException(status_code=status_code, detail="The requested stream is unavailable.") | |
| except requests.RequestException: | |
| # Handles timeouts, network drops, etc. | |
| raise HTTPException(status_code=502, detail="Failed to connect to streaming gateway.") | |
| # OPTIONAL SECURITY NOTE: Consider removing or commenting out the debug route entirely in production, | |
| # as anyone guessing it could read the source HTML of your stream provider. | |
| async def debug_source(channel: str): | |
| target_url = f"https://wc.ppvtv.top/embed/{channel}" | |
| headers = { | |
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", | |
| "Referer": "https://ppvtv.top/" | |
| } | |
| try: | |
| response = requests.get(target_url, headers=headers, timeout=10) | |
| return PlainTextResponse(content=response.text) | |
| except Exception: | |
| return PlainTextResponse(content="Error fetching page safely.") |