Spaces:
Running
Running
Fix VTV streams: xemtv.us primary, new FPTPlay URLs, normalize old URLs, 4-source fallback
Browse files- vtv_api.py +40 -4
vtv_api.py
CHANGED
|
@@ -74,7 +74,7 @@ FPTPLAY_URLS = {
|
|
| 74 |
"vtv6": "https://live-a.fptplay53.net/live/media/vtv6/live247-hls-avc/index.m3u8",
|
| 75 |
"vtv7": "https://live-a.fptplay53.net/live/media/vtv7/live247-hls-avc/index.m3u8",
|
| 76 |
"vtv8": "https://live-a.fptplay53.net/live/media/vtv8/live-hls-avc/index.m3u8",
|
| 77 |
-
"vtv9": "https://live.fptplay53.net/
|
| 78 |
"vtv10": "https://live-a.fptplay53.net/live/media/vtv10/live247-hls-avc/index.m3u8",
|
| 79 |
}
|
| 80 |
|
|
@@ -180,10 +180,42 @@ def fetch_vtvgo_stream(channel_id):
|
|
| 180 |
pass
|
| 181 |
return None
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
def fetch_vtv_stream(channel_id):
|
| 184 |
"""Fetch VTV stream with multi-source fallback chain:
|
| 185 |
-
1. xemtv.us (primary
|
| 186 |
-
2. FPTPlay CDN (fallback
|
| 187 |
3. VTVGo CDN (fallback)
|
| 188 |
4. xemtv.net legacy (last resort)
|
| 189 |
"""
|
|
@@ -202,12 +234,15 @@ def fetch_vtv_stream(channel_id):
|
|
| 202 |
|
| 203 |
if channel_id == 'vtvprime':
|
| 204 |
url = fetch_xemtv_us_stream('vtvprime') or fetch_xemtv_legacy_stream('vtvprime')
|
|
|
|
|
|
|
| 205 |
_set_cache(channel_id, url)
|
| 206 |
return url
|
| 207 |
|
| 208 |
# Source 1: xemtv.us (primary)
|
| 209 |
url = fetch_xemtv_us_stream(channel_id)
|
| 210 |
if url:
|
|
|
|
| 211 |
_set_cache(channel_id, url)
|
| 212 |
return url
|
| 213 |
|
|
@@ -223,9 +258,10 @@ def fetch_vtv_stream(channel_id):
|
|
| 223 |
_set_cache(channel_id, url)
|
| 224 |
return url
|
| 225 |
|
| 226 |
-
# Source 4: xemtv.net legacy
|
| 227 |
url = fetch_xemtv_legacy_stream(channel_id)
|
| 228 |
if url:
|
|
|
|
| 229 |
_set_cache(channel_id, url)
|
| 230 |
return url
|
| 231 |
|
|
|
|
| 74 |
"vtv6": "https://live-a.fptplay53.net/live/media/vtv6/live247-hls-avc/index.m3u8",
|
| 75 |
"vtv7": "https://live-a.fptplay53.net/live/media/vtv7/live247-hls-avc/index.m3u8",
|
| 76 |
"vtv8": "https://live-a.fptplay53.net/live/media/vtv8/live-hls-avc/index.m3u8",
|
| 77 |
+
"vtv9": "https://live-a.fptplay53.net/live/media/vtv9/live247-hls-avc/index.m3u8",
|
| 78 |
"vtv10": "https://live-a.fptplay53.net/live/media/vtv10/live247-hls-avc/index.m3u8",
|
| 79 |
}
|
| 80 |
|
|
|
|
| 180 |
pass
|
| 181 |
return None
|
| 182 |
|
| 183 |
+
def normalize_fptplay_url(url):
|
| 184 |
+
"""Replace old/broken FPTPlay URLs with new working ones"""
|
| 185 |
+
if not url:
|
| 186 |
+
return url
|
| 187 |
+
old_to_new = {
|
| 188 |
+
"https://live.fptplay53.net/fnxch2/vtv1hd_abr.smil/chunklist.m3u8":
|
| 189 |
+
"https://live-a.fptplay53.net/live/media/vtv1/live247-hls-avc/index.m3u8",
|
| 190 |
+
"https://live.fptplay53.net/fnxch2/vtv2hd_abr.smil/chunklist.m3u8":
|
| 191 |
+
"https://live-a.fptplay53.net/live/media/vtv2/live247-hls-avc/index.m3u8",
|
| 192 |
+
"https://live.fptplay53.net/fnxch2/vtv3hd_abr.smil/chunklist.m3u8":
|
| 193 |
+
"https://live-a.fptplay53.net/live/media/vtv3/live247-hls-avc/index.m3u8",
|
| 194 |
+
"https://live.fptplay53.net/fnxch2/vtv4hd_abr.smil/chunklist.m3u8":
|
| 195 |
+
"https://live-a.fptplay53.net/live/media/vtv4/live247-hls-avc/index.m3u8",
|
| 196 |
+
"https://live.fptplay53.net/fnxhd1/vtv5hd_vhls.smil/chunklist.m3u8":
|
| 197 |
+
"https://live-a.fptplay53.net/live/media/vtv5/live247-hls-avc/index.m3u8",
|
| 198 |
+
"https://live.fptplay53.net/fnxhd1/vtv6hd_vhls.smil/chunklist.m3u8":
|
| 199 |
+
"https://live-a.fptplay53.net/live/media/vtv6/live247-hls-avc/index.m3u8",
|
| 200 |
+
"https://live.fptplay53.net/fnxhd1/vtv7hd_vhls.smil/chunklist_b5000000.m3u8":
|
| 201 |
+
"https://live-a.fptplay53.net/live/media/vtv7/live247-hls-avc/index.m3u8",
|
| 202 |
+
"https://live.fptplay53.net/epzhd1/vtv8hd_vhls.smil/c.hunklist.m3u8":
|
| 203 |
+
"https://live-a.fptplay53.net/live/media/vtv8/live-hls-avc/index.m3u8",
|
| 204 |
+
"https://live.fptplay53.net/epzhd1/vtv8hd_vhls.smil/chunklist.m3u8":
|
| 205 |
+
"https://live-a.fptplay53.net/live/media/vtv8/live-hls-avc/index.m3u8",
|
| 206 |
+
"https://live.fptplay53.net/fnxhd1/vtv9hd_vhls.smil/chunklist.m3u8":
|
| 207 |
+
"https://live-a.fptplay53.net/live/media/vtv9/live247-hls-avc/index.m3u8",
|
| 208 |
+
"https://live.fptplay53.net/fnxhd1/vtv10hd_vhls.smil/chunklist.m3u8":
|
| 209 |
+
"https://live-a.fptplay53.net/live/media/vtv10/live247-hls-avc/index.m3u8",
|
| 210 |
+
"https://live-a.fptplay53.net/live/media/VTV5HD/live_hls_avc/index.m3u8":
|
| 211 |
+
"https://live-a.fptplay53.net/live/media/vtv5/live247-hls-avc/index.m3u8",
|
| 212 |
+
}
|
| 213 |
+
return old_to_new.get(url, url)
|
| 214 |
+
|
| 215 |
def fetch_vtv_stream(channel_id):
|
| 216 |
"""Fetch VTV stream with multi-source fallback chain:
|
| 217 |
+
1. xemtv.us (primary - new domain, most reliable)
|
| 218 |
+
2. FPTPlay CDN (fallback - new URLs)
|
| 219 |
3. VTVGo CDN (fallback)
|
| 220 |
4. xemtv.net legacy (last resort)
|
| 221 |
"""
|
|
|
|
| 234 |
|
| 235 |
if channel_id == 'vtvprime':
|
| 236 |
url = fetch_xemtv_us_stream('vtvprime') or fetch_xemtv_legacy_stream('vtvprime')
|
| 237 |
+
if url:
|
| 238 |
+
url = normalize_fptplay_url(url)
|
| 239 |
_set_cache(channel_id, url)
|
| 240 |
return url
|
| 241 |
|
| 242 |
# Source 1: xemtv.us (primary)
|
| 243 |
url = fetch_xemtv_us_stream(channel_id)
|
| 244 |
if url:
|
| 245 |
+
url = normalize_fptplay_url(url)
|
| 246 |
_set_cache(channel_id, url)
|
| 247 |
return url
|
| 248 |
|
|
|
|
| 258 |
_set_cache(channel_id, url)
|
| 259 |
return url
|
| 260 |
|
| 261 |
+
# Source 4: xemtv.net legacy (last resort)
|
| 262 |
url = fetch_xemtv_legacy_stream(channel_id)
|
| 263 |
if url:
|
| 264 |
+
url = normalize_fptplay_url(url)
|
| 265 |
_set_cache(channel_id, url)
|
| 266 |
return url
|
| 267 |
|