Spaces:
Sleeping
Sleeping
Nikita Makarov commited on
Commit ·
13c7f50
1
Parent(s): fab1b17
Fix search_youtube_music: use Modal proxy first instead of direct API
Browse files- src/mcp_servers/music_server.py +18 -10
src/mcp_servers/music_server.py
CHANGED
|
@@ -240,23 +240,31 @@ class MusicMCPServer:
|
|
| 240 |
# Apply rate limiting
|
| 241 |
self._rate_limit_youtube()
|
| 242 |
|
| 243 |
-
#
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
max_retries = 3
|
| 250 |
-
retry_delay = 2 # Start with 2 seconds
|
| 251 |
|
| 252 |
-
#
|
| 253 |
-
print("
|
| 254 |
api_tracks = self.search_youtube_via_api(query, limit)
|
| 255 |
if api_tracks:
|
| 256 |
print(f"✅ Found {len(api_tracks)} tracks via YouTube API")
|
| 257 |
return api_tracks
|
| 258 |
|
|
|
|
| 259 |
print("⚠️ YouTube API failed, trying yt-dlp...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
for attempt in range(max_retries):
|
| 262 |
try:
|
|
|
|
| 240 |
# Apply rate limiting
|
| 241 |
self._rate_limit_youtube()
|
| 242 |
|
| 243 |
+
# First, try Modal proxy (works in all restricted networks)
|
| 244 |
+
print("🔍 Trying Modal proxy search...")
|
| 245 |
+
modal_tracks = self.search_youtube_via_modal_proxy(query, limit)
|
| 246 |
+
if modal_tracks:
|
| 247 |
+
print(f"✅ Found {len(modal_tracks)} tracks via Modal proxy")
|
| 248 |
+
return modal_tracks
|
|
|
|
|
|
|
| 249 |
|
| 250 |
+
# Fallback to direct YouTube API (works in restricted networks but may not work in HF Spaces)
|
| 251 |
+
print("⚠️ Modal proxy failed, trying YouTube Data API...")
|
| 252 |
api_tracks = self.search_youtube_via_api(query, limit)
|
| 253 |
if api_tracks:
|
| 254 |
print(f"✅ Found {len(api_tracks)} tracks via YouTube API")
|
| 255 |
return api_tracks
|
| 256 |
|
| 257 |
+
# Last resort: try yt-dlp (won't work in HF Spaces due to DNS restrictions)
|
| 258 |
print("⚠️ YouTube API failed, trying yt-dlp...")
|
| 259 |
+
|
| 260 |
+
# Check if YouTube is accessible before attempting search
|
| 261 |
+
if not self._check_youtube_available():
|
| 262 |
+
print("⚠️ YouTube is not accessible (DNS/network issue). Skipping yt-dlp search.")
|
| 263 |
+
return []
|
| 264 |
+
|
| 265 |
+
tracks = []
|
| 266 |
+
max_retries = 3
|
| 267 |
+
retry_delay = 2 # Start with 2 seconds
|
| 268 |
|
| 269 |
for attempt in range(max_retries):
|
| 270 |
try:
|