Spaces:
Running
Running
Upload vtv_api.py with huggingface_hub
Browse files- vtv_api.py +70 -5
vtv_api.py
CHANGED
|
@@ -150,17 +150,82 @@ def fetch_xemtv_us_stream(channel_id):
|
|
| 150 |
return None
|
| 151 |
|
| 152 |
def fetch_xemtivitop_stream(channel_id):
|
| 153 |
-
"""Fetch stream from xemtivitop.com blogspot pages"""
|
| 154 |
page_url = XEMTIVITOP_ENDPOINTS.get(channel_id)
|
| 155 |
if not page_url:
|
| 156 |
return None
|
| 157 |
try:
|
| 158 |
headers = {**UA, "Referer": "https://www.xemtivitop.com/"}
|
| 159 |
r = requests.get(page_url, headers=headers, timeout=15, allow_redirects=True, verify=False)
|
| 160 |
-
if r.status_code =
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
except:
|
| 165 |
pass
|
| 166 |
return None
|
|
|
|
| 150 |
return None
|
| 151 |
|
| 152 |
def fetch_xemtivitop_stream(channel_id):
|
| 153 |
+
"""Fetch stream from xemtivitop.com blogspot pages - follows iframe chain to find m3u8"""
|
| 154 |
page_url = XEMTIVITOP_ENDPOINTS.get(channel_id)
|
| 155 |
if not page_url:
|
| 156 |
return None
|
| 157 |
try:
|
| 158 |
headers = {**UA, "Referer": "https://www.xemtivitop.com/"}
|
| 159 |
r = requests.get(page_url, headers=headers, timeout=15, allow_redirects=True, verify=False)
|
| 160 |
+
if r.status_code != 200:
|
| 161 |
+
return None
|
| 162 |
+
html = r.text
|
| 163 |
+
|
| 164 |
+
# Try 1: Direct m3u8 in the page
|
| 165 |
+
m3u8 = extract_m3u8_from_html(html)
|
| 166 |
+
if m3u8:
|
| 167 |
+
return m3u8
|
| 168 |
+
|
| 169 |
+
# Try 2: Find blogspot iframe (kenhtivitop.blogspot.com) and extract m3u8 from it
|
| 170 |
+
import html as html_lib
|
| 171 |
+
iframe_match = re.search(r'src="(https://kenhtivitop\.blogspot\.com[^"]*)"', html, re.IGNORECASE)
|
| 172 |
+
if iframe_match:
|
| 173 |
+
iframe_url = iframe_match.group(1)
|
| 174 |
+
try:
|
| 175 |
+
r2 = requests.get(iframe_url, headers={**UA, "Referer": "https://www.xemtivitop.com/"}, timeout=10, allow_redirects=True, verify=False)
|
| 176 |
+
if r2.status_code == 200:
|
| 177 |
+
m3u8 = extract_m3u8_from_html(r2.text)
|
| 178 |
+
if m3u8:
|
| 179 |
+
return m3u8
|
| 180 |
+
except:
|
| 181 |
+
pass
|
| 182 |
+
|
| 183 |
+
# Try 3: Find PHP endpoint (sv2.xemtivitop.com/live/hot/...) and follow chain
|
| 184 |
+
php_match = re.search(r'src="(https://sv2\.xemtivitop\.com/live/hot/[^"]*)"', html, re.IGNORECASE)
|
| 185 |
+
if php_match:
|
| 186 |
+
php_url = php_match.group(1)
|
| 187 |
+
try:
|
| 188 |
+
r3 = requests.get(php_url, headers={**UA, "Referer": "https://www.xemtivitop.com/"}, timeout=10, allow_redirects=True, verify=False)
|
| 189 |
+
if r3.status_code == 200:
|
| 190 |
+
# PHP page may contain iframe to lienket.php
|
| 191 |
+
link_match = re.search(r'src="(https://sv2\.xemtivitop\.com/lienket\.php[^"]*)"', r3.text, re.IGNORECASE)
|
| 192 |
+
if link_match:
|
| 193 |
+
lk_url = link_match.group(1)
|
| 194 |
+
try:
|
| 195 |
+
r4 = requests.get(lk_url, headers={**UA, "Referer": php_url}, timeout=10, allow_redirects=True, verify=False)
|
| 196 |
+
if r4.status_code == 200:
|
| 197 |
+
# lienket.php may have href.li / vtvgo / tvmanh references
|
| 198 |
+
# Check for href.li redirect
|
| 199 |
+
href_li = re.search(r'href="https://href\.li/\?(https?://[^"]*)"', r4.text)
|
| 200 |
+
if href_li:
|
| 201 |
+
target = href_li.group(1)
|
| 202 |
+
# vtvgo.vn needs auth - return FPTPlay CDN fallback as best effort
|
| 203 |
+
pass
|
| 204 |
+
# Check for tvmanh.com iframes
|
| 205 |
+
tvmanh_match = re.search(r'src="(https://playtvmanh\.blogspot\.com[^"]*)"', r4.text, re.IGNORECASE)
|
| 206 |
+
if not tvmanh_match:
|
| 207 |
+
tvmanh_match = re.search(r'src="(https://playxemtivitop\.blogspot\.com[^"]*)"', r4.text, re.IGNORECASE)
|
| 208 |
+
if tvmanh_match:
|
| 209 |
+
try:
|
| 210 |
+
r5 = requests.get(tvmanh_match.group(1), headers={**UA, "Referer": lk_url}, timeout=10, allow_redirects=True, verify=False)
|
| 211 |
+
if r5.status_code == 200:
|
| 212 |
+
m3u8 = extract_m3u8_from_html(r5.text)
|
| 213 |
+
if m3u8:
|
| 214 |
+
return m3u8
|
| 215 |
+
except:
|
| 216 |
+
pass
|
| 217 |
+
# Check for direct m3u8 in lienket page
|
| 218 |
+
m3u8 = extract_m3u8_from_html(r4.text)
|
| 219 |
+
if m3u8:
|
| 220 |
+
return m3u8
|
| 221 |
+
except:
|
| 222 |
+
pass
|
| 223 |
+
# Direct m3u8 in PHP page
|
| 224 |
+
m3u8 = extract_m3u8_from_html(r3.text)
|
| 225 |
+
if m3u8:
|
| 226 |
+
return m3u8
|
| 227 |
+
except:
|
| 228 |
+
pass
|
| 229 |
except:
|
| 230 |
pass
|
| 231 |
return None
|