Spaces:
Running
Running
Update app_multi.py
Browse files- app_multi.py +31 -15
app_multi.py
CHANGED
@@ -75,16 +75,6 @@ def auto_search(name):
|
|
75 |
return (sampling_rate, signal)
|
76 |
|
77 |
|
78 |
-
# combine video with music
|
79 |
-
|
80 |
-
def combine_music(video, audio):
|
81 |
-
my_clip = mpe.VideoFileClip(video)
|
82 |
-
audio_background = mpe.AudioFileClip(audio)
|
83 |
-
final_audio = mpe.CompositeAudioClip([my_clip.audio, audio_background])
|
84 |
-
final_clip = my_clip.set_audio(final_audio)
|
85 |
-
final_clip.write_videofile("video.mp4")
|
86 |
-
return "video.mp4"
|
87 |
-
|
88 |
# Reference: https://huggingface.co/spaces/zomehwh/rvc-models/blob/main/app.py#L21 # noqa
|
89 |
in_hf_space = getenv('SYSTEM') == 'spaces'
|
90 |
|
@@ -382,9 +372,35 @@ def mix(audio1, audio2):
|
|
382 |
|
383 |
return "song.wav"
|
384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
# Bilibili
|
386 |
def youtube_downloader(
|
387 |
-
|
388 |
start_time,
|
389 |
end_time,
|
390 |
is_full_song,
|
@@ -394,6 +410,7 @@ def youtube_downloader(
|
|
394 |
quiet=False,
|
395 |
force=True,
|
396 |
):
|
|
|
397 |
if is_full_song:
|
398 |
ydl_opts = {
|
399 |
'noplaylist': True,
|
@@ -678,14 +695,13 @@ with app:
|
|
678 |
with gr.Tab("🤗 - 轻松提取音乐"):
|
679 |
with gr.Row():
|
680 |
with gr.Column():
|
681 |
-
ydl_url_input = gr.Textbox(label="
|
682 |
with gr.Row():
|
683 |
start = gr.Number(value=0, label="起始时间 (秒)")
|
684 |
end = gr.Number(value=15, label="结束时间 (秒)")
|
685 |
check_full = gr.Checkbox(label="是否上传整首歌曲", info="若勾选则不需要填写起止时间", value=True)
|
686 |
-
|
687 |
-
|
688 |
-
vc_search = gr.Button("用歌曲名来搜索吧")
|
689 |
|
690 |
ydl_url_submit = gr.Button("提取声音文件吧", variant="primary")
|
691 |
as_audio_submit = gr.Button("去除背景音吧", variant="primary")
|
|
|
75 |
return (sampling_rate, signal)
|
76 |
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
# Reference: https://huggingface.co/spaces/zomehwh/rvc-models/blob/main/app.py#L21 # noqa
|
79 |
in_hf_space = getenv('SYSTEM') == 'spaces'
|
80 |
|
|
|
372 |
|
373 |
return "song.wav"
|
374 |
|
375 |
+
|
376 |
+
import requests
|
377 |
+
import yt_dlp
|
378 |
+
headers = {
|
379 |
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4302.0 Safari/537.36"
|
380 |
+
}
|
381 |
+
import re
|
382 |
+
|
383 |
+
pattern = r'//www\.bilibili\.com/video[^"]*'
|
384 |
+
|
385 |
+
def find_first_appearance_with_neighborhood(text, pattern):
|
386 |
+
match = re.search(pattern, text)
|
387 |
+
|
388 |
+
if match:
|
389 |
+
return match.group()
|
390 |
+
else:
|
391 |
+
return None
|
392 |
+
|
393 |
+
def search_bilibili(keyword):
|
394 |
+
req = requests.get("https://search.bilibili.com/all?keyword={}&duration=1&tids=3&page=1".format(keyword), headers=headers).text
|
395 |
+
|
396 |
+
video_link = "https:" + find_first_appearance_with_neighborhood(req, pattern)
|
397 |
+
|
398 |
+
return video_link
|
399 |
+
|
400 |
+
|
401 |
# Bilibili
|
402 |
def youtube_downloader(
|
403 |
+
song_name,
|
404 |
start_time,
|
405 |
end_time,
|
406 |
is_full_song,
|
|
|
410 |
quiet=False,
|
411 |
force=True,
|
412 |
):
|
413 |
+
video_identifier = search_bilibili(song_name)
|
414 |
if is_full_song:
|
415 |
ydl_opts = {
|
416 |
'noplaylist': True,
|
|
|
695 |
with gr.Tab("🤗 - 轻松提取音乐"):
|
696 |
with gr.Row():
|
697 |
with gr.Column():
|
698 |
+
ydl_url_input = gr.Textbox(label="通过歌曲名搜索", placeholder = "小幸运")
|
699 |
with gr.Row():
|
700 |
start = gr.Number(value=0, label="起始时间 (秒)")
|
701 |
end = gr.Number(value=15, label="结束时间 (秒)")
|
702 |
check_full = gr.Checkbox(label="是否上传整首歌曲", info="若勾选则不需要填写起止时间", value=True)
|
703 |
+
search_name = gr.Dropdown(label="通过歌曲名搜索", info="选一首您喜欢的歌曲吧", visible=False, choices=["周杰伦晴天","周杰伦兰亭序","周杰伦七里香","周杰伦花海","周杰伦反方向的钟","周杰伦一路向北","周杰伦稻香","周杰伦明明就","周杰伦爱在西元前","孙燕姿逆光","陈奕迅富士山下","许嵩有何不可","薛之谦其实","邓紫棋光年之外","李荣浩年少有为"])
|
704 |
+
vc_search = gr.Button("用歌曲名来搜索吧", visible=False)
|
|
|
705 |
|
706 |
ydl_url_submit = gr.Button("提取声音文件吧", variant="primary")
|
707 |
as_audio_submit = gr.Button("去除背景音吧", variant="primary")
|