Spaces:
Sleeping
Sleeping
Screenshots via yt-dlp clip download over HTTPS proxy (ffmpeg local); trust proxy CA for yt-dlp
Browse files
app.py
CHANGED
|
@@ -36,8 +36,8 @@ def _install_proxy_ca() -> None:
|
|
| 36 |
roots = fh.read()
|
| 37 |
with open(bundle, "w", encoding="utf-8") as fh:
|
| 38 |
fh.write(roots.rstrip() + "\n" + ca + "\n")
|
| 39 |
-
os.environ["REQUESTS_CA_BUNDLE"] = bundle
|
| 40 |
-
os.environ["SSL_CERT_FILE"] = bundle
|
| 41 |
except Exception:
|
| 42 |
pass
|
| 43 |
|
|
@@ -262,17 +262,6 @@ def run_pipeline(topic, hf_token, yt_api_key, llm_model, vlm_model,
|
|
| 262 |
yield (status(f"Transcript ready ({len(segs)} segments)."),
|
| 263 |
ranking, gr.update(value=transcript), gr.update())
|
| 264 |
|
| 265 |
-
# 4. Resolve a stream URL for screenshots (best-effort) ----------------------
|
| 266 |
-
progress(0.45, desc="Resolving stream")
|
| 267 |
-
stream_url = None
|
| 268 |
-
try:
|
| 269 |
-
stream_url, _ = frames_mod.get_stream_url(best["video_id"], cookiefile, proxy)
|
| 270 |
-
except Exception as exc:
|
| 271 |
-
yield (status(f"⚠️ Couldn't resolve a video stream for screenshots "
|
| 272 |
-
f"({type(exc).__name__}) — producing a **text-only** tutorial. "
|
| 273 |
-
"Set YT_PROXY/YT_COOKIES secrets to enable screenshots."),
|
| 274 |
-
ranking, gr.update(value=transcript), gr.update())
|
| 275 |
-
|
| 276 |
# 5. Tutorial text -----------------------------------------------------------
|
| 277 |
progress(0.6, desc="Writing tutorial")
|
| 278 |
keywords = _collect_keywords(primary_kw, secondary_kw)
|
|
@@ -286,15 +275,22 @@ def run_pipeline(topic, hf_token, yt_api_key, llm_model, vlm_model,
|
|
| 286 |
yield (status(f"🔑 Primary keyword '{keywords['primary']}' appears {n}× in the post."),
|
| 287 |
ranking, gr.update(value=transcript), gr.update())
|
| 288 |
|
| 289 |
-
# 6. Screenshots (weighted timestamps ->
|
| 290 |
selected, caps = {}, {}
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
| 292 |
progress(0.75, desc="Screenshots")
|
| 293 |
-
times = frames_mod.compute_shot_times(
|
| 294 |
-
tut["steps"], segs, w_llm=float(w_llm), w_whisper=float(w_whisper),
|
| 295 |
-
lead=float(lead), max_shots=int(max_shots))
|
| 296 |
yield status(f"🎞️ Capturing {len(times)} screenshots at weighted timestamps…"), ranking, gr.update(value=transcript), gr.update()
|
| 297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
if selected:
|
| 299 |
progress(0.88, desc="Captioning")
|
| 300 |
yield status(f"✍️ Captioning {len(selected)} screenshots with `{vlm_model}`…"), ranking, gr.update(value=transcript), gr.update()
|
|
|
|
| 36 |
roots = fh.read()
|
| 37 |
with open(bundle, "w", encoding="utf-8") as fh:
|
| 38 |
fh.write(roots.rstrip() + "\n" + ca + "\n")
|
| 39 |
+
os.environ["REQUESTS_CA_BUNDLE"] = bundle # requests / youtube-transcript-api
|
| 40 |
+
os.environ["SSL_CERT_FILE"] = bundle # stdlib ssl + yt-dlp (see frames.py)
|
| 41 |
except Exception:
|
| 42 |
pass
|
| 43 |
|
|
|
|
| 262 |
yield (status(f"Transcript ready ({len(segs)} segments)."),
|
| 263 |
ranking, gr.update(value=transcript), gr.update())
|
| 264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
# 5. Tutorial text -----------------------------------------------------------
|
| 266 |
progress(0.6, desc="Writing tutorial")
|
| 267 |
keywords = _collect_keywords(primary_kw, secondary_kw)
|
|
|
|
| 275 |
yield (status(f"🔑 Primary keyword '{keywords['primary']}' appears {n}× in the post."),
|
| 276 |
ranking, gr.update(value=transcript), gr.update())
|
| 277 |
|
| 278 |
+
# 6. Screenshots (weighted timestamps -> yt-dlp clip download -> ffmpeg) ------
|
| 279 |
selected, caps = {}, {}
|
| 280 |
+
times = frames_mod.compute_shot_times(
|
| 281 |
+
tut["steps"], segs, w_llm=float(w_llm), w_whisper=float(w_whisper),
|
| 282 |
+
lead=float(lead), max_shots=int(max_shots))
|
| 283 |
+
if times:
|
| 284 |
progress(0.75, desc="Screenshots")
|
|
|
|
|
|
|
|
|
|
| 285 |
yield status(f"🎞️ Capturing {len(times)} screenshots at weighted timestamps…"), ranking, gr.update(value=transcript), gr.update()
|
| 286 |
+
try:
|
| 287 |
+
selected = frames_mod.capture_shots(
|
| 288 |
+
times, best["video_id"], frames_dir, cookiefile, proxy, progress)
|
| 289 |
+
except Exception as exc:
|
| 290 |
+
yield (status(f"⚠️ Couldn't fetch screenshots ({type(exc).__name__}) — "
|
| 291 |
+
"producing a **text-only** tutorial. Ensure `YT_PROXY` is set "
|
| 292 |
+
"(HTTPS proxy) so yt-dlp can download clips."),
|
| 293 |
+
ranking, gr.update(value=transcript), gr.update())
|
| 294 |
if selected:
|
| 295 |
progress(0.88, desc="Captioning")
|
| 296 |
yield status(f"✍️ Captioning {len(selected)} screenshots with `{vlm_model}`…"), ranking, gr.update(value=transcript), gr.update()
|