Spaces:
Running
Running
revert: app_wrapper.py back to previous version (before 3:4 change)
Browse files- app_wrapper.py +24 -23
app_wrapper.py
CHANGED
|
@@ -8,12 +8,12 @@ import app
|
|
| 8 |
|
| 9 |
# ββ CSS Patches ββ
|
| 10 |
SHORTS_EXTRA_CSS = """
|
| 11 |
-
/*
|
| 12 |
-
.
|
| 13 |
/* TikTok feed fullwidth */
|
| 14 |
.tiktok-fullscreen-container{width:100%!important;max-width:100%!important;border-radius:0!important}
|
| 15 |
-
/* Fullheight toggle
|
| 16 |
-
.tiktok-fullscreen-container.
|
| 17 |
.tiktok-fullheight-btn{position:absolute;bottom:70px;right:12px;background:rgba(255,255,255,.15);color:#fff;border:none;padding:6px 12px;border-radius:16px;font-size:11px;cursor:pointer;z-index:8;backdrop-filter:blur(6px)}
|
| 18 |
.tiktok-fullheight-btn.active{background:rgba(92,184,122,.5)}
|
| 19 |
"""
|
|
@@ -43,11 +43,21 @@ div[class*="svelte"]{padding-left:0!important;padding-right:0!important}
|
|
| 43 |
|
| 44 |
if "vslide-shorts-item" not in app.CSS:
|
| 45 |
app.CSS += SHORTS_CSS
|
| 46 |
-
if "
|
| 47 |
app.CSS += SHORTS_EXTRA_CSS
|
| 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:
|
|
@@ -82,22 +92,11 @@ def _patched_render_homepage(articles, *args, **kwargs):
|
|
| 82 |
return html
|
| 83 |
app.render_homepage_html = _patched_render_homepage
|
| 84 |
|
| 85 |
-
# ββ
|
| 86 |
-
def _fixed_extract_24h_video_urls(article_url):
|
| 87 |
-
vid = _extract_24h_video_url(article_url)
|
| 88 |
-
if not vid:
|
| 89 |
-
return []
|
| 90 |
-
all_parts = vid.get("all_parts", [vid["src"]])
|
| 91 |
-
poster = vid.get("poster", "")
|
| 92 |
-
return [{"src": p, "poster": poster, "vtype": "hls"} for p in all_parts]
|
| 93 |
-
app._extract_24h_video_urls = _fixed_extract_24h_video_urls
|
| 94 |
-
|
| 95 |
-
# ββ Patch render_video_page_html: contain toggle button (default is 3:4 cover) ββ
|
| 96 |
_orig_render_video_page = app.render_video_page_html
|
| 97 |
def _patched_render_video_page():
|
| 98 |
html = _orig_render_video_page()
|
| 99 |
-
|
| 100 |
-
toggle_btn = '<button class="tiktok-fullheight-btn" onclick="event.stopPropagation();var c=this.closest(\'.tiktok-fullscreen-container\');c.classList.toggle(\'contain-mode\');var on=c.classList.contains(\'contain-mode\');c.querySelectorAll(\'.tiktok-fullheight-btn\').forEach(function(b){b.classList.toggle(\'active\',on);b.textContent=on?\'\\u2922 3:4\':\'\\u2B07 Contain\';});">\u2B07 Contain</button>'
|
| 101 |
html = html.replace('<div class="tiktok-unmute-hint"', toggle_btn + '<div class="tiktok-unmute-hint"')
|
| 102 |
return html
|
| 103 |
app.render_video_page_html = _patched_render_video_page
|
|
@@ -145,7 +144,6 @@ def _render_bdp_tiktok_feed(current_url):
|
|
| 145 |
return _build_tiktok_html(videos, current_url, "BDP")
|
| 146 |
|
| 147 |
def _render_24h_tiktok_feed(current_url):
|
| 148 |
-
"""Render 24h highlight video in TikTok feed. Multi-part expanded."""
|
| 149 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 150 |
try:
|
| 151 |
all_articles = app.scrape_24h_video_list()[:20]
|
|
@@ -201,6 +199,7 @@ def _build_tiktok_html(videos, current_url, source_label):
|
|
| 201 |
ordered.extend(rest)
|
| 202 |
|
| 203 |
badge_cls = "bdp-badge-24h" if source_label == "24h" else "bdp-badge-bdp"
|
|
|
|
| 204 |
|
| 205 |
slides = []
|
| 206 |
for vi, v in enumerate(ordered):
|
|
@@ -215,8 +214,9 @@ def _build_tiktok_html(videos, current_url, source_label):
|
|
| 215 |
else:
|
| 216 |
vtag = f'<video class="tiktok-video" playsinline preload="metadata"{poster_attr} muted loop><source src="{app.safe_url(vsrc)}" type="video/mp4"></video>'
|
| 217 |
|
| 218 |
-
|
| 219 |
-
|
|
|
|
| 220 |
|
| 221 |
slides.append(f'''<div class="tiktok-slide" data-index="{vi}" data-aid="{aid}">
|
| 222 |
{vtag}
|
|
@@ -232,7 +232,7 @@ def _build_tiktok_html(videos, current_url, source_label):
|
|
| 232 |
<button class="tiktok-action-btn" onclick="{share_js}">\U0001f4e4 Chia s\u1ebb</button>
|
| 233 |
</div>
|
| 234 |
</div>
|
| 235 |
-
{
|
| 236 |
<div class="tiktok-unmute-hint" onclick="window.bdpTikTokUnmute(this)">\U0001f507 B\u1eadt ti\u1ebfng</div>
|
| 237 |
<span class="tiktok-counter">{vi+1}/{len(ordered)}</span>
|
| 238 |
</div>''')
|
|
@@ -251,7 +251,8 @@ def _build_tiktok_html(videos, current_url, source_label):
|
|
| 251 |
grid_html = f'''<div class="bdp-wrap"><div class="bdp-topbar"><span>\U0001f3ac Video</span><span>{len(ordered)} video</span></div>
|
| 252 |
<div class="bdp-grid">{''.join(list_cards)}</div></div>'''
|
| 253 |
|
| 254 |
-
|
|
|
|
| 255 |
<div class="tiktok-fullscreen-feed">{''.join(slides)}</div>
|
| 256 |
</div>
|
| 257 |
{grid_html}'''
|
|
|
|
| 8 |
|
| 9 |
# ββ CSS Patches ββ
|
| 10 |
SHORTS_EXTRA_CSS = """
|
| 11 |
+
/* Shorts feed: video 9:16 crop center */
|
| 12 |
+
.shorts-feed-mode .tiktok-video{object-fit:cover!important}
|
| 13 |
/* TikTok feed fullwidth */
|
| 14 |
.tiktok-fullscreen-container{width:100%!important;max-width:100%!important;border-radius:0!important}
|
| 15 |
+
/* Fullheight toggle for highlight */
|
| 16 |
+
.tiktok-fullscreen-container.fullheight-mode .tiktok-video{object-fit:cover!important}
|
| 17 |
.tiktok-fullheight-btn{position:absolute;bottom:70px;right:12px;background:rgba(255,255,255,.15);color:#fff;border:none;padding:6px 12px;border-radius:16px;font-size:11px;cursor:pointer;z-index:8;backdrop-filter:blur(6px)}
|
| 18 |
.tiktok-fullheight-btn.active{background:rgba(92,184,122,.5)}
|
| 19 |
"""
|
|
|
|
| 43 |
|
| 44 |
if "vslide-shorts-item" not in app.CSS:
|
| 45 |
app.CSS += SHORTS_CSS
|
| 46 |
+
if "shorts-feed-mode" not in app.CSS:
|
| 47 |
app.CSS += SHORTS_EXTRA_CSS
|
| 48 |
if "FULLWIDTH: kill all Gradio padding" not in app.CSS:
|
| 49 |
app.CSS += FULLWIDTH_CSS
|
| 50 |
|
| 51 |
+
# ββ Override app._extract_24h_video_urls with fixed multi-part version ββ
|
| 52 |
+
def _fixed_extract_24h_video_urls(article_url):
|
| 53 |
+
vid = _extract_24h_video_url(article_url)
|
| 54 |
+
if not vid:
|
| 55 |
+
return []
|
| 56 |
+
all_parts = vid.get("all_parts", [vid["src"]])
|
| 57 |
+
poster = vid.get("poster", "")
|
| 58 |
+
return [{"src": p, "poster": poster, "vtype": "hls"} for p in all_parts]
|
| 59 |
+
app._extract_24h_video_urls = _fixed_extract_24h_video_urls
|
| 60 |
+
|
| 61 |
# ββ Fix homepage slider: bdpOpenTikTok β bdpOpen with 3 params ββ
|
| 62 |
_orig_render_video_slider = getattr(app, 'render_video_slider_html', None)
|
| 63 |
if _orig_render_video_slider:
|
|
|
|
| 92 |
return html
|
| 93 |
app.render_homepage_html = _patched_render_homepage
|
| 94 |
|
| 95 |
+
# ββ Patch render_video_page_html: fullheight button ββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
_orig_render_video_page = app.render_video_page_html
|
| 97 |
def _patched_render_video_page():
|
| 98 |
html = _orig_render_video_page()
|
| 99 |
+
toggle_btn = '<button class="tiktok-fullheight-btn" onclick="event.stopPropagation();var c=this.closest(\'.tiktok-fullscreen-container\');c.classList.toggle(\'fullheight-mode\');var on=c.classList.contains(\'fullheight-mode\');c.querySelectorAll(\'.tiktok-fullheight-btn\').forEach(function(b){b.classList.toggle(\'active\',on);b.textContent=on?\'\\u2B07 Contain\':\'\\u2922 Fullheight\';});">\u2922 Fullheight</button>'
|
|
|
|
| 100 |
html = html.replace('<div class="tiktok-unmute-hint"', toggle_btn + '<div class="tiktok-unmute-hint"')
|
| 101 |
return html
|
| 102 |
app.render_video_page_html = _patched_render_video_page
|
|
|
|
| 144 |
return _build_tiktok_html(videos, current_url, "BDP")
|
| 145 |
|
| 146 |
def _render_24h_tiktok_feed(current_url):
|
|
|
|
| 147 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 148 |
try:
|
| 149 |
all_articles = app.scrape_24h_video_list()[:20]
|
|
|
|
| 199 |
ordered.extend(rest)
|
| 200 |
|
| 201 |
badge_cls = "bdp-badge-24h" if source_label == "24h" else "bdp-badge-bdp"
|
| 202 |
+
is_shorts = source_label == "24h"
|
| 203 |
|
| 204 |
slides = []
|
| 205 |
for vi, v in enumerate(ordered):
|
|
|
|
| 214 |
else:
|
| 215 |
vtag = f'<video class="tiktok-video" playsinline preload="metadata"{poster_attr} muted loop><source src="{app.safe_url(vsrc)}" type="video/mp4"></video>'
|
| 216 |
|
| 217 |
+
fullheight_btn = ''
|
| 218 |
+
if not is_shorts:
|
| 219 |
+
fullheight_btn = '<button class="tiktok-fullheight-btn" onclick="event.stopPropagation();var c=this.closest(\'.tiktok-fullscreen-container\');c.classList.toggle(\'fullheight-mode\');var on=c.classList.contains(\'fullheight-mode\');c.querySelectorAll(\'.tiktok-fullheight-btn\').forEach(function(b){b.classList.toggle(\'active\',on);b.textContent=on?\'\\u2B07 Contain\':\'\\u2922 Fullheight\';});">\u2922 Fullheight</button>'
|
| 220 |
|
| 221 |
slides.append(f'''<div class="tiktok-slide" data-index="{vi}" data-aid="{aid}">
|
| 222 |
{vtag}
|
|
|
|
| 232 |
<button class="tiktok-action-btn" onclick="{share_js}">\U0001f4e4 Chia s\u1ebb</button>
|
| 233 |
</div>
|
| 234 |
</div>
|
| 235 |
+
{fullheight_btn}
|
| 236 |
<div class="tiktok-unmute-hint" onclick="window.bdpTikTokUnmute(this)">\U0001f507 B\u1eadt ti\u1ebfng</div>
|
| 237 |
<span class="tiktok-counter">{vi+1}/{len(ordered)}</span>
|
| 238 |
</div>''')
|
|
|
|
| 251 |
grid_html = f'''<div class="bdp-wrap"><div class="bdp-topbar"><span>\U0001f3ac Video</span><span>{len(ordered)} video</span></div>
|
| 252 |
<div class="bdp-grid">{''.join(list_cards)}</div></div>'''
|
| 253 |
|
| 254 |
+
mode_class = "shorts-feed-mode" if is_shorts else ""
|
| 255 |
+
return f'''<div class="tiktok-fullscreen-container {mode_class}" id="tiktok-fullscreen-feed">
|
| 256 |
<div class="tiktok-fullscreen-feed">{''.join(slides)}</div>
|
| 257 |
</div>
|
| 258 |
{grid_html}'''
|