Update neorvc/main_cli.py
Browse files- neorvc/main_cli.py +16 -9
neorvc/main_cli.py
CHANGED
@@ -60,39 +60,46 @@ def get_youtube_video_id(url: str, ignore_playlist: bool = True) -> str | None:
|
|
60 |
return parsed.path.split("/")[-1]
|
61 |
return None
|
62 |
|
63 |
-
async def yt_download(
|
|
|
|
|
|
|
|
|
64 |
if not os.path.exists(cookies_path):
|
65 |
raise FileNotFoundError(f"Cookies file not found: {cookies_path}")
|
66 |
|
67 |
-
video_id = get_youtube_video_id(
|
68 |
if not video_id:
|
69 |
raise ValueError("Invalid YouTube URL: could not extract video ID.")
|
70 |
|
71 |
-
output_file = os.path.join(OUTPUT_DIR, f"{video_id}.
|
72 |
if os.path.exists(output_file):
|
73 |
return Path(output_file)
|
74 |
|
75 |
handle_progress(progress, description="Downloading YouTube audio", value=10)
|
76 |
|
|
|
|
|
77 |
cmd = [
|
78 |
"yt-dlp",
|
79 |
"--format", "bestaudio/best",
|
80 |
"--extract-audio",
|
81 |
-
"--audio-format", "
|
82 |
-
"--audio-quality", "
|
|
|
83 |
"--cookies", str(cookies_path),
|
84 |
-
"--output",
|
85 |
"--no-check-certificate",
|
86 |
-
|
87 |
]
|
88 |
|
89 |
process = await asyncio.create_subprocess_exec(
|
90 |
*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
91 |
)
|
92 |
-
await process.communicate()
|
93 |
|
94 |
if process.returncode != 0:
|
95 |
-
raise RuntimeError("yt-dlp failed")
|
96 |
|
97 |
if not os.path.exists(output_file):
|
98 |
raise RuntimeError(f"Downloaded file not found: {output_file}")
|
|
|
60 |
return parsed.path.split("/")[-1]
|
61 |
return None
|
62 |
|
63 |
+
async def yt_download(
|
64 |
+
url: str,
|
65 |
+
cookies_path: str = os.path.join(BASE_DIR, "neorvc", "config.txt"),
|
66 |
+
progress: Optional[Union['tqdm', 'GradioProgress']] = None
|
67 |
+
) -> Path:
|
68 |
if not os.path.exists(cookies_path):
|
69 |
raise FileNotFoundError(f"Cookies file not found: {cookies_path}")
|
70 |
|
71 |
+
video_id = get_youtube_video_id(url)
|
72 |
if not video_id:
|
73 |
raise ValueError("Invalid YouTube URL: could not extract video ID.")
|
74 |
|
75 |
+
output_file = os.path.join(OUTPUT_DIR, f"{video_id}.wav")
|
76 |
if os.path.exists(output_file):
|
77 |
return Path(output_file)
|
78 |
|
79 |
handle_progress(progress, description="Downloading YouTube audio", value=10)
|
80 |
|
81 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
82 |
+
|
83 |
cmd = [
|
84 |
"yt-dlp",
|
85 |
"--format", "bestaudio/best",
|
86 |
"--extract-audio",
|
87 |
+
"--audio-format", "wav",
|
88 |
+
"--audio-quality", "0", # highest quality for wav
|
89 |
+
"--postprocessor-args", "-acodec pcm_f32le",
|
90 |
"--cookies", str(cookies_path),
|
91 |
+
"--output", output_file,
|
92 |
"--no-check-certificate",
|
93 |
+
url
|
94 |
]
|
95 |
|
96 |
process = await asyncio.create_subprocess_exec(
|
97 |
*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
98 |
)
|
99 |
+
stdout, stderr = await process.communicate()
|
100 |
|
101 |
if process.returncode != 0:
|
102 |
+
raise RuntimeError(f"yt-dlp failed: {stderr.decode().strip()}")
|
103 |
|
104 |
if not os.path.exists(output_file):
|
105 |
raise RuntimeError(f"Downloaded file not found: {output_file}")
|