Spaces:
Running
Running
more link
Browse files- src/main.py +37 -16
src/main.py
CHANGED
@@ -28,38 +28,59 @@ 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 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
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)
|
52 |
-
if query.path
|
53 |
-
return query.path.split('/')[
|
54 |
-
if query.path
|
|
|
|
|
55 |
return query.path.split('/')[2]
|
56 |
-
|
|
|
|
|
|
|
57 |
return query.path.split('/')[2]
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
60 |
return None
|
61 |
|
62 |
|
|
|
63 |
def yt_download(link):
|
64 |
ydl_opts = {
|
65 |
'format': 'bestaudio',
|
|
|
28 |
output_dir = os.path.join(BASE_DIR, 'song_output')
|
29 |
|
30 |
|
31 |
+
|
32 |
def get_youtube_video_id(url, ignore_playlist=True):
|
33 |
"""
|
34 |
+
Extracts video ID from YouTube, YouTube Shorts, Spotify, and SoundCloud URLs.
|
35 |
+
|
36 |
Examples:
|
37 |
+
YouTube:
|
38 |
http://youtu.be/SA2iWivDJiE
|
39 |
http://www.youtube.com/watch?v=_oPAwA_Udwc&feature=feedu
|
40 |
http://www.youtube.com/embed/SA2iWivDJiE
|
41 |
http://www.youtube.com/v/SA2iWivDJiE?version=3&hl=en_US
|
42 |
+
|
43 |
+
YouTube Shorts:
|
44 |
+
https://www.youtube.com/shorts/abc123xyz
|
45 |
+
|
46 |
+
Spotify:
|
47 |
+
https://open.spotify.com/track/5nTtCOCds6I0PHMNtqelas
|
48 |
+
|
49 |
+
SoundCloud:
|
50 |
+
https://soundcloud.com/artist/trackname
|
51 |
"""
|
52 |
+
|
53 |
query = urlparse(url)
|
54 |
+
|
55 |
+
if query.hostname in {'youtu.be', 'www.youtube.com', 'youtube.com', 'music.youtube.com'}:
|
56 |
+
# YouTube and YouTube Shorts
|
57 |
+
if query.hostname == 'youtu.be':
|
58 |
+
return query.path[1:]
|
59 |
+
|
|
|
|
|
|
|
|
|
60 |
if query.path == '/watch':
|
61 |
+
return parse_qs(query.query).get('v', [None])[0]
|
62 |
+
if query.path.startswith('/embed/'):
|
63 |
+
return query.path.split('/')[2]
|
64 |
+
if query.path.startswith('/v/'):
|
65 |
+
return query.path.split('/')[2]
|
66 |
+
if query.path.startswith('/shorts/'):
|
67 |
return query.path.split('/')[2]
|
68 |
+
|
69 |
+
elif query.hostname == 'open.spotify.com':
|
70 |
+
# Spotify
|
71 |
+
if query.path.startswith('/track/'):
|
72 |
return query.path.split('/')[2]
|
73 |
|
74 |
+
elif query.hostname == 'soundcloud.com':
|
75 |
+
# SoundCloud
|
76 |
+
# Example SoundCloud URL: https://soundcloud.com/artist/trackname
|
77 |
+
return query.path[1:] # returns "artist/trackname"
|
78 |
+
|
79 |
+
# Return None for invalid or unsupported URLs
|
80 |
return None
|
81 |
|
82 |
|
83 |
+
|
84 |
def yt_download(link):
|
85 |
ydl_opts = {
|
86 |
'format': 'bestaudio',
|