bep40 commited on
Commit
d52af2c
·
verified ·
1 Parent(s): d199be8

Clean up app_main.py: remove unused VTV backend routes, keep match detail

Browse files
Files changed (1) hide show
  1. app_main.py +1 -24
app_main.py CHANGED
@@ -74,7 +74,7 @@ app.router.routes = [r for r in app.router.routes if not (
74
  (getattr(r, 'path', None) in ('/api/short/comments', '/api/short/comment'))
75
  )]
76
  app.routes[:] = [r for r in app.routes if not (
77
- hasattr(r, 'path') and getattr(r, 'path', None) == '/' and
78
  hasattr(r, 'methods') and 'GET' in getattr(r, 'methods', set())
79
  )]
80
 
@@ -98,21 +98,16 @@ def _storage():return JSONResponse({'persistent':os.path.isdir('/data') and os.a
98
  async def _share(url:str='',title:str='',img:str=''):
99
  return HTMLResponse(f'<!DOCTYPE html><html><head><meta property="og:title" content="{_clean(title)}"><meta property="og:image" content="{_clean(img)}"><meta http-equiv="refresh" content="0;url={_clean(url) or "/"}"></head><body>Redirecting...</body></html>')
100
 
101
- # Proxy page fetch (for xemtv.net CORS)
102
  @app.get('/api/proxy/page')
103
  def proxy_page(url: str = Query(...)):
104
- """Proxy fetch a page to avoid CORS."""
105
  try:
106
  r = req.get(url, headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36','Accept-Language':'vi-VN,vi;q=0.9','Referer':'https://hd.xemtv.net/'}, timeout=15)
107
  return HTMLResponse(content=r.text)
108
  except:
109
  return HTMLResponse(content='', status_code=502)
110
 
111
- # HLS Stream Proxy — adds proper Referer/Origin for fptplay CDN
112
  @app.get('/api/proxy/hls')
113
  def proxy_hls(url: str = Query(...)):
114
- """Proxy HLS manifest with proper Referer header for fptplay CDN.
115
- Rewrites segment URLs to route through our proxy."""
116
  try:
117
  headers = {
118
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
@@ -124,7 +119,6 @@ def proxy_hls(url: str = Query(...)):
124
  r = req.get(url, headers=headers, timeout=15)
125
  content_type = r.headers.get('Content-Type', 'application/vnd.apple.mpegurl')
126
  text = r.text
127
- # Rewrite segment URLs (.ts files and nested m3u8) to go through our proxy
128
  base_url = url.rsplit('/', 1)[0] + '/'
129
  def _rewrite_url(m):
130
  seg_url = m.group(0)
@@ -139,10 +133,8 @@ def proxy_hls(url: str = Query(...)):
139
  except:
140
  return HTMLResponse(content='', status_code=502)
141
 
142
- # Segment proxy for HLS segments
143
  @app.get('/api/proxy/seg')
144
  def proxy_seg(url: str = Query(...)):
145
- """Proxy individual HLS segment with proper headers."""
146
  try:
147
  headers = {
148
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
@@ -250,21 +242,6 @@ def api_match_detail_by_url(url: str = Query(...)):
250
  """Get match detail by full bongda.com.vn URL."""
251
  return JSONResponse(fetch_match_detail_by_url(url))
252
 
253
- # VTV Channels API
254
- from vtv_scraper import fetch_vtv_stream, get_all_vtv_streams
255
-
256
- @app.get('/api/vtv/streams')
257
- def api_vtv_streams():
258
- """Get all VTV channel streams."""
259
- channels = get_all_vtv_streams()
260
- return JSONResponse({'channels': channels})
261
-
262
- @app.get('/api/vtv/stream/{channel_name}')
263
- def api_vtv_stream(channel_name: str):
264
- """Get stream URL for a specific VTV channel."""
265
- stream = fetch_vtv_stream(channel_name)
266
- return JSONResponse({'stream_url': stream, 'channel': channel_name})
267
-
268
  def _wc2026_bg_refresh():
269
  time.sleep(10)
270
  while True:
 
74
  (getattr(r, 'path', None) in ('/api/short/comments', '/api/short/comment'))
75
  )]
76
  app.routes[:] = [r for r in app.routes if not (
77
+ hasattr(r, 'path') and getattr(r, 'path', None) == '/' and
78
  hasattr(r, 'methods') and 'GET' in getattr(r, 'methods', set())
79
  )]
80
 
 
98
  async def _share(url:str='',title:str='',img:str=''):
99
  return HTMLResponse(f'<!DOCTYPE html><html><head><meta property="og:title" content="{_clean(title)}"><meta property="og:image" content="{_clean(img)}"><meta http-equiv="refresh" content="0;url={_clean(url) or "/"}"></head><body>Redirecting...</body></html>')
100
 
 
101
  @app.get('/api/proxy/page')
102
  def proxy_page(url: str = Query(...)):
 
103
  try:
104
  r = req.get(url, headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36','Accept-Language':'vi-VN,vi;q=0.9','Referer':'https://hd.xemtv.net/'}, timeout=15)
105
  return HTMLResponse(content=r.text)
106
  except:
107
  return HTMLResponse(content='', status_code=502)
108
 
 
109
  @app.get('/api/proxy/hls')
110
  def proxy_hls(url: str = Query(...)):
 
 
111
  try:
112
  headers = {
113
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
 
119
  r = req.get(url, headers=headers, timeout=15)
120
  content_type = r.headers.get('Content-Type', 'application/vnd.apple.mpegurl')
121
  text = r.text
 
122
  base_url = url.rsplit('/', 1)[0] + '/'
123
  def _rewrite_url(m):
124
  seg_url = m.group(0)
 
133
  except:
134
  return HTMLResponse(content='', status_code=502)
135
 
 
136
  @app.get('/api/proxy/seg')
137
  def proxy_seg(url: str = Query(...)):
 
138
  try:
139
  headers = {
140
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
 
242
  """Get match detail by full bongda.com.vn URL."""
243
  return JSONResponse(fetch_match_detail_by_url(url))
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  def _wc2026_bg_refresh():
246
  time.sleep(10)
247
  while True: