bep40 commited on
Commit
4937047
·
verified ·
1 Parent(s): 89e641c

Upload app_main.py

Browse files
Files changed (1) hide show
  1. app_main.py +23 -2
app_main.py CHANGED
@@ -71,13 +71,11 @@ def _search_all(topic, limit=40):
71
  # AGGRESSIVELY remove ALL old '/' routes from entire chain
72
  # This ensures our new '/' route is the ONLY one serving
73
  # ============================================================
74
- # Remove from app.router.routes (APIRoute objects)
75
  app.router.routes = [r for r in app.router.routes if not (
76
  (getattr(r, 'path', None) == '/' and 'GET' in getattr(r, 'methods', set())) or
77
  (getattr(r, 'path', None) == '/api/hashtag/sources' and 'GET' in getattr(r, 'methods', set())) or
78
  (getattr(r, 'path', None) in ('/api/short/comments', '/api/short/comment'))
79
  )]
80
- # Also remove from app.routes (includes mounts)
81
  app.routes[:] = [r for r in app.routes if not (
82
  hasattr(r, 'path') and getattr(r, 'path', None) == '/' and
83
  hasattr(r, 'methods') and 'GET' in getattr(r, 'methods', set())
@@ -207,6 +205,29 @@ def api_match_detail_by_url(url: str = Query(...)):
207
  """Get match detail by full bongda.com.vn URL."""
208
  return JSONResponse(fetch_match_detail_by_url(url))
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  def _wc2026_bg_refresh():
211
  time.sleep(10)
212
  while True:
 
71
  # AGGRESSIVELY remove ALL old '/' routes from entire chain
72
  # This ensures our new '/' route is the ONLY one serving
73
  # ============================================================
 
74
  app.router.routes = [r for r in app.router.routes if not (
75
  (getattr(r, 'path', None) == '/' and 'GET' in getattr(r, 'methods', set())) or
76
  (getattr(r, 'path', None) == '/api/hashtag/sources' and 'GET' in getattr(r, 'methods', set())) or
77
  (getattr(r, 'path', None) in ('/api/short/comments', '/api/short/comment'))
78
  )]
 
79
  app.routes[:] = [r for r in app.routes if not (
80
  hasattr(r, 'path') and getattr(r, 'path', None) == '/' and
81
  hasattr(r, 'methods') and 'GET' in getattr(r, 'methods', set())
 
205
  """Get match detail by full bongda.com.vn URL."""
206
  return JSONResponse(fetch_match_detail_by_url(url))
207
 
208
+ # ============================================================
209
+ # VTV CHANNELS API
210
+ # ============================================================
211
+ from vtv_scraper import get_vtv_channels_for_frontend, XEMTV_CHANNELS, fetch_vtv_stream
212
+
213
+ @app.get('/api/vtv/channels')
214
+ def api_vtv_channels():
215
+ """Get all VTV channel stream URLs."""
216
+ channels = get_vtv_channels_for_frontend()
217
+ # Add fallback URLs for each channel
218
+ for ch in channels:
219
+ name = ch['name']
220
+ ch['fallback_url'] = XEMTV_CHANNELS.get(name, 'https://hd.xemtv.net/')
221
+ return JSONResponse({'channels': channels})
222
+
223
+ @app.get('/api/vtv/stream/{channel_name}')
224
+ def api_vtv_stream(channel_name: str):
225
+ """Get stream URL for a specific VTV channel."""
226
+ url = fetch_vtv_stream(channel_name.upper())
227
+ if url:
228
+ return JSONResponse({'url': url})
229
+ return JSONResponse({'url': None, 'fallback': XEMTV_CHANNELS.get(channel_name.upper(), 'https://hd.xemtv.net/')})
230
+
231
  def _wc2026_bg_refresh():
232
  time.sleep(10)
233
  while True: