Spaces:
Runtime error
Runtime error
Commit
·
a44f2df
1
Parent(s):
91ba404
Update app_multi.py
Browse files- app_multi.py +47 -28
app_multi.py
CHANGED
@@ -419,34 +419,51 @@ def youtube_downloader(
|
|
419 |
url_base="",
|
420 |
quiet=False,
|
421 |
force=True,
|
|
|
422 |
):
|
423 |
-
|
424 |
-
|
425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
return output_path
|
427 |
else:
|
428 |
-
|
429 |
-
|
430 |
-
quiet = "--quiet --no-warnings" if quiet else ""
|
431 |
-
command = f"""
|
432 |
-
yt-dlp {quiet} -x --audio-format wav -f bestaudio -o "{output_filename}" --download-sections "*{start_time}-{end_time}" "{url_base}{video_identifier}" # noqa: E501
|
433 |
-
""".strip()
|
434 |
-
|
435 |
-
attempts = 0
|
436 |
-
while True:
|
437 |
-
try:
|
438 |
-
_ = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
|
439 |
-
except subprocess.CalledProcessError:
|
440 |
-
attempts += 1
|
441 |
-
if attempts == num_attempts:
|
442 |
-
return None
|
443 |
-
else:
|
444 |
-
break
|
445 |
-
|
446 |
-
if output_path.exists():
|
447 |
-
return output_path
|
448 |
-
else:
|
449 |
-
return None
|
450 |
|
451 |
def audio_separated(audio_input, progress=gr.Progress()):
|
452 |
# start progress
|
@@ -689,8 +706,10 @@ with app:
|
|
689 |
with gr.Row():
|
690 |
with gr.Column():
|
691 |
ydl_url_input = gr.Textbox(label="音乐视频网址(可直接填写相应的BV号)", value = "https://www.bilibili.com/video/BV...")
|
692 |
-
|
693 |
-
|
|
|
|
|
694 |
with gr.Accordion('搜索歌曲名上传', open=False):
|
695 |
search_name = gr.Dropdown(label="通过歌曲名搜索", info="选一首您喜欢的歌曲吧", choices=["周杰伦晴天","周杰伦兰亭序","周杰伦七里香","周杰伦花海","周杰伦反方向的钟","周杰伦一路向北","周杰伦稻香","周杰伦明明就","周杰伦爱在西元前","孙燕姿逆光","陈奕迅富士山下","许嵩有何不可","薛之谦其实","邓紫棋光年之外","李荣浩年少有为"])
|
696 |
vc_search = gr.Button("用歌曲名来搜索吧")
|
@@ -705,7 +724,7 @@ with app:
|
|
705 |
as_audio_message = gr.Textbox(label="Message", visible=False)
|
706 |
|
707 |
vc_search.click(auto_search, [search_name], [ydl_audio_output])
|
708 |
-
ydl_url_submit.click(fn=youtube_downloader, inputs=[ydl_url_input, start, end], outputs=[ydl_audio_output])
|
709 |
as_audio_submit.click(fn=audio_separated, inputs=[as_audio_input], outputs=[as_audio_vocals, as_audio_no_vocals, as_audio_message], show_progress=True, queue=True)
|
710 |
|
711 |
with gr.Row():
|
|
|
419 |
url_base="",
|
420 |
quiet=False,
|
421 |
force=True,
|
422 |
+
full_song=True,
|
423 |
):
|
424 |
+
if full_song:
|
425 |
+
ydl_opts = {
|
426 |
+
'noplaylist': True,
|
427 |
+
'format': 'bestaudio/best',
|
428 |
+
'postprocessors': [{
|
429 |
+
'key': 'FFmpegExtractAudio',
|
430 |
+
'preferredcodec': 'wav',
|
431 |
+
}],
|
432 |
+
"outtmpl": 'dl_audio/youtube_audio',
|
433 |
+
}
|
434 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
435 |
+
ydl.download([url])
|
436 |
+
audio_path = "dl_audio/youtube_audio.wav"
|
437 |
+
return audio_path
|
438 |
+
|
439 |
+
else:
|
440 |
+
output_path = Path(output_filename)
|
441 |
+
if output_path.exists():
|
442 |
+
if not force:
|
443 |
+
return output_path
|
444 |
+
else:
|
445 |
+
output_path.unlink()
|
446 |
+
|
447 |
+
quiet = "--quiet --no-warnings" if quiet else ""
|
448 |
+
command = f"""
|
449 |
+
yt-dlp {quiet} -x --audio-format wav -f bestaudio -o "{output_filename}" --download-sections "*{start_time}-{end_time}" "{url_base}{video_identifier}" # noqa: E501
|
450 |
+
""".strip()
|
451 |
+
|
452 |
+
attempts = 0
|
453 |
+
while True:
|
454 |
+
try:
|
455 |
+
_ = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
|
456 |
+
except subprocess.CalledProcessError:
|
457 |
+
attempts += 1
|
458 |
+
if attempts == num_attempts:
|
459 |
+
return None
|
460 |
+
else:
|
461 |
+
break
|
462 |
+
|
463 |
+
if output_path.exists():
|
464 |
return output_path
|
465 |
else:
|
466 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
|
468 |
def audio_separated(audio_input, progress=gr.Progress()):
|
469 |
# start progress
|
|
|
706 |
with gr.Row():
|
707 |
with gr.Column():
|
708 |
ydl_url_input = gr.Textbox(label="音乐视频网址(可直接填写相应的BV号)", value = "https://www.bilibili.com/video/BV...")
|
709 |
+
with gr.Row():
|
710 |
+
start = gr.Number(value=0, label="起始时间 (秒)")
|
711 |
+
end = gr.Number(value=15, label="结束时间 (秒)")
|
712 |
+
check_full = gr.Checkbox(label="是否上传整首歌曲", value=True)
|
713 |
with gr.Accordion('搜索歌曲名上传', open=False):
|
714 |
search_name = gr.Dropdown(label="通过歌曲名搜索", info="选一首您喜欢的歌曲吧", choices=["周杰伦晴天","周杰伦兰亭序","周杰伦七里香","周杰伦花海","周杰伦反方向的钟","周杰伦一路向北","周杰伦稻香","周杰伦明明就","周杰伦爱在西元前","孙燕姿逆光","陈奕迅富士山下","许嵩有何不可","薛之谦其实","邓紫棋光年之外","李荣浩年少有为"])
|
715 |
vc_search = gr.Button("用歌曲名来搜索吧")
|
|
|
724 |
as_audio_message = gr.Textbox(label="Message", visible=False)
|
725 |
|
726 |
vc_search.click(auto_search, [search_name], [ydl_audio_output])
|
727 |
+
ydl_url_submit.click(fn=youtube_downloader, inputs=[ydl_url_input, start, end, check_full], outputs=[ydl_audio_output])
|
728 |
as_audio_submit.click(fn=audio_separated, inputs=[as_audio_input], outputs=[as_audio_vocals, as_audio_no_vocals, as_audio_message], show_progress=True, queue=True)
|
729 |
|
730 |
with gr.Row():
|