Spaces:
Running
Running
Upload vtv_api.py
Browse files- vtv_api.py +17 -5
vtv_api.py
CHANGED
|
@@ -13,14 +13,18 @@ UA = {
|
|
| 13 |
"Accept-Language": "vi-VN,vi;q=0.9",
|
| 14 |
}
|
| 15 |
|
| 16 |
-
# ===== NGUỒN PHÁT
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
CHANNEL_URLS = {
|
| 18 |
"vtv1": None,
|
| 19 |
"vtv2": None,
|
| 20 |
"vtv3": None,
|
| 21 |
"vtv4": None,
|
| 22 |
"vtv5": None,
|
| 23 |
-
"vtv6":
|
| 24 |
"vtv7": None,
|
| 25 |
"vtv8": None,
|
| 26 |
"vtv9": None,
|
|
@@ -87,7 +91,12 @@ def _fetch_m3u():
|
|
| 87 |
}
|
| 88 |
if ch_id in ch_map:
|
| 89 |
ch_id = ch_map[ch_id]
|
|
|
|
| 90 |
if ch_id in CHANNEL_URLS and ch_id not in all_urls:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
# Ưu tiên FLV hơn HLS/m3u8
|
| 92 |
if ".flv" in s:
|
| 93 |
all_urls[ch_id] = s
|
|
@@ -103,10 +112,13 @@ def _fetch_m3u():
|
|
| 103 |
with _channel_urls_lock:
|
| 104 |
found = 0
|
| 105 |
for ch_id in CHANNEL_URLS:
|
|
|
|
|
|
|
|
|
|
| 106 |
if ch_id in all_urls:
|
| 107 |
CHANNEL_URLS[ch_id] = all_urls[ch_id]
|
| 108 |
found += 1
|
| 109 |
-
print(f"[M3U] Found {found}/10 channels")
|
| 110 |
|
| 111 |
def get_channel_url(channel_id):
|
| 112 |
_fetch_m3u()
|
|
@@ -124,7 +136,7 @@ def proxy_stream(url: str = Query(...)):
|
|
| 124 |
"""Proxy FLV/HLS stream — tránh CORS & geo-block"""
|
| 125 |
try:
|
| 126 |
req_headers = dict(UA)
|
| 127 |
-
req_headers["Referer"] = "https://
|
| 128 |
r = requests.get(url, headers=req_headers, timeout=30, stream=True)
|
| 129 |
if r.status_code != 200:
|
| 130 |
return Response(content=f"stream error: {r.status_code}", status_code=502)
|
|
@@ -159,7 +171,7 @@ def proxy_flv(url: str = Query(...)):
|
|
| 159 |
"""Proxy FLV stream với Range support"""
|
| 160 |
try:
|
| 161 |
req_headers = dict(UA)
|
| 162 |
-
req_headers["Referer"] = "https://
|
| 163 |
r = requests.get(url, headers=req_headers, timeout=30, stream=True)
|
| 164 |
if r.status_code != 200:
|
| 165 |
return Response(content=f"flv error: {r.status_code}", status_code=502)
|
|
|
|
| 13 |
"Accept-Language": "vi-VN,vi;q=0.9",
|
| 14 |
}
|
| 15 |
|
| 16 |
+
# ===== NGUỒN PHÁT: HARDCODE VTV6 + M3U fallback cho các kênh khác =====
|
| 17 |
+
HARDCODED_URLS = {
|
| 18 |
+
"vtv6": "https://live.fptplay53.net/live/media/v6abr/live247-hls-avc/v6abr-avc1_5600000=10000-mp4a_131600=20000.m3u8",
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
CHANNEL_URLS = {
|
| 22 |
"vtv1": None,
|
| 23 |
"vtv2": None,
|
| 24 |
"vtv3": None,
|
| 25 |
"vtv4": None,
|
| 26 |
"vtv5": None,
|
| 27 |
+
"vtv6": HARDCODED_URLS["vtv6"], # hardcode VTV6
|
| 28 |
"vtv7": None,
|
| 29 |
"vtv8": None,
|
| 30 |
"vtv9": None,
|
|
|
|
| 91 |
}
|
| 92 |
if ch_id in ch_map:
|
| 93 |
ch_id = ch_map[ch_id]
|
| 94 |
+
# Chỉ cập nhật nếu chưa có hoặc hardcode không ghi đè
|
| 95 |
if ch_id in CHANNEL_URLS and ch_id not in all_urls:
|
| 96 |
+
# KHÔNG ghi đè hardcode (VTV6)
|
| 97 |
+
if CHANNEL_URLS[ch_id] and CHANNEL_URLS[ch_id] == HARDCODED_URLS.get(ch_id):
|
| 98 |
+
current_channel = None
|
| 99 |
+
continue
|
| 100 |
# Ưu tiên FLV hơn HLS/m3u8
|
| 101 |
if ".flv" in s:
|
| 102 |
all_urls[ch_id] = s
|
|
|
|
| 112 |
with _channel_urls_lock:
|
| 113 |
found = 0
|
| 114 |
for ch_id in CHANNEL_URLS:
|
| 115 |
+
# KHÔNG ghi đè hardcode
|
| 116 |
+
if CHANNEL_URLS[ch_id] and HARDCODED_URLS.get(ch_id):
|
| 117 |
+
continue
|
| 118 |
if ch_id in all_urls:
|
| 119 |
CHANNEL_URLS[ch_id] = all_urls[ch_id]
|
| 120 |
found += 1
|
| 121 |
+
print(f"[M3U] Found {found}/10 channels (hardcoded: vtv6)")
|
| 122 |
|
| 123 |
def get_channel_url(channel_id):
|
| 124 |
_fetch_m3u()
|
|
|
|
| 136 |
"""Proxy FLV/HLS stream — tránh CORS & geo-block"""
|
| 137 |
try:
|
| 138 |
req_headers = dict(UA)
|
| 139 |
+
req_headers["Referer"] = "https://live.fptplay53.net/"
|
| 140 |
r = requests.get(url, headers=req_headers, timeout=30, stream=True)
|
| 141 |
if r.status_code != 200:
|
| 142 |
return Response(content=f"stream error: {r.status_code}", status_code=502)
|
|
|
|
| 171 |
"""Proxy FLV stream với Range support"""
|
| 172 |
try:
|
| 173 |
req_headers = dict(UA)
|
| 174 |
+
req_headers["Referer"] = "https://live.fptplay53.net/"
|
| 175 |
r = requests.get(url, headers=req_headers, timeout=30, stream=True)
|
| 176 |
if r.status_code != 200:
|
| 177 |
return Response(content=f"flv error: {r.status_code}", status_code=502)
|