Spaces:
Running
Running
Fix VTV 403: add Referer/Origin headers for vtvdigital + show video before HLS attach
Browse files
main.py
CHANGED
|
@@ -136,8 +136,12 @@ def _parse_match_from_li(li, status_type="live"):
|
|
| 136 |
@app.get("/api/proxy/m3u8")
|
| 137 |
def proxy_m3u8(url: str = Query(...)):
|
| 138 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
verify_ssl = "vtvdigital" not in url
|
| 140 |
-
r = requests.get(url, headers=
|
| 141 |
if r.status_code != 200: return Response(status_code=502, content="upstream error")
|
| 142 |
lines = r.text.strip().split('\n'); rewritten = []
|
| 143 |
for line in lines:
|
|
@@ -149,8 +153,12 @@ def proxy_m3u8(url: str = Query(...)):
|
|
| 149 |
@app.get("/api/proxy/seg")
|
| 150 |
def proxy_segment(url: str = Query(...)):
|
| 151 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
verify_ssl = "vtvdigital" not in url
|
| 153 |
-
r = requests.get(url, headers=
|
| 154 |
if r.status_code != 200: return Response(status_code=502, content="upstream error")
|
| 155 |
data = r.content
|
| 156 |
# If response is an m3u8 sub-playlist, rewrite segment URLs
|
|
|
|
| 136 |
@app.get("/api/proxy/m3u8")
|
| 137 |
def proxy_m3u8(url: str = Query(...)):
|
| 138 |
try:
|
| 139 |
+
headers = dict(HEADERS)
|
| 140 |
+
if "vtvdigital" in url:
|
| 141 |
+
headers["Referer"] = "https://vtv.vn/"
|
| 142 |
+
headers["Origin"] = "https://vtv.vn"
|
| 143 |
verify_ssl = "vtvdigital" not in url
|
| 144 |
+
r = requests.get(url, headers=headers, timeout=15, verify=verify_ssl)
|
| 145 |
if r.status_code != 200: return Response(status_code=502, content="upstream error")
|
| 146 |
lines = r.text.strip().split('\n'); rewritten = []
|
| 147 |
for line in lines:
|
|
|
|
| 153 |
@app.get("/api/proxy/seg")
|
| 154 |
def proxy_segment(url: str = Query(...)):
|
| 155 |
try:
|
| 156 |
+
headers = dict(HEADERS)
|
| 157 |
+
if "vtvdigital" in url:
|
| 158 |
+
headers["Referer"] = "https://vtv.vn/"
|
| 159 |
+
headers["Origin"] = "https://vtv.vn"
|
| 160 |
verify_ssl = "vtvdigital" not in url
|
| 161 |
+
r = requests.get(url, headers=headers, timeout=30, verify=verify_ssl)
|
| 162 |
if r.status_code != 200: return Response(status_code=502, content="upstream error")
|
| 163 |
data = r.content
|
| 164 |
# If response is an m3u8 sub-playlist, rewrite segment URLs
|