Spaces:
Running
Running
vtv_api: fix verify for smil URLs, use GET+Range
Browse files- vtv_api.py +4 -5
vtv_api.py
CHANGED
|
@@ -110,16 +110,13 @@ def _set_cache(key, data):
|
|
| 110 |
|
| 111 |
|
| 112 |
def _verify_url(url, timeout=5):
|
| 113 |
-
"""Verify a stream URL is reachable
|
| 114 |
try:
|
| 115 |
headers = {"User-Agent": UA["User-Agent"]}
|
| 116 |
if "fptplay" in url:
|
| 117 |
headers["Referer"] = "https://fptplay.vn/"
|
| 118 |
headers["Origin"] = "https://fptplay.vn"
|
| 119 |
-
|
| 120 |
-
if r.status_code == 200:
|
| 121 |
-
return True
|
| 122 |
-
# Some servers don't support HEAD, try GET with range
|
| 123 |
headers["Range"] = "bytes=0-0"
|
| 124 |
r = requests.get(url, headers=headers, timeout=timeout, allow_redirects=True)
|
| 125 |
return r.status_code in (200, 206)
|
|
@@ -301,3 +298,5 @@ def proxy_vtv_segment(url: str = Query(...)):
|
|
| 301 |
)
|
| 302 |
except:
|
| 303 |
return Response(status_code=502, content="proxy error")
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
|
| 112 |
def _verify_url(url, timeout=5):
|
| 113 |
+
"""Verify a stream URL is reachable."""
|
| 114 |
try:
|
| 115 |
headers = {"User-Agent": UA["User-Agent"]}
|
| 116 |
if "fptplay" in url:
|
| 117 |
headers["Referer"] = "https://fptplay.vn/"
|
| 118 |
headers["Origin"] = "https://fptplay.vn"
|
| 119 |
+
# Try GET with range first (more reliable than HEAD for CDNs)
|
|
|
|
|
|
|
|
|
|
| 120 |
headers["Range"] = "bytes=0-0"
|
| 121 |
r = requests.get(url, headers=headers, timeout=timeout, allow_redirects=True)
|
| 122 |
return r.status_code in (200, 206)
|
|
|
|
| 298 |
)
|
| 299 |
except:
|
| 300 |
return Response(status_code=502, content="proxy error")
|
| 301 |
+
|
| 302 |
+
# Updated: 1781062125
|