Spaces:
Runtime error
Runtime error
Update src/main.py
Browse files- src/main.py +2 -33
src/main.py
CHANGED
|
@@ -28,37 +28,6 @@ rvc_models_dir = os.path.join(BASE_DIR, 'rvc_models')
|
|
| 28 |
output_dir = os.path.join(BASE_DIR, 'song_output')
|
| 29 |
|
| 30 |
|
| 31 |
-
def get_youtube_video_id(url, ignore_playlist=True):
|
| 32 |
-
"""
|
| 33 |
-
Examples:
|
| 34 |
-
http://youtu.be/SA2iWivDJiE
|
| 35 |
-
http://www.youtube.com/watch?v=_oPAwA_Udwc&feature=feedu
|
| 36 |
-
http://www.youtube.com/embed/SA2iWivDJiE
|
| 37 |
-
http://www.youtube.com/v/SA2iWivDJiE?version=3&hl=en_US
|
| 38 |
-
"""
|
| 39 |
-
query = urlparse(url)
|
| 40 |
-
if query.hostname == 'youtu.be':
|
| 41 |
-
if query.path[1:] == 'watch':
|
| 42 |
-
return query.query[2:]
|
| 43 |
-
return query.path[1:]
|
| 44 |
-
|
| 45 |
-
if query.hostname in {'www.youtube.com', 'youtube.com', 'music.youtube.com'}:
|
| 46 |
-
if not ignore_playlist:
|
| 47 |
-
# use case: get playlist id not current video in playlist
|
| 48 |
-
with suppress(KeyError):
|
| 49 |
-
return parse_qs(query.query)['list'][0]
|
| 50 |
-
if query.path == '/watch':
|
| 51 |
-
return parse_qs(query.query)['v'][0]
|
| 52 |
-
if query.path[:7] == '/watch/':
|
| 53 |
-
return query.path.split('/')[1]
|
| 54 |
-
if query.path[:7] == '/embed/':
|
| 55 |
-
return query.path.split('/')[2]
|
| 56 |
-
if query.path[:3] == '/v/':
|
| 57 |
-
return query.path.split('/')[2]
|
| 58 |
-
|
| 59 |
-
# returns None for invalid YouTube url
|
| 60 |
-
return None
|
| 61 |
-
|
| 62 |
|
| 63 |
def yt_download(link):
|
| 64 |
ydl_opts = {
|
|
@@ -250,9 +219,9 @@ def song_cover_pipeline(song_input, voice_model, pitch_change, keep_files,
|
|
| 250 |
# if youtube url
|
| 251 |
if urlparse(song_input).scheme == 'https':
|
| 252 |
input_type = 'yt'
|
| 253 |
-
song_id =
|
| 254 |
if song_id is None:
|
| 255 |
-
error_msg = 'Invalid
|
| 256 |
raise_exception(error_msg, is_webui)
|
| 257 |
|
| 258 |
# local audio file
|
|
|
|
| 28 |
output_dir = os.path.join(BASE_DIR, 'song_output')
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
def yt_download(link):
|
| 33 |
ydl_opts = {
|
|
|
|
| 219 |
# if youtube url
|
| 220 |
if urlparse(song_input).scheme == 'https':
|
| 221 |
input_type = 'yt'
|
| 222 |
+
song_id = yt_download(song_input)
|
| 223 |
if song_id is None:
|
| 224 |
+
error_msg = 'Invalid url.'
|
| 225 |
raise_exception(error_msg, is_webui)
|
| 226 |
|
| 227 |
# local audio file
|