Spaces:
Running
Running
admin
commited on
Commit
·
668edc0
1
Parent(s):
6ea35b9
try abs path
Browse files
app.py
CHANGED
@@ -28,13 +28,10 @@ def download_audio(url: str, save_path: str):
|
|
28 |
response = requests.get(url, stream=True)
|
29 |
response.raise_for_status()
|
30 |
with open(save_path, "wb") as file:
|
31 |
-
for chunk in
|
32 |
-
response.iter_content(chunk_size=8192),
|
33 |
-
desc="Downloading...",
|
34 |
-
):
|
35 |
file.write(chunk)
|
36 |
|
37 |
-
|
38 |
|
39 |
|
40 |
def is_url(s: str):
|
@@ -75,7 +72,7 @@ def upl_infer(audio_path: str, cache_dir="./__pycache__/mode1"):
|
|
75 |
return None, None, None, None, f"{e}", None
|
76 |
|
77 |
|
78 |
-
def
|
79 |
match = re.search(r"\d+", input_string)
|
80 |
if match:
|
81 |
return str(int(match.group()))
|
@@ -112,14 +109,13 @@ def url_infer(song: str, cache_dir="./__pycache__/mode2"):
|
|
112 |
audio_path = f"{cache_dir}/output.mp3"
|
113 |
try:
|
114 |
if (is_url(song) and "163" in song and "?id=" in song) or song.isdigit():
|
115 |
-
song_id =
|
116 |
song_url = f"https://music.163.com/song/media/outer/url?id={song_id}.mp3"
|
117 |
song_name, free = music163_song_info(song_id)
|
118 |
if not free:
|
119 |
-
print("Unable to parse VIP songs")
|
120 |
raise AttributeError("Unable to parse VIP songs")
|
121 |
|
122 |
-
download_audio(song_url, audio_path)
|
123 |
|
124 |
midi, title = audio2midi(audio_path, cache_dir)
|
125 |
if song_name:
|
|
|
28 |
response = requests.get(url, stream=True)
|
29 |
response.raise_for_status()
|
30 |
with open(save_path, "wb") as file:
|
31 |
+
for chunk in response.iter_content(chunk_size=8192):
|
|
|
|
|
|
|
32 |
file.write(chunk)
|
33 |
|
34 |
+
return os.path.abspath(save_path)
|
35 |
|
36 |
|
37 |
def is_url(s: str):
|
|
|
72 |
return None, None, None, None, f"{e}", None
|
73 |
|
74 |
|
75 |
+
def get_1st_int(input_string: str):
|
76 |
match = re.search(r"\d+", input_string)
|
77 |
if match:
|
78 |
return str(int(match.group()))
|
|
|
109 |
audio_path = f"{cache_dir}/output.mp3"
|
110 |
try:
|
111 |
if (is_url(song) and "163" in song and "?id=" in song) or song.isdigit():
|
112 |
+
song_id = get_1st_int(song.split("?id=")[-1])
|
113 |
song_url = f"https://music.163.com/song/media/outer/url?id={song_id}.mp3"
|
114 |
song_name, free = music163_song_info(song_id)
|
115 |
if not free:
|
|
|
116 |
raise AttributeError("Unable to parse VIP songs")
|
117 |
|
118 |
+
audio_path = download_audio(song_url, audio_path)
|
119 |
|
120 |
midi, title = audio2midi(audio_path, cache_dir)
|
121 |
if song_name:
|