bep40 commited on
Commit
501f7c8
·
verified ·
1 Parent(s): 2b0cb3a

fix: slider bdpOpen with 3 params + add slug; note on multi-part limitation

Browse files
Files changed (1) hide show
  1. app_wrapper.py +29 -19
app_wrapper.py CHANGED
@@ -1,5 +1,5 @@
1
  """Entry point: shorts carousel + TikTok-style video playback for ALL video sources."""
2
- import sys, os
3
 
4
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
5
  from shorts_carousel import scrape_24h_news_shorts, render_shorts_carousel, SHORTS_CSS, _extract_24h_video_url
@@ -48,14 +48,22 @@ if "shorts-feed-mode" not in app.CSS:
48
  if "FULLWIDTH: kill all Gradio padding" not in app.CSS:
49
  app.CSS += FULLWIDTH_CSS
50
 
51
- # ══ Fix homepage slider: replace bdpOpenTikTok with bdpOpen ══
52
  _orig_render_video_slider = getattr(app, 'render_video_slider_html', None)
53
  if _orig_render_video_slider:
54
  def _patched_render_video_slider(videos):
55
  html = _orig_render_video_slider(videos)
56
- # bdpOpenTikTok doesn't work. Replace with bdpOpen.
57
- # bdpOpenTikTok('url','aid') bdpOpen('url','aid','')
58
- html = html.replace("bdpOpenTikTok(", "bdpOpen(")
 
 
 
 
 
 
 
 
59
  return html
60
  app.render_video_slider_html = _patched_render_video_slider
61
 
@@ -94,7 +102,7 @@ def _patched_read_article(url):
94
  if not url or url == "#" or len(url) < 10:
95
  return "<p>Không tìm thấy bài viết.</p>"
96
 
97
- # 24h URLs → shorts/highlight TikTok feed
98
  if "24h.com.vn" in url:
99
  result = _render_24h_tiktok_feed(url)
100
  if result:
@@ -109,10 +117,9 @@ def _patched_read_article(url):
109
  return _orig_read_article(url)
110
 
111
  def _render_bdp_tiktok_feed(current_url):
112
- """Render BDP video in TikTok feed style (with other BDP videos)."""
113
  from concurrent.futures import ThreadPoolExecutor, as_completed
114
 
115
- # Get BDP video list
116
  try:
117
  bdp_list = app.scrape_bdp_video_list()[:15]
118
  except:
@@ -141,23 +148,27 @@ def _render_bdp_tiktok_feed(current_url):
141
  if not videos:
142
  return None
143
 
144
- return _build_tiktok_html(videos, current_url, "bdp")
145
 
146
  def _render_24h_tiktok_feed(current_url):
147
- """Render 24h video in TikTok feed style (with other 24h videos)."""
148
  from concurrent.futures import ThreadPoolExecutor, as_completed
149
 
150
- # Try shorts list first, then highlights
151
  try:
152
- all_articles = scrape_24h_news_shorts()[:15]
153
  except:
154
  all_articles = []
155
 
156
- if not all_articles:
 
157
  try:
158
- all_articles = app.scrape_24h_video_list()[:15]
159
- except:
160
- all_articles = []
 
 
 
161
 
162
  if not all_articles:
163
  return None
@@ -170,7 +181,7 @@ def _render_24h_tiktok_feed(current_url):
170
  return None
171
 
172
  videos = []
173
- with ThreadPoolExecutor(max_workers=6) as ex:
174
  futures = {ex.submit(_fetch_video, a): a for a in all_articles}
175
  for f in as_completed(futures):
176
  try:
@@ -184,8 +195,7 @@ def _render_24h_tiktok_feed(current_url):
184
  return _build_tiktok_html(videos, current_url, "24h")
185
 
186
  def _build_tiktok_html(videos, current_url, source_label):
187
- """Build TikTok feed HTML from video list. Clicked video placed first."""
188
- # Reorder: clicked video first
189
  current_aid = app.make_id(current_url)
190
  ordered = []
191
  rest = []
 
1
  """Entry point: shorts carousel + TikTok-style video playback for ALL video sources."""
2
+ import sys, os, re as _re
3
 
4
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
5
  from shorts_carousel import scrape_24h_news_shorts, render_shorts_carousel, SHORTS_CSS, _extract_24h_video_url
 
48
  if "FULLWIDTH: kill all Gradio padding" not in app.CSS:
49
  app.CSS += FULLWIDTH_CSS
50
 
51
+ # ══ Fix homepage slider: bdpOpenTikTok bdpOpen with 3 params ══
52
  _orig_render_video_slider = getattr(app, 'render_video_slider_html', None)
53
  if _orig_render_video_slider:
54
  def _patched_render_video_slider(videos):
55
  html = _orig_render_video_slider(videos)
56
+ # Replace bdpOpenTikTok('url','aid') with bdpOpen('url','aid','')
57
+ # The original has: window.bdpOpenTikTok('url','aid')
58
+ # We need: window.bdpOpen('url','aid','')
59
+ html = html.replace("window.bdpOpenTikTok(", "window.bdpOpen(")
60
+ # Now fix: bdpOpen('url','aid') needs third param → add ,'')
61
+ # Pattern: bdpOpen('...','...') → bdpOpen('...','...','')
62
+ html = _re.sub(
63
+ r"window\.bdpOpen\('([^']+)','([^']+)'\)",
64
+ r"window.bdpOpen('\1','\2','')",
65
+ html
66
+ )
67
  return html
68
  app.render_video_slider_html = _patched_render_video_slider
69
 
 
102
  if not url or url == "#" or len(url) < 10:
103
  return "<p>Không tìm thấy bài viết.</p>"
104
 
105
+ # 24h URLs → TikTok feed with all 24h highlight videos
106
  if "24h.com.vn" in url:
107
  result = _render_24h_tiktok_feed(url)
108
  if result:
 
117
  return _orig_read_article(url)
118
 
119
  def _render_bdp_tiktok_feed(current_url):
120
+ """Render BDP video in TikTok feed style."""
121
  from concurrent.futures import ThreadPoolExecutor, as_completed
122
 
 
123
  try:
124
  bdp_list = app.scrape_bdp_video_list()[:15]
125
  except:
 
148
  if not videos:
149
  return None
150
 
151
+ return _build_tiktok_html(videos, current_url, "BDP")
152
 
153
  def _render_24h_tiktok_feed(current_url):
154
+ """Render 24h video in TikTok feed style using highlight list (more videos)."""
155
  from concurrent.futures import ThreadPoolExecutor, as_completed
156
 
157
+ # Use highlight list (has more video content than shorts)
158
  try:
159
+ all_articles = app.scrape_24h_video_list()[:20]
160
  except:
161
  all_articles = []
162
 
163
+ # Also add shorts if highlight list is short
164
+ if len(all_articles) < 10:
165
  try:
166
+ shorts = scrape_24h_news_shorts()[:10]
167
+ seen = {a["link"] for a in all_articles}
168
+ for s in shorts:
169
+ if s["link"] not in seen:
170
+ all_articles.append(s)
171
+ except: pass
172
 
173
  if not all_articles:
174
  return None
 
181
  return None
182
 
183
  videos = []
184
+ with ThreadPoolExecutor(max_workers=8) as ex:
185
  futures = {ex.submit(_fetch_video, a): a for a in all_articles}
186
  for f in as_completed(futures):
187
  try:
 
195
  return _build_tiktok_html(videos, current_url, "24h")
196
 
197
  def _build_tiktok_html(videos, current_url, source_label):
198
+ """Build TikTok feed HTML. Clicked video placed first."""
 
199
  current_aid = app.make_id(current_url)
200
  ordered = []
201
  rest = []