Spaces:
Build error
Build error
CB commited on
Update streamlit_app.py
Browse files- streamlit_app.py +12 -5
streamlit_app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
import json
|
|
@@ -72,7 +73,11 @@ def convert_video_to_mp4(video_path: str) -> str:
|
|
| 72 |
target_path = str(Path(video_path).with_suffix(".mp4"))
|
| 73 |
if os.path.exists(target_path):
|
| 74 |
return target_path
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
try:
|
| 77 |
os.remove(video_path)
|
| 78 |
except Exception:
|
|
@@ -89,10 +94,12 @@ def download_video_ytdlp(url: str, save_dir: str, video_password: str = None) ->
|
|
| 89 |
if video_password:
|
| 90 |
ydl_opts["videopassword"] = video_password
|
| 91 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 92 |
-
ydl.
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
if
|
|
|
|
|
|
|
| 96 |
matches = sorted(glob(os.path.join(save_dir, "*")), key=os.path.getmtime, reverse=True)[:1]
|
| 97 |
if not matches:
|
| 98 |
raise FileNotFoundError("Downloaded video not found")
|
|
|
|
| 1 |
+
# streamlit_app.py
|
| 2 |
import os
|
| 3 |
import time
|
| 4 |
import json
|
|
|
|
| 73 |
target_path = str(Path(video_path).with_suffix(".mp4"))
|
| 74 |
if os.path.exists(target_path):
|
| 75 |
return target_path
|
| 76 |
+
try:
|
| 77 |
+
ffmpeg.input(video_path).output(target_path).run(overwrite_output=True, quiet=True)
|
| 78 |
+
except Exception as e:
|
| 79 |
+
# If ffmpeg binary missing or conversion fails, re-raise with hint
|
| 80 |
+
raise RuntimeError(f"ffmpeg conversion failed: {e}")
|
| 81 |
try:
|
| 82 |
os.remove(video_path)
|
| 83 |
except Exception:
|
|
|
|
| 94 |
if video_password:
|
| 95 |
ydl_opts["videopassword"] = video_password
|
| 96 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 97 |
+
info = ydl.extract_info(url, download=True)
|
| 98 |
+
# Prefer returned id/filename
|
| 99 |
+
video_id = info.get("id") if isinstance(info, dict) else None
|
| 100 |
+
if video_id:
|
| 101 |
+
matches = glob(os.path.join(save_dir, f"{video_id}.*"))
|
| 102 |
+
else:
|
| 103 |
matches = sorted(glob(os.path.join(save_dir, "*")), key=os.path.getmtime, reverse=True)[:1]
|
| 104 |
if not matches:
|
| 105 |
raise FileNotFoundError("Downloaded video not found")
|