Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,12 +48,25 @@ def sec_to_hms(sec: int) -> str:
|
|
48 |
return f"{h:02d}:{m:02d}:{s:02d}"
|
49 |
|
50 |
def download_audio(url: str, out_path: Path) -> Path:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
opts = {
|
52 |
"format": "bestaudio/best",
|
53 |
"outtmpl": str(out_path.with_suffix(".%(ext)s")),
|
54 |
-
"
|
55 |
"quiet": True,
|
56 |
}
|
|
|
|
|
57 |
with YoutubeDL(opts) as ydl:
|
58 |
info = ydl.extract_info(url, download=True)
|
59 |
filename = ydl.prepare_filename(info)
|
|
|
48 |
return f"{h:02d}:{m:02d}:{s:02d}"
|
49 |
|
50 |
def download_audio(url: str, out_path: Path) -> Path:
|
51 |
+
"""
|
52 |
+
Download best audio via yt_dlp, always using cookies.txt in the repo root.
|
53 |
+
"""
|
54 |
+
repo_root = Path(__file__).parent
|
55 |
+
cookie_path = repo_root / "cookies.txt"
|
56 |
+
if not cookie_path.is_file() or cookie_path.stat().st_size == 0:
|
57 |
+
raise FileNotFoundError(
|
58 |
+
f"No valid cookies.txt found at {cookie_path}. "
|
59 |
+
f"Make sure you uploaded your Netscape-format cookie jar."
|
60 |
+
)
|
61 |
+
|
62 |
opts = {
|
63 |
"format": "bestaudio/best",
|
64 |
"outtmpl": str(out_path.with_suffix(".%(ext)s")),
|
65 |
+
"cookiefile": str(cookie_path),
|
66 |
"quiet": True,
|
67 |
}
|
68 |
+
print(f"[download_audio] using cookiefile: {opts['cookiefile']}")
|
69 |
+
|
70 |
with YoutubeDL(opts) as ydl:
|
71 |
info = ydl.extract_info(url, download=True)
|
72 |
filename = ydl.prepare_filename(info)
|