Spaces:
Running
Running
Upload main.py
Browse files
main.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
"""VNEWS - FastAPI backend
|
| 2 |
-
import re, time, json, os, threading
|
| 3 |
import html as html_lib
|
| 4 |
from datetime import datetime, timezone, timedelta
|
| 5 |
from collections import defaultdict
|
|
@@ -35,8 +35,7 @@ def _check_rate_limit(ip: str) -> bool:
|
|
| 35 |
async def rate_limit_middleware(request: Request, call_next):
|
| 36 |
if request.url.path.startswith("/api/"):
|
| 37 |
ip = request.client.host
|
| 38 |
-
if not _check_rate_limit(ip):
|
| 39 |
-
return JSONResponse({"error": "rate limit exceeded"}, status_code=429)
|
| 40 |
return await call_next(request)
|
| 41 |
|
| 42 |
# ===== VTV CHANNELS API =====
|
|
@@ -49,6 +48,7 @@ BASE_BDP = "https://bongdaplus.vn"
|
|
| 49 |
_cache = {}
|
| 50 |
_cache_ttl = 300
|
| 51 |
_cache_ttl_live = 60
|
|
|
|
| 52 |
|
| 53 |
PRIORITY_LEAGUES = ["Ngoại Hạng Anh","FA Cup","Champions League","LaLiga","Copa del Rey","Serie A","Bundesliga","Ligue 1","V-League"]
|
| 54 |
LEAGUE_IDS = {"nha":27110,"laliga":27233,"seriea":27044,"bundesliga":26891,"ligue1":27212}
|
|
@@ -253,17 +253,6 @@ def extract_xemlaibongda_video(url):
|
|
| 253 |
return None
|
| 254 |
except: return None
|
| 255 |
|
| 256 |
-
# ===== VTV Nam Bộ Shorts (yt-dlp based) =====
|
| 257 |
-
from yt_scraper import get_vtvnambo_shorts, get_wc_related_shorts
|
| 258 |
-
|
| 259 |
-
@app.get("/api/shorts/vtvnamo")
|
| 260 |
-
def api_shorts_vtvnamo(count: int = Query(default=50, le=100)):
|
| 261 |
-
return JSONResponse(get_vtvnambo_shorts(count))
|
| 262 |
-
|
| 263 |
-
@app.get("/api/shorts/wc")
|
| 264 |
-
def api_shorts_wc(count: int = Query(default=50, le=100)):
|
| 265 |
-
return JSONResponse(get_wc_related_shorts(count))
|
| 266 |
-
|
| 267 |
# ===== LIVESCORE =====
|
| 268 |
@app.get("/api/livescore/live")
|
| 269 |
def api_livescore_live(): return JSONResponse({"html":_cached("ls_live",lambda:fetch_bongda_api("/api/fixtures/live"),ttl=_cache_ttl_live)})
|
|
@@ -528,4 +517,4 @@ def api_hot_topics():
|
|
| 528 |
|
| 529 |
@app.get("/", response_class=HTMLResponse)
|
| 530 |
async def root():
|
| 531 |
-
return HTMLResponse("<h1>VNEWS
|
|
|
|
| 1 |
+
"""VNEWS - FastAPI backend with livescore + xemlaibongda highlights + VTV channels"""
|
| 2 |
+
import re, time, subprocess, json, os, threading
|
| 3 |
import html as html_lib
|
| 4 |
from datetime import datetime, timezone, timedelta
|
| 5 |
from collections import defaultdict
|
|
|
|
| 35 |
async def rate_limit_middleware(request: Request, call_next):
|
| 36 |
if request.url.path.startswith("/api/"):
|
| 37 |
ip = request.client.host
|
| 38 |
+
if not _check_rate_limit(ip): return JSONResponse({"error": "rate limit exceeded"}, status_code=429)
|
|
|
|
| 39 |
return await call_next(request)
|
| 40 |
|
| 41 |
# ===== VTV CHANNELS API =====
|
|
|
|
| 48 |
_cache = {}
|
| 49 |
_cache_ttl = 300
|
| 50 |
_cache_ttl_live = 60
|
| 51 |
+
_cache_ttl_yt = 1800
|
| 52 |
|
| 53 |
PRIORITY_LEAGUES = ["Ngoại Hạng Anh","FA Cup","Champions League","LaLiga","Copa del Rey","Serie A","Bundesliga","Ligue 1","V-League"]
|
| 54 |
LEAGUE_IDS = {"nha":27110,"laliga":27233,"seriea":27044,"bundesliga":26891,"ligue1":27212}
|
|
|
|
| 253 |
return None
|
| 254 |
except: return None
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
# ===== LIVESCORE =====
|
| 257 |
@app.get("/api/livescore/live")
|
| 258 |
def api_livescore_live(): return JSONResponse({"html":_cached("ls_live",lambda:fetch_bongda_api("/api/fixtures/live"),ttl=_cache_ttl_live)})
|
|
|
|
| 517 |
|
| 518 |
@app.get("/", response_class=HTMLResponse)
|
| 519 |
async def root():
|
| 520 |
+
return HTMLResponse("<h1>VNEWS v17</h1><p>VTV Digital CDN ssaimh · No shorts Dantri/SKDS · Homepage full content</p>")
|