Spaces:
Sleeping
Sleeping
Devank Upadhyaya commited on
Commit ·
41410d8
1
Parent(s): 689d01c
Add ffmpeg and yt-dlp timeout
Browse files- Dockerfile +2 -1
- tools.py +15 -7
Dockerfile
CHANGED
|
@@ -6,10 +6,11 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
|
| 6 |
# Set the working directory to /app
|
| 7 |
WORKDIR /app
|
| 8 |
|
| 9 |
-
# Install system dependencies required for MediaPipe and
|
| 10 |
RUN apt-get update && apt-get install -y \
|
| 11 |
libgl1 \
|
| 12 |
libglib2.0-0 \
|
|
|
|
| 13 |
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
# Copy the final requirements file into the container
|
|
|
|
| 6 |
# Set the working directory to /app
|
| 7 |
WORKDIR /app
|
| 8 |
|
| 9 |
+
# Install system dependencies required for MediaPipe, OpenCV, and video processing
|
| 10 |
RUN apt-get update && apt-get install -y \
|
| 11 |
libgl1 \
|
| 12 |
libglib2.0-0 \
|
| 13 |
+
ffmpeg \
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
|
| 16 |
# Copy the final requirements file into the container
|
tools.py
CHANGED
|
@@ -147,15 +147,23 @@ def download_youtube_video(url: str, out_path: str) -> str:
|
|
| 147 |
for fmt in format_options:
|
| 148 |
cmd = ["yt-dlp", "-f", fmt, "--no-playlist", "--no-warnings", "-o", out_path, url]
|
| 149 |
logger.debug(f"Trying yt-dlp format: {fmt}")
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
fallback_template = out_path.replace(".mp4", ".%(ext)s")
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
base = out_path.replace(".mp4", "")
|
| 160 |
possible = [f"{base}.{ext}" for ext in ["mp4", "webm", "mkv", "avi", "mov"]]
|
| 161 |
for p in possible:
|
|
|
|
| 147 |
for fmt in format_options:
|
| 148 |
cmd = ["yt-dlp", "-f", fmt, "--no-playlist", "--no-warnings", "-o", out_path, url]
|
| 149 |
logger.debug(f"Trying yt-dlp format: {fmt}")
|
| 150 |
+
try:
|
| 151 |
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
|
| 152 |
+
if result.returncode == 0 and os.path.exists(out_path):
|
| 153 |
+
logger.debug(f"Download succeeded: {fmt}")
|
| 154 |
+
return out_path
|
| 155 |
+
last_error = result.stderr
|
| 156 |
+
except subprocess.TimeoutExpired as e:
|
| 157 |
+
last_error = f"Timeout for format {fmt}: {e}"
|
| 158 |
+
logger.error(last_error)
|
| 159 |
|
| 160 |
fallback_template = out_path.replace(".mp4", ".%(ext)s")
|
| 161 |
+
try:
|
| 162 |
+
subprocess.run(["yt-dlp", "--no-playlist", "--no-warnings", "-o", fallback_template, url],
|
| 163 |
+
capture_output=True, text=True, timeout=60)
|
| 164 |
+
except subprocess.TimeoutExpired as e:
|
| 165 |
+
logger.error(f"Fallback timeout: {e}")
|
| 166 |
+
|
| 167 |
base = out_path.replace(".mp4", "")
|
| 168 |
possible = [f"{base}.{ext}" for ext in ["mp4", "webm", "mkv", "avi", "mov"]]
|
| 169 |
for p in possible:
|